Browse Source

增加shell权限

caner 1 year ago
parent
commit
bed4145270

+ 88 - 0
src-tauri/Cargo.lock

@@ -731,6 +731,15 @@ version = "1.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7"
 
+[[package]]
+name = "encoding_rs"
+version = "0.8.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
+dependencies = [
+ "cfg-if",
+]
+
 [[package]]
 name = "equivalent"
 version = "1.0.1"
@@ -1605,6 +1614,25 @@ version = "2.11.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
 
+[[package]]
+name = "is-docker"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
+dependencies = [
+ "once_cell",
+]
+
+[[package]]
+name = "is-wsl"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
+dependencies = [
+ "is-docker",
+ "once_cell",
+]
+
 [[package]]
 name = "itoa"
 version = "0.4.8"
@@ -2236,6 +2264,18 @@ version = "1.20.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
 
+[[package]]
+name = "open"
+version = "5.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2483562e62ea94312f3576a7aca397306df7990b8d89033e18766744377ef95"
+dependencies = [
+ "dunce",
+ "is-wsl",
+ "libc",
+ "pathdiff",
+]
+
 [[package]]
 name = "openssl"
 version = "0.10.70"
@@ -2286,6 +2326,16 @@ version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
 
+[[package]]
+name = "os_pipe"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982"
+dependencies = [
+ "libc",
+ "windows-sys 0.59.0",
+]
+
 [[package]]
 name = "pango"
 version = "0.18.3"
@@ -2334,6 +2384,12 @@ dependencies = [
  "windows-targets 0.52.6",
 ]
 
+[[package]]
+name = "pathdiff"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
+
 [[package]]
 name = "percent-encoding"
 version = "2.3.1"
@@ -3279,6 +3335,16 @@ dependencies = [
  "digest",
 ]
 
+[[package]]
+name = "shared_child"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09fa9338aed9a1df411814a5b2252f7cd206c55ae9bf2fa763f8de84603aa60c"
+dependencies = [
+ "libc",
+ "windows-sys 0.59.0",
+]
+
 [[package]]
 name = "shlex"
 version = "1.3.0"
@@ -3698,6 +3764,27 @@ dependencies = [
  "url",
 ]
 
+[[package]]
+name = "tauri-plugin-shell"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb2c50a63e60fb8925956cc5b7569f4b750ac197a4d39f13b8dd46ea8e2bad79"
+dependencies = [
+ "encoding_rs",
+ "log",
+ "open",
+ "os_pipe",
+ "regex",
+ "schemars",
+ "serde",
+ "serde_json",
+ "shared_child",
+ "tauri",
+ "tauri-plugin",
+ "thiserror 2.0.11",
+ "tokio",
+]
+
 [[package]]
 name = "tauri-runtime"
 version = "2.3.0"
@@ -3824,6 +3911,7 @@ dependencies = [
  "tauri",
  "tauri-build",
  "tauri-plugin-mqtt",
+ "tauri-plugin-shell",
 ]
 
 [[package]]

+ 1 - 0
src-tauri/Cargo.toml

@@ -22,3 +22,4 @@ tauri = { version = "2.2.5", features = ["macos-private-api"] }
 serde = { version = "1", features = ["derive"] }
 serde_json = "1"
 tauri-plugin-mqtt = "0.1.1"
+tauri-plugin-shell = "2"

+ 4 - 3
src-tauri/capabilities/default.json

@@ -7,13 +7,14 @@
   ],
   "permissions": [
     "core:default",
+    "mqtt:default",
+    "shell:allow-open",
     "core:window:default",
+    "core:resources:default",
     "core:window:allow-start-dragging",
     "core:window:allow-close",
     "core:window:allow-maximize",
     "core:window:allow-minimize",
-    "core:window:allow-internal-toggle-maximize",
-    "mqtt:default",
-    "core:resources:default"
+    "core:window:allow-internal-toggle-maximize"
   ]
 }

+ 1 - 0
src-tauri/src/lib.rs

@@ -1,6 +1,7 @@
 
 pub fn run() {
     tauri::Builder::default()
+        .plugin(tauri_plugin_shell::init())
         .plugin(tauri_plugin_mqtt::init())
         .invoke_handler(tauri::generate_handler![])
         .run(tauri::generate_context!())

+ 2 - 1
src/components/mic.vue

@@ -38,8 +38,9 @@ async function initMic() {
       emit('callBack', blob)
     }
   } catch (error: any) {
+    console.log('录音错误', error)
     const type = error.toString().includes('getUserMedia')
-    notice.warning({ title: type ? '不支持webrtc音频' : '未获取到音频设备' })
+    notice.warning({ title: type ? '不支持webrtc音频' : '未获取到音频设备', duration: 2000 })
   }
 }