diff --git a/Cargo.lock b/Cargo.lock index 12b46e106e..b902121c5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4533,6 +4533,22 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "ctor" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec09e802f5081de6157da9a75701d6c713d8dc3ba52571fd4bd25f412644e8a6" +dependencies = [ + "ctor-proc-macro", + "dtor", +] + +[[package]] +name = "ctor-proc-macro" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2931af7e13dc045d8e9d26afccc6fa115d64e115c9c84b1166288b46f6782c2" + [[package]] name = "ctr" version = "0.9.2" @@ -4663,8 +4679,18 @@ version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.20.11", + "darling_macro 0.20.11", +] + +[[package]] +name = "darling" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a79c4acb1fd5fa3d9304be4c76e031c54d2e92d172a393e24b19a14fe8532fe9" +dependencies = [ + "darling_core 0.21.0", + "darling_macro 0.21.0", ] [[package]] @@ -4681,13 +4707,38 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "darling_core" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74875de90daf30eb59609910b84d4d368103aaec4c924824c6799b28f77d6a1d" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.104", +] + [[package]] name = "darling_macro" version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ - "darling_core", + "darling_core 0.20.11", + "quote", + "syn 2.0.104", +] + +[[package]] +name = "darling_macro" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79f8e61677d5df9167cd85265f8e5f64b215cdea3fb55eebc3e622e44c7a146" +dependencies = [ + "darling_core 0.21.0", "quote", "syn 2.0.104", ] @@ -4843,7 +4894,7 @@ version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" dependencies = [ - "darling", + "darling 0.20.11", "proc-macro2", "quote", "syn 2.0.104", @@ -6143,7 +6194,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading 0.8.8", + "libloading 0.7.4", ] [[package]] @@ -6239,6 +6290,21 @@ dependencies = [ "dtoa", ] +[[package]] +name = "dtor" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97cbdf2ad6846025e8e25df05171abfb30e3ababa12ee0a0e44b9bbe570633a8" +dependencies = [ + "dtor-proc-macro", +] + +[[package]] +name = "dtor-proc-macro" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7454e41ff9012c00d53cf7f475c5e3afa3b91b7c90568495495e8d9bf47a1055" + [[package]] name = "dunce" version = "1.0.5" @@ -6465,7 +6531,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76d07902c93376f1e96c34abc4d507c0911df3816cef50b01f5a2ff3ad8c370d" dependencies = [ - "darling", + "darling 0.20.11", "proc-macro2", "quote", "syn 2.0.104", @@ -7478,7 +7544,7 @@ dependencies = [ "vec_map", "wasm-bindgen", "web-sys", - "windows 0.61.3", + "windows 0.54.0", ] [[package]] @@ -8796,7 +8862,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core 0.61.2", + "windows-core 0.57.0", ] [[package]] @@ -9219,7 +9285,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf9fed6d91cfb734e7476a06bde8300a1b94e217e1b523b6f0cd1a01998c71d" dependencies = [ - "darling", + "darling 0.20.11", "indoc", "proc-macro2", "quote", @@ -10669,6 +10735,63 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "napi-build-ohos" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "959f833e4ea8bec8f92b23b705b5558d42d8e63672c77b9b281b7228c5df6e88" + +[[package]] +name = "napi-derive-backend-ohos" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b27250baa967a15214e57384dd6228c59afbccb15ab8f97207c9758917544bf5" +dependencies = [ + "convert_case 0.8.0", + "proc-macro2", + "quote", + "semver", + "syn 2.0.104", +] + +[[package]] +name = "napi-derive-ohos" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c844efa85d53b5adc3b326520f3a108c3a737b7534ee10d406f81884e7e71b3c" +dependencies = [ + "convert_case 0.8.0", + "ctor 0.4.3", + "napi-derive-backend-ohos", + "proc-macro2", + "quote", + "syn 2.0.104", +] + +[[package]] +name = "napi-ohos" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44cd7f1a2b5b17e763d8fcc33f3a9f426c0303a1fcb9b89d7c553308c3a1db97" +dependencies = [ + "bitflags 2.9.1", + "ctor 0.4.3", + "napi-build-ohos", + "napi-sys-ohos", + "nohash-hasher", + "rustc-hash 2.1.1", + "tokio", +] + +[[package]] +name = "napi-sys-ohos" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff0b7e156bf62a778295ba4f130cde6c2fe07936ebf9448fab6ca0f7c7040682" +dependencies = [ + "libloading 0.8.8", +] + [[package]] name = "nasm-rs" version = "0.3.0" @@ -10859,6 +10982,12 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + [[package]] name = "nom" version = "7.1.3" @@ -11549,6 +11678,144 @@ dependencies = [ "byteorder", ] +[[package]] +name = "ohos-arkui-binding" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "731d879cf95234bbd12e525bdce7da6475a6786a86dd2362fac0f3cfca760373" +dependencies = [ + "bitflags 2.9.1", + "napi-ohos", + "napi-sys-ohos", + "ohos-arkui-sys", + "ohos-xcomponent-binding", + "ohos-xcomponent-sys", + "ohos_enum_macro 0.0.2", +] + +[[package]] +name = "ohos-arkui-sys" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a19176486bbe46d33830aca4213b07bb46c745200118e57106639db4962e1c3" +dependencies = [ + "napi-sys-ohos", +] + +[[package]] +name = "ohos-display-binding" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157fe09232fd0af55ed9207d30b47a5f5ff7f84a0673a3b47f65acb7bbc9b8a9" +dependencies = [ + "ohos-display-sys", + "ohos_enum_macro 0.0.1", +] + +[[package]] +name = "ohos-display-soloist-binding" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b26e7a334db10af3d3b71cc0cddfd923030421e719031d8d75ca8ffb431614dd" +dependencies = [ + "ohos-display-soloist-sys", +] + +[[package]] +name = "ohos-display-soloist-sys" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b6f9ced0cbe82574a06d95cf5ffa35eee07b13e0631c8abd421feb03aa16b0a" + +[[package]] +name = "ohos-display-sys" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe9e1bba4d94159d0a65f1b4e748c148d4bce7930912c424522693f1837dad77" + +[[package]] +name = "ohos-ime-binding" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bed52a087eacd3ea07de5258ca7574276431b17d4c0464ed7f7f57a5fa99bd48" +dependencies = [ + "ohos-input-method-sys", + "ohos_enum_macro 0.0.1", +] + +[[package]] +name = "ohos-input-method-sys" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e95bb83d997b0d7f1d04e9b2ba8874a1bd8e89dc5e88d0852a4390f8b44b0703" + +[[package]] +name = "ohos-web-binding" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "390cbdbe97bddcb5dcd46d52654799525ef42962cf6f360c57b4bb72597ebd61" +dependencies = [ + "bitflags 2.9.1", + "ohos-web-sys", + "ohos_enum_macro 0.0.2", +] + +[[package]] +name = "ohos-web-sys" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa646f3223c2bc90a400641c3a5cda4b350387ffda1a904b8bfb3db92b81ecbc" + +[[package]] +name = "ohos-xcomponent-binding" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f99c43b17408bb43ae53832a7b929dc6a359685f914624e82fec0a52e9d6ac" +dependencies = [ + "napi-derive-ohos", + "napi-ohos", + "napi-sys-ohos", + "ohos-display-binding", + "ohos-xcomponent-sys", + "ohos_enum_macro 0.0.2", + "raw-window-handle 0.6.2", +] + +[[package]] +name = "ohos-xcomponent-sys" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5613209329ff61bc8695871ef985d57fc59ea4d55263e2c2395d8810d063575e" +dependencies = [ + "ohos-arkui-sys", +] + +[[package]] +name = "ohos_enum_macro" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0ee769776099c824423d1686e21b5fd13b464d374d60f7cc25c48c1c836ede1" +dependencies = [ + "convert_case 0.6.0", + "proc-macro2", + "quote", + "regex", + "syn 2.0.104", +] + +[[package]] +name = "ohos_enum_macro" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4bacd60b52be93024c446f27645d795ab71eb2243bb4c5d87b6238a35341fbd" +dependencies = [ + "convert_case 0.6.0", + "proc-macro2", + "quote", + "regex", + "syn 2.0.104", +] + [[package]] name = "oid-registry" version = "0.6.1" @@ -11606,6 +11873,35 @@ dependencies = [ "pathdiff", ] +[[package]] +name = "openharmony-ability" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef188801ee7d2356067f4d4d54eb1d1eaab58e9acce9a8f9cc9695f8327bc52" +dependencies = [ + "http 1.3.1", + "napi-derive-ohos", + "napi-ohos", + "ohos-arkui-binding", + "ohos-display-binding", + "ohos-display-soloist-binding", + "ohos-ime-binding", + "ohos-web-binding", + "ohos-xcomponent-binding", +] + +[[package]] +name = "openharmony-ability-derive" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba6d923f6fc667cb9db25ff570deece3cdffb3fc4b58b8bc04f0419ca5de1d3" +dependencies = [ + "darling 0.21.0", + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "openssl" version = "0.10.73" @@ -12129,7 +12425,7 @@ dependencies = [ "aes-gcm", "aes-kw", "argon2", - "base64 0.22.1", + "base64 0.21.7", "bitfield", "block-padding", "blowfish", @@ -14459,7 +14755,7 @@ version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de90945e6565ce0d9a25098082ed4ee4002e047cb59892c318d66821e14bb30f" dependencies = [ - "darling", + "darling 0.20.11", "proc-macro2", "quote", "syn 2.0.104", @@ -15435,7 +15731,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8384a2ebb61abbde4466dfc9d5dcda134dfa939b77bfb2df878d1c7dffe081f1" dependencies = [ - "darling", + "darling 0.20.11", "proc-macro2", "quote", "syn 2.0.104", @@ -16228,8 +16524,7 @@ dependencies = [ [[package]] name = "tao" version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49c380ca75a231b87b6c9dd86948f035012e7171d1a7c40a9c2890489a7ffd8a" +source = "git+https://github.com/richerfu/tao.git#7877ea48d6e47d0401aad8c4db13cf12db8bad99" dependencies = [ "bitflags 2.9.1", "core-foundation 0.10.1", @@ -16252,11 +16547,13 @@ dependencies = [ "objc2-app-kit 0.3.1", "objc2-foundation 0.3.1", "once_cell", + "openharmony-ability", + "openharmony-ability-derive", "parking_lot", "raw-window-handle 0.5.2", "raw-window-handle 0.6.2", "scopeguard", - "tao-macros", + "tao-macros 0.1.3 (git+https://github.com/richerfu/tao.git)", "unicode-segmentation", "url", "windows 0.61.3", @@ -16276,6 +16573,16 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "tao-macros" +version = "0.1.3" +source = "git+https://github.com/richerfu/tao.git#7877ea48d6e47d0401aad8c4db13cf12db8bad99" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "tap" version = "1.0.1" @@ -16399,7 +16706,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41743bbbeb96c3a100d234e5a0b60a46d5aa068f266160862c7afdbf828ca02e" dependencies = [ "anyhow", - "ctor", + "ctor 0.2.9", "dunce", "glob", "http 1.3.1", @@ -16689,7 +16996,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ba1f5563024b63bb6acb4558452d9ba737518c1d11fcc1861febe98d1e31cf4" dependencies = [ - "darling", + "darling 0.20.11", "proc-macro2", "quote", "syn 2.0.104", @@ -19342,8 +19649,7 @@ checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" [[package]] name = "wry" version = "0.52.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12a714d9ba7075aae04a6e50229d6109e3d584774b99a6a8c60de1698ca111b9" +source = "git+https://github.com/richerfu/wry.git#0747f2cb13e391986f1f9fdf4b252d4c882acaf9" dependencies = [ "base64 0.22.1", "block2 0.6.1", @@ -19366,11 +19672,13 @@ dependencies = [ "objc2-ui-kit 0.3.1", "objc2-web-kit", "once_cell", + "openharmony-ability", + "openharmony-ability-derive", "percent-encoding", "raw-window-handle 0.6.2", "sha2", "soup3", - "tao-macros", + "tao-macros 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 2.0.12", "url", "webkit2gtk", diff --git a/Cargo.toml b/Cargo.toml index f49009e72b..9a47e652a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/packages/desktop/Cargo.toml b/packages/desktop/Cargo.toml index b77f52b738..2d77072c3e 100644 --- a/packages/desktop/Cargo.toml +++ b/packages/desktop/Cargo.toml @@ -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] diff --git a/packages/desktop/src/app.rs b/packages/desktop/src/app.rs index bcf36203fe..b6f6c93393 100644 --- a/packages/desktop/src/app.rs +++ b/packages/desktop/src/app.rs @@ -87,15 +87,24 @@ 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 @@ -103,7 +112,10 @@ impl App { 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) @@ -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" => { @@ -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: _, @@ -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(); @@ -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(); @@ -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(); @@ -584,7 +617,7 @@ impl App { explicit_window_position: Option, ) { // 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; } diff --git a/packages/desktop/src/file_upload.rs b/packages/desktop/src/file_upload.rs index fcf4cc8d12..e27d72f106 100644 --- a/packages/desktop/src/file_upload.rs +++ b/packages/desktop/src/file_upload.rs @@ -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 { 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 { fn get_file_event_for_folder( diff --git a/packages/desktop/src/hooks.rs b/packages/desktop/src/hooks.rs index c6fd33ad6c..d727ac9e4f 100644 --- a/packages/desktop/src/hooks.rs +++ b/packages/desktop/src/hooks.rs @@ -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 { @@ -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 { @@ -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 { diff --git a/packages/desktop/src/ipc.rs b/packages/desktop/src/ipc.rs index 9dfbf104b9..818f3b6cb6 100644 --- a/packages/desktop/src/ipc.rs +++ b/packages/desktop/src/ipc.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + use serde::{Deserialize, Serialize}; use tao::window::WindowId; @@ -5,16 +7,28 @@ use tao::window::WindowId; #[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 diff --git a/packages/desktop/src/launch_ohos.rs b/packages/desktop/src/launch_ohos.rs new file mode 100644 index 0000000000..48e3dd5f80 --- /dev/null +++ b/packages/desktop/src/launch_ohos.rs @@ -0,0 +1,167 @@ +use crate::Config; +use crate::{ + app::App, + ipc::{IpcMethod, UserWindowEvent}, +}; +use dioxus_core::*; +use dioxus_document::eval; +use std::any::Any; +use tao::event::{Event, StartCause, WindowEvent}; + +/// Launch the WebView and run the event loop, with configuration and root props. +/// +/// This will block the main thread, and *must* be spawned on the main thread. This function does not assume any runtime +/// and is equivalent to calling launch_with_props with the tokio feature disabled. +pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, mut desktop_config: Config) -> () { + let mut custom_event_handler = desktop_config.custom_event_handler.take(); + let (event_loop, mut inner_app) = App::new(desktop_config, virtual_dom); + + let app = Box::leak(Box::new(inner_app)); + + event_loop.run(move |window_event, event_loop, control_flow| { + // Set the control flow and check if any events need to be handled in the app itself + app.tick(&window_event); + + if let Some(ref mut f) = custom_event_handler { + f(&window_event, event_loop) + } + + match window_event { + Event::NewEvents(StartCause::Init) => app.handle_start_cause_init(), + Event::LoopDestroyed => app.handle_loop_destroyed(), + Event::WindowEvent { + event, window_id, .. + } => match event { + WindowEvent::CloseRequested => app.handle_close_requested(window_id), + WindowEvent::Destroyed { .. } => app.window_destroyed(window_id), + WindowEvent::Resized(new_size) => app.resize_window(window_id, new_size), + _ => {} + }, + + Event::UserEvent(event) => match event { + UserWindowEvent::Poll(id) => app.poll_vdom(id), + UserWindowEvent::NewWindow => app.handle_new_window(), + UserWindowEvent::CloseWindow(id) => app.handle_close_msg(id), + UserWindowEvent::Shutdown => app.control_flow = tao::event_loop::ControlFlow::Exit, + + #[cfg(all( + any(target_os = "windows", target_os = "linux", target_os = "macos"), + not(target_env = "ohos") + ))] + UserWindowEvent::GlobalHotKeyEvent(evnt) => app.handle_global_hotkey(evnt), + + #[cfg(all( + any(target_os = "windows", target_os = "linux", target_os = "macos"), + not(target_env = "ohos") + ))] + UserWindowEvent::MudaMenuEvent(evnt) => app.handle_menu_event(evnt), + + #[cfg(all( + any(target_os = "windows", target_os = "linux", target_os = "macos"), + not(target_env = "ohos") + ))] + UserWindowEvent::TrayMenuEvent(evnt) => app.handle_tray_menu_event(evnt), + + #[cfg(all( + any(target_os = "windows", target_os = "linux", target_os = "macos"), + not(target_env = "ohos") + ))] + UserWindowEvent::TrayIconEvent(evnt) => app.handle_tray_icon_event(evnt), + + #[cfg(all(feature = "devtools", debug_assertions))] + UserWindowEvent::HotReloadEvent(msg) => app.handle_hot_reload_msg(msg), + + // Windows-only drag-n-drop fix events. We need to call the interpreter drag-n-drop code. + UserWindowEvent::WindowsDragDrop(id) => { + if let Some(webview) = app.webviews.get(&id) { + webview.dom.in_runtime(|| { + ScopeId::ROOT.in_runtime(|| { + eval("window.interpreter.handleWindowsDragDrop();"); + }); + }); + } + } + UserWindowEvent::WindowsDragLeave(id) => { + if let Some(webview) = app.webviews.get(&id) { + webview.dom.in_runtime(|| { + ScopeId::ROOT.in_runtime(|| { + eval("window.interpreter.handleWindowsDragLeave();"); + }); + }); + } + } + UserWindowEvent::WindowsDragOver(id, x_pos, y_pos) => { + if let Some(webview) = app.webviews.get(&id) { + webview.dom.in_runtime(|| { + ScopeId::ROOT.in_runtime(|| { + let e = eval( + r#" + const xPos = await dioxus.recv(); + const yPos = await dioxus.recv(); + window.interpreter.handleWindowsDragOver(xPos, yPos) + "#, + ); + + _ = e.send(x_pos); + _ = e.send(y_pos); + }); + }); + } + } + + UserWindowEvent::Ipc { id, msg } => match msg.method() { + IpcMethod::Initialize => app.handle_initialize_msg(id), + IpcMethod::FileDialog => app.handle_file_dialog_msg(msg, id), + IpcMethod::UserEvent => {} + IpcMethod::Query => app.handle_query_msg(msg, id), + IpcMethod::BrowserOpen => app.handle_browser_open(msg), + IpcMethod::Other(_) => {} + }, + }, + _ => {} + } + + *control_flow = app.control_flow; + }) +} + +/// Launches the WebView and runs the event loop, with configuration and root props. +pub fn launch_virtual_dom(virtual_dom: VirtualDom, desktop_config: Config) -> () { + // #[cfg(feature = "tokio_runtime")] + // { + // tokio::runtime::Builder::new_multi_thread() + // .enable_all() + // .build() + // .unwrap() + // .block_on(tokio::task::unconstrained(async move { + // launch_virtual_dom_blocking(virtual_dom, desktop_config) + // })); + + // unreachable!("The desktop launch function will never exit") + // } + + // #[cfg(not(feature = "tokio_runtime"))] + { + launch_virtual_dom_blocking(virtual_dom, desktop_config); + } +} + +/// Launches the WebView and runs the event loop, with configuration and root props. +pub fn launch( + root: fn() -> Element, + contexts: Vec Box + Send + Sync>>, + platform_config: Vec>, +) -> () { + let mut virtual_dom = VirtualDom::new(root); + + for context in contexts { + virtual_dom.insert_any_root_context(context()); + } + + let platform_config = *platform_config + .into_iter() + .find_map(|cfg| cfg.downcast::().ok()) + .unwrap_or_default(); + + launch_virtual_dom(virtual_dom, platform_config) +} diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index d4051bf4be..2d95b692cb 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -26,10 +26,17 @@ mod waker; mod webview; // mobile shortcut is only supported on mobile platforms -#[cfg(any(target_os = "ios", target_os = "android"))] +#[cfg(any(target_os = "ios", target_os = "android", target_env = "ohos"))] mod mobile_shortcut; /// The main entrypoint for this crate +#[cfg(not(target_env = "ohos"))] +#[path = "launch.rs"] +pub mod launch; + +/// The main entrypoint for this crate on OHOS +#[cfg(target_env = "ohos")] +#[path = "launch_ohos.rs"] pub mod launch; // Reexport tao and wry, might want to re-export other important things @@ -39,11 +46,14 @@ pub use tao::event::WindowEvent; pub use tao::window::WindowBuilder; pub use wry; // Reexport muda only if we are on desktop platforms that support menus -#[cfg(not(any(target_os = "ios", target_os = "android")))] +#[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] pub use muda; // Tray icon -#[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 mod trayicon; // Public exports @@ -54,5 +64,6 @@ pub use desktop_context::{ }; pub use event_handlers::WryEventHandler; pub use hooks::*; +pub use ipc::UserWindowEvent; pub use shortcut::{HotKeyState, ShortcutHandle, ShortcutRegistryError}; pub use wry::RequestAsyncResponder; diff --git a/packages/desktop/src/menubar.rs b/packages/desktop/src/menubar.rs index b63d07d174..fe9e335e5d 100644 --- a/packages/desktop/src/menubar.rs +++ b/packages/desktop/src/menubar.rs @@ -1,14 +1,14 @@ use tao::window::Window; -#[cfg(not(any(target_os = "ios", target_os = "android")))] +#[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] pub type DioxusMenu = muda::Menu; -#[cfg(any(target_os = "ios", target_os = "android"))] +#[cfg(any(target_os = "ios", target_os = "android", target_env = "ohos"))] pub type DioxusMenu = (); /// Initializes the menu bar for the window. #[allow(unused)] pub fn init_menu_bar(menu: &DioxusMenu, window: &Window) { - #[cfg(not(any(target_os = "ios", target_os = "android")))] + #[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] { desktop_platforms::init_menu_bar(menu, window); } @@ -21,13 +21,13 @@ pub fn init_menu_bar(menu: &DioxusMenu, window: &Window) { /// > by [`MenuItem`](muda::MenuItem). #[allow(unused)] pub fn default_menu_bar() -> DioxusMenu { - #[cfg(not(any(target_os = "ios", target_os = "android")))] + #[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] { desktop_platforms::default_menu_bar() } } -#[cfg(not(any(target_os = "ios", target_os = "android")))] +#[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] mod desktop_platforms { use super::*; use muda::{Menu, MenuItem, PredefinedMenuItem, Submenu}; @@ -40,7 +40,7 @@ mod desktop_platforms { menu.init_for_hwnd(window.hwnd()); } - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", not(target_env = "ohos")))] { use tao::platform::unix::WindowExtUnix; menu.init_for_gtk_window(window.gtk_window(), window.default_vbox()) diff --git a/packages/desktop/src/shortcut.rs b/packages/desktop/src/shortcut.rs index 3993012b24..9e2b55b4f5 100644 --- a/packages/desktop/src/shortcut.rs +++ b/packages/desktop/src/shortcut.rs @@ -1,18 +1,21 @@ -#[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 use global_hotkey::{ hotkey::{Code, HotKey}, Error as HotkeyError, GlobalHotKeyEvent, GlobalHotKeyManager, HotKeyState, }; -#[cfg(any(target_os = "ios", target_os = "android"))] +#[cfg(any(target_os = "ios", target_os = "android", target_env = "ohos"))] pub use crate::mobile_shortcut::*; use crate::window; @@ -64,7 +67,10 @@ impl ShortcutRegistry { } } - #[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(crate) fn call_handlers(&self, id: GlobalHotKeyEvent) { if let Some(ShortcutInner { callbacks, .. }) = self.shortcuts.borrow_mut().get_mut(&id.id) { for (_, callback) in callbacks.iter_mut() { diff --git a/packages/desktop/src/trayicon.rs b/packages/desktop/src/trayicon.rs index 8cc65f7d23..07631882be 100644 --- a/packages/desktop/src/trayicon.rs +++ b/packages/desktop/src/trayicon.rs @@ -2,31 +2,34 @@ use dioxus_core::{provide_context, try_consume_context, use_hook}; -#[cfg(not(any(target_os = "ios", target_os = "android")))] +#[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] pub use tray_icon::*; /// tray icon menu type trait -#[cfg(not(any(target_os = "ios", target_os = "android")))] +#[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] pub type DioxusTrayMenu = tray_icon::menu::Menu; -#[cfg(any(target_os = "ios", target_os = "android"))] +#[cfg(any(target_os = "ios", target_os = "android", target_env = "ohos"))] pub type DioxusTrayMenu = (); /// tray icon icon type trait -#[cfg(not(any(target_os = "ios", target_os = "android")))] +#[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] pub type DioxusTrayIcon = tray_icon::Icon; -#[cfg(any(target_os = "ios", target_os = "android"))] +#[cfg(any(target_os = "ios", target_os = "android", target_env = "ohos"))] pub type DioxusTrayIcon = (); /// tray icon type trait -#[cfg(not(any(target_os = "ios", target_os = "android")))] +#[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] pub type DioxusTray = tray_icon::TrayIcon; -#[cfg(any(target_os = "ios", target_os = "android"))] +#[cfg(any(target_os = "ios", target_os = "android", target_env = "ohos"))] pub type DioxusTray = (); /// initializes a tray icon #[allow(unused)] pub fn init_tray_icon(menu: DioxusTrayMenu, icon: Option) -> DioxusTray { - #[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") + ))] { let builder = tray_icon::TrayIconBuilder::new() .with_menu(Box::new(menu)) @@ -47,7 +50,10 @@ pub fn init_tray_icon(menu: DioxusTrayMenu, icon: Option) -> Dio /// Returns a default tray icon menu pub fn default_tray_icon() -> DioxusTrayMenu { - #[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") + ))] { use tray_icon::menu::{Menu, PredefinedMenuItem}; let tray_menu = Menu::new(); @@ -59,7 +65,10 @@ pub fn default_tray_icon() -> DioxusTrayMenu { } /// Provides a hook to the tray icon -#[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() -> Option { use_hook(try_consume_context) } diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index 14489a2bd9..f4a546e460 100644 --- a/packages/desktop/src/webview.rs +++ b/packages/desktop/src/webview.rs @@ -187,7 +187,7 @@ impl WebviewInstance { // // on mobile, we want them to be `None` so tao makes them the size of the screen. Otherwise we // get a window that is not the size of the screen and weird black bars. - #[cfg(not(any(target_os = "ios", target_os = "android")))] + #[cfg(not(any(target_os = "ios", target_os = "android", target_env = "ohos")))] { if cfg.window.window.inner_size.is_none() { window = window.with_inner_size(tao::dpi::LogicalSize::new(800.0, 600.0)); @@ -387,7 +387,11 @@ impl WebviewInstance { webview = webview.with_devtools(true); } - let menu = if cfg!(not(any(target_os = "android", target_os = "ios"))) { + let menu = if cfg!(not(any( + target_os = "android", + target_os = "ios", + target_env = "ohos" + ))) { let menu_option = cfg.menu.into(); if let Some(menu) = &menu_option { crate::menubar::init_menu_bar(menu, &window); @@ -401,7 +405,8 @@ impl WebviewInstance { target_os = "windows", target_os = "macos", target_os = "ios", - target_os = "android" + target_os = "android", + target_env = "ohos" ))] let webview = if cfg.as_child_window { webview.build_as_child(&window) @@ -413,7 +418,8 @@ impl WebviewInstance { target_os = "windows", target_os = "macos", target_os = "ios", - target_os = "android" + target_os = "android", + target_env = "ohos" )))] let webview = { use tao::platform::unix::WindowExtUnix;