From 3c7ea76d2d36d3ea3d3467ee23f7645a202348eb Mon Sep 17 00:00:00 2001 From: medcl Date: Wed, 19 Feb 2025 13:07:49 +0800 Subject: [PATCH] fix: open url for linux --- package.json | 1 + pnpm-lock.yaml | 23 ++--- src-tauri/Cargo.lock | 137 ++++++++++++++++++++++++++++ src-tauri/Cargo.toml | 1 + src-tauri/capabilities/default.json | 9 +- src-tauri/src/lib.rs | 1 + src-tauri/src/util/mod.rs | 7 ++ src-tauri/tauri.conf.json | 4 +- 8 files changed, 168 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 3acdd2c7..2f3ba45e 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@tauri-apps/plugin-dialog": "^2.2.0", "@tauri-apps/plugin-global-shortcut": "~2.0.0", "@tauri-apps/plugin-http": "~2.0.1", + "@tauri-apps/plugin-opener": "~2", "@tauri-apps/plugin-os": "^2.2.0", "@tauri-apps/plugin-shell": ">=2.0.0", "@tauri-apps/plugin-updater": "^2.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39e7f04d..3beb953f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: '@tauri-apps/plugin-http': specifier: ~2.0.1 version: 2.0.1 + '@tauri-apps/plugin-opener': + specifier: ~2 + version: 2.2.5 '@tauri-apps/plugin-os': specifier: ^2.2.0 version: 2.2.0 @@ -557,55 +560,46 @@ packages: resolution: {integrity: sha512-0KXvIJQMOImLCVCz9uvvdPgfyWo93aHHp8ui3FrtOP57svqrF/roSSR5pjqL2hcMp0ljeGlU4q9o/rQaAQ3AYA==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.24.0': resolution: {integrity: sha512-it2BW6kKFVh8xk/BnHfakEeoLPv8STIISekpoF+nBgWM4d55CZKc7T4Dx1pEbTnYm/xEKMgy1MNtYuoA8RFIWw==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.24.0': resolution: {integrity: sha512-i0xTLXjqap2eRfulFVlSnM5dEbTVque/3Pi4g2y7cxrs7+a9De42z4XxKLYJ7+OhE3IgxvfQM7vQc43bwTgPwA==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.24.0': resolution: {integrity: sha512-9E6MKUJhDuDh604Qco5yP/3qn3y7SLXYuiC0Rpr89aMScS2UAmK1wHP2b7KAa1nSjWJc/f/Lc0Wl1L47qjiyQw==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-powerpc64le-gnu@4.24.0': resolution: {integrity: sha512-2XFFPJ2XMEiF5Zi2EBf4h73oR1V/lycirxZxHZNc93SqDN/IWhYYSYj8I9381ikUFXZrz2v7r2tOVk2NBwxrWw==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.24.0': resolution: {integrity: sha512-M3Dg4hlwuntUCdzU7KjYqbbd+BLq3JMAOhCKdBE3TcMGMZbKkDdJ5ivNdehOssMCIokNHFOsv7DO4rlEOfyKpg==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.24.0': resolution: {integrity: sha512-mjBaoo4ocxJppTorZVKWFpy1bfFj9FeCMJqzlMQGjpNPY9JwQi7OuS1axzNIk0nMX6jSgy6ZURDZ2w0QW6D56g==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.24.0': resolution: {integrity: sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.24.0': resolution: {integrity: sha512-w1i+L7kAXZNdYl+vFvzSZy8Y1arS7vMgIy8wusXJzRrPyof5LAb02KGr1PD2EkRcl73kHulIID0M501lN+vobQ==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.24.0': resolution: {integrity: sha512-VXBrnPWgBpVDCVY6XF3LEW0pOU51KbaHhccHw6AS6vBWIC60eqsH19DAeeObl+g8nKAz04QFdl/Cefta0xQtUQ==} @@ -664,28 +658,24 @@ packages: engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [glibc] '@tauri-apps/cli-linux-arm64-musl@2.2.7': resolution: {integrity: sha512-+8HZ+txff/Y3YjAh80XcLXcX8kpGXVdr1P8AfjLHxHdS6QD4Md+acSxGTTNbplmHuBaSHJvuTvZf9tU1eDCTDg==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [musl] '@tauri-apps/cli-linux-x64-gnu@2.2.7': resolution: {integrity: sha512-ahlSnuCnUntblp9dG7/w5ZWZOdzRFi3zl0oScgt7GF4KNAOEa7duADsxPA4/FT2hLRa0SvpqtD4IYFvCxoVv3Q==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [glibc] '@tauri-apps/cli-linux-x64-musl@2.2.7': resolution: {integrity: sha512-+qKAWnJRSX+pjjRbKAQgTdFY8ecdcu8UdJ69i7wn3ZcRn2nMMzOO2LOMOTQV42B7/Q64D1pIpmZj9yblTMvadA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [musl] '@tauri-apps/cli-win32-arm64-msvc@2.2.7': resolution: {integrity: sha512-aa86nRnrwT04u9D9fhf5JVssuAZlUCCc8AjqQjqODQjMd4BMA2+d4K9qBMpEG/1kVh95vZaNsLogjEaqSTTw4A==} @@ -725,6 +715,9 @@ packages: '@tauri-apps/plugin-http@2.0.1': resolution: {integrity: sha512-j6IA3pVBybSCwPpsihpX4z8bs6PluuGtr06ahL/xy4D8HunNBTmRmadJrFOQi0gOAbaig4MkQ15nzNLBLy8R1A==} + '@tauri-apps/plugin-opener@2.2.5': + resolution: {integrity: sha512-hHsJ9RPWpZvZEPVFaL+d25gABMUMOf/A6ESXnvf/ii9guTukj58WXsAE/SOysXRIhej7kseRCxnOnIMpSCdUsQ==} + '@tauri-apps/plugin-os@2.2.0': resolution: {integrity: sha512-HszbCdbisMlu5QhCNAN8YIWyz2v33abAWha6+uvV2CKX8P5VSct/y+kEe22JeyqrxCnWlQ3DRx7s49Byg7/0EA==} @@ -2796,6 +2789,10 @@ snapshots: dependencies: '@tauri-apps/api': 2.2.0 + '@tauri-apps/plugin-opener@2.2.5': + dependencies: + '@tauri-apps/api': 2.2.0 + '@tauri-apps/plugin-os@2.2.0': dependencies: '@tauri-apps/api': 2.2.0 diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 95aba01d..f1545064 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -683,6 +683,7 @@ dependencies = [ "tauri-plugin-fs", "tauri-plugin-global-shortcut", "tauri-plugin-http", + "tauri-plugin-opener", "tauri-plugin-os", "tauri-plugin-process", "tauri-plugin-shell", @@ -4924,6 +4925,28 @@ dependencies = [ "urlpattern", ] +[[package]] +name = "tauri-plugin-opener" +version = "2.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "635ed7c580dc3cdc61c94097d38ef517d749ffc0141c806d904e68e4b0cf1c2a" +dependencies = [ + "dunce", + "glob", + "objc2-app-kit", + "objc2-foundation", + "open", + "schemars", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.6", + "url", + "windows 0.58.0", + "zbus 5.4.0", +] + [[package]] name = "tauri-plugin-os" version = "2.2.0" @@ -6437,6 +6460,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59690dea168f2198d1a3b0cac23b8063efcd11012f10ae4698f284808c8ef603" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.10.1" @@ -6621,6 +6653,42 @@ dependencies = [ "zvariant 4.2.0", ] +[[package]] +name = "zbus" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbddd8b6cb25d5d8ec1b23277b45299a98bfb220f1761ca11e186d5c702507f8" +dependencies = [ + "async-broadcast 0.7.2", + "async-executor", + "async-fs 2.1.2", + "async-io 2.4.0", + "async-lock 3.4.0", + "async-process 2.3.0", + "async-recursion", + "async-task", + "async-trait", + "blocking", + "enumflags2", + "event-listener 5.3.1", + "futures-core", + "futures-util", + "hex", + "nix 0.29.0", + "ordered-stream", + "serde", + "serde_repr", + "static_assertions", + "tracing", + "uds_windows", + "windows-sys 0.59.0", + "winnow 0.7.2", + "xdg-home", + "zbus_macros 5.4.0", + "zbus_names 4.2.0", + "zvariant 5.4.0", +] + [[package]] name = "zbus_macros" version = "3.15.2" @@ -6648,6 +6716,21 @@ dependencies = [ "zvariant_utils 2.1.0", ] +[[package]] +name = "zbus_macros" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac404d48b4e9cf193c8b49589f3280ceca5ff63519e7e64f55b4cf9c47ce146" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 2.0.90", + "zbus_names 4.2.0", + "zvariant 5.4.0", + "zvariant_utils 3.2.0", +] + [[package]] name = "zbus_names" version = "2.6.1" @@ -6670,6 +6753,18 @@ dependencies = [ "zvariant 4.2.0", ] +[[package]] +name = "zbus_names" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7be68e64bf6ce8db94f63e72f0c7eb9a60d733f7e0499e628dfab0f84d6bcb97" +dependencies = [ + "serde", + "static_assertions", + "winnow 0.7.2", + "zvariant 5.4.0", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -6740,6 +6835,21 @@ dependencies = [ "zvariant_derive 4.2.0", ] +[[package]] +name = "zvariant" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2df9ee044893fcffbdc25de30546edef3e32341466811ca18421e3cd6c5a3ac" +dependencies = [ + "endi", + "enumflags2", + "serde", + "static_assertions", + "winnow 0.7.2", + "zvariant_derive 5.4.0", + "zvariant_utils 3.2.0", +] + [[package]] name = "zvariant_derive" version = "3.15.2" @@ -6766,6 +6876,19 @@ dependencies = [ "zvariant_utils 2.1.0", ] +[[package]] +name = "zvariant_derive" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74170caa85b8b84cc4935f2d56a57c7a15ea6185ccdd7eadb57e6edd90f94b2f" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 2.0.90", + "zvariant_utils 3.2.0", +] + [[package]] name = "zvariant_utils" version = "1.0.1" @@ -6787,3 +6910,17 @@ dependencies = [ "quote", "syn 2.0.90", ] + +[[package]] +name = "zvariant_utils" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16edfee43e5d7b553b77872d99bc36afdda75c223ca7ad5e3fbecd82ca5fc34" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "static_assertions", + "syn 2.0.90", + "winnow 0.7.2", +] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2a0572f9..bfd5af2e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -52,6 +52,7 @@ plist = "1.7" base64 = "0.13" walkdir = "2" fuzzy_prefix_search = "0.2" +tauri-plugin-opener = "2" [target."cfg(target_os = \"macos\")".dependencies] tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" } diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 522a9abb..b9d79579 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -32,7 +32,6 @@ "core:window:allow-get-all-windows", "core:window:allow-set-focus", "core:app:allow-set-app-theme", - "shell:default", "http:default", "http:allow-fetch", "http:allow-fetch-cancel", @@ -49,6 +48,14 @@ "global-shortcut:allow-unregister", "global-shortcut:allow-unregister-all", "theme:default", + "core:event:default", + "shell:default", + "shell:allow-open", + "shell:allow-kill", + "shell:allow-spawn", + "shell:allow-execute", + "opener:allow-default-urls", + "core:event:default", "deep-link:allow-get-current", "deep-link:default", "deep-link:allow-register", diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 9d3ae11b..6166a37d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -77,6 +77,7 @@ pub fn run() { let app = app_builder .invoke_handler(tauri::generate_handler![ + util::open_url, change_window_height, shortcut::change_shortcut, shortcut::unregister_shortcut, diff --git a/src-tauri/src/util/mod.rs b/src-tauri/src/util/mod.rs index e69de29b..979bf5fe 100644 --- a/src-tauri/src/util/mod.rs +++ b/src-tauri/src/util/mod.rs @@ -0,0 +1,7 @@ +#[tauri::command] +pub fn open_url(url: String) -> Result<(), String> { + match tauri_plugin_opener::open_url(&url, None::<&str>) { + Ok(_) => Ok(()), + Err(e) => Err(format!("Failed to open URL: {}", e)), + } +} \ No newline at end of file diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index cc754d67..78112465 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -127,7 +127,9 @@ ] }, "websocket": {}, - "shell": {}, + "shell": { + "open": true + }, "globalShortcut": {}, "deep-link": { "schema": "coco", -- Gitee