Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
348 changes: 328 additions & 20 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,12 @@ memmap2 = "0.9.5"
memfd = "0.6.4"

# desktop
wry = { version = "0.52.1", default-features = false }
tao = { version = "0.34.0", features = ["rwh_05"] }
wry = { git = "https://github.com/richerfu/wry.git", default-features = false }
tao = { git = "https://github.com/richerfu/tao.git", features = ["rwh_06"] }

# wry = { path = "../wry", default-features = false }
# tao = { path = "../tao", features = ["rwh_06"] }

infer = "0.19.0"
dunce = "1.0.5"
percent-encoding = "2.3.1"
Expand Down
10 changes: 4 additions & 6 deletions packages/desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,29 @@ webbrowser = { version = "1.0" }
[target.'cfg(unix)'.dependencies]
signal-hook = "0.3.18"

[target.'cfg(target_os = "linux")'.dependencies]
[target.'cfg(any(target_os = "linux", not(target_env = "ohos")))'.dependencies]
wry = { workspace = true, features = ["os-webview", "protocol", "drag-drop", "linux-body"] }

[target.'cfg(any(target_os = "windows",target_os = "macos",target_os = "linux",target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
[target.'cfg(all(any(target_os = "windows",target_os = "macos",target_os = "linux",target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"), not(target_env = "ohos")))'.dependencies]
global-hotkey = "0.7.0"
rfd = { version = "0.15.3", default-features = false, features = ["xdg-portal", "tokio"] }
muda = { workspace = true }

[target.'cfg(any(target_os = "windows",target_os = "macos",target_os = "linux"))'.dependencies]
[target.'cfg(all(any(target_os = "windows",target_os = "macos",target_os = "linux"), not(target_env = "ohos")))'.dependencies]
tray-icon = { workspace = true }

[target.'cfg(target_os = "ios")'.dependencies]
objc = "0.2.7"
objc_id = "0.1.1"

# use rustls on android
[target.'cfg(target_os = "android")'.dependencies]
tungstenite = { workspace = true, features = ["rustls"] }
jni = "0.21.1"
ndk = { version = "0.9.0" }
ndk-sys = { version = "0.6.0" }
ndk-context = { version = "0.1.1" }

# use native tls on other platforms
[target.'cfg(not(target_os = "android"))'.dependencies]
[target.'cfg(any(not(target_os = "android"), not(target_env = "ohos")))'.dependencies]
tungstenite = { workspace = true, features = ["native-tls"] }

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
57 changes: 45 additions & 12 deletions packages/desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,35 @@ impl App {
dioxus_html::set_event_converter(Box::new(crate::events::SerializedHtmlEventConverter));

// Wire up the global hotkey handler
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
app.set_global_hotkey_handler();

// Wire up the menubar receiver - this way any component can key into the menubar actions
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
app.set_menubar_receiver();

// Wire up the tray icon receiver - this way any component can key into the menubar actions
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
app.set_tray_icon_receiver();

// Allow hotreloading to work - but only in debug mode
#[cfg(all(feature = "devtools", debug_assertions))]
app.connect_hotreload();

#[cfg(debug_assertions)]
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
app.connect_preserve_window_state_handler();

(event_loop, app)
Expand All @@ -116,12 +128,18 @@ impl App {
.apply_event(window_event, &self.shared.target);
}

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
pub fn handle_global_hotkey(&self, event: global_hotkey::GlobalHotKeyEvent) {
self.shared.shortcut_manager.call_handlers(event);
}

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
pub fn handle_menu_event(&mut self, event: muda::MenuEvent) {
match event.id().0.as_str() {
"dioxus-float-top" => {
Expand All @@ -147,12 +165,18 @@ impl App {
_ => (),
}
}
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
pub fn handle_tray_menu_event(&mut self, event: tray_icon::menu::MenuEvent) {
_ = event;
}

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
pub fn handle_tray_icon_event(&mut self, event: tray_icon::TrayIconEvent) {
if let tray_icon::TrayIconEvent::Click {
id: _,
Expand Down Expand Up @@ -454,7 +478,10 @@ impl App {
view.poll_vdom();
}

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
fn set_global_hotkey_handler(&self) {
let receiver = self.shared.proxy.clone();

Expand All @@ -468,7 +495,10 @@ impl App {
}));
}

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
fn set_menubar_receiver(&self) {
let receiver = self.shared.proxy.clone();

Expand All @@ -482,7 +512,10 @@ impl App {
}));
}

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
fn set_tray_icon_receiver(&self) {
let receiver = self.shared.proxy.clone();

Expand Down Expand Up @@ -584,7 +617,7 @@ impl App {
explicit_window_position: Option<tao::dpi::Position>,
) {
// We only want to do this on desktop
if cfg!(target_os = "android") || cfg!(target_os = "ios") {
if cfg!(target_os = "android") || cfg!(target_os = "ios") || cfg!(target_env = "ohos") {
return;
}

Expand Down
38 changes: 22 additions & 16 deletions packages/desktop/src/file_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,33 @@ pub(crate) struct FileDialogRequest {

#[allow(unused)]
impl FileDialogRequest {
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
#[cfg(not(all(
any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
),
not(target_env = "ohos")
)))]
pub(crate) fn get_file_event(&self) -> Vec<PathBuf> {
vec![]
}

#[cfg(any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
#[cfg(all(
any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
),
not(target_env = "ohos")
))]
pub(crate) fn get_file_event(&self) -> Vec<PathBuf> {
fn get_file_event_for_folder(
Expand Down
30 changes: 24 additions & 6 deletions packages/desktop/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ pub fn use_wry_event_handler(
/// Register an event handler that runs when a muda event is processed.
#[cfg_attr(
docsrs,
doc(cfg(any(target_os = "windows", target_os = "linux", target_os = "macos")))
doc(cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
)))
)]
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
pub fn use_muda_event_handler(
mut handler: impl FnMut(&muda::MenuEvent) + 'static,
) -> WryEventHandler {
Expand All @@ -54,9 +60,15 @@ pub fn use_muda_event_handler(
/// Register an event handler that runs when a tray icon menu event is processed.
#[cfg_attr(
docsrs,
doc(cfg(any(target_os = "windows", target_os = "linux", target_os = "macos")))
doc(cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
)))
)]
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
pub fn use_tray_menu_event_handler(
mut handler: impl FnMut(&tray_icon::menu::MenuEvent) + 'static,
) -> WryEventHandler {
Expand All @@ -72,9 +84,15 @@ pub fn use_tray_menu_event_handler(
/// If you want to register tray icon menus handler use `use_tray_menu_event_handler` instead.
#[cfg_attr(
docsrs,
doc(cfg(any(target_os = "windows", target_os = "linux", target_os = "macos")))
doc(cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
)))
)]
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
pub fn use_tray_icon_event_handler(
mut handler: impl FnMut(&tray_icon::TrayIconEvent) + 'static,
) -> WryEventHandler {
Expand Down
22 changes: 18 additions & 4 deletions packages/desktop/src/ipc.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
#![allow(missing_docs)]

use serde::{Deserialize, Serialize};
use tao::window::WindowId;

#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum UserWindowEvent {
/// A global hotkey event
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
GlobalHotKeyEvent(global_hotkey::GlobalHotKeyEvent),

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
MudaMenuEvent(muda::MenuEvent),

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
TrayIconEvent(tray_icon::TrayIconEvent),

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(all(
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(target_env = "ohos")
))]
TrayMenuEvent(tray_icon::menu::MenuEvent),

/// Poll the virtualdom
Expand Down
Loading