mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-10 08:58:15 +08:00
✨ 调用系统命令打开目录
This commit is contained in:
12
src-tauri/Cargo.lock
generated
12
src-tauri/Cargo.lock
generated
@@ -3542,6 +3542,16 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shared_child"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signature"
|
||||
version = "2.2.0"
|
||||
@@ -4131,6 +4141,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"open",
|
||||
"os_info",
|
||||
"os_pipe",
|
||||
"percent-encoding",
|
||||
"rand 0.8.5",
|
||||
"raw-window-handle",
|
||||
@@ -4142,6 +4153,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"serialize-to-javascript",
|
||||
"shared_child",
|
||||
"state",
|
||||
"sys-locale",
|
||||
"tar",
|
||||
|
||||
@@ -17,7 +17,7 @@ chrono = "0.4.34"
|
||||
log = "0.4.20"
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.114"
|
||||
tauri = { version = "1.6.0", features = [ "shell-open", "window-set-always-on-top", "window-set-fullscreen", "dialog-message", "process-exit", "fs-read-dir", "window-hide", "os-all", "clipboard-all", "dialog-open", "dialog-save", "fs-create-dir", "fs-remove-dir", "fs-write-file", "fs-remove-file", "fs-read-file", "path-all", "fs-exists", "window-close", "window-set-title", "window-unminimize", "window-show", "window-set-focus", "http-request"] }
|
||||
tauri = { version = "1.6.0", features = [ "shell-execute", "shell-open", "window-set-always-on-top", "window-set-fullscreen", "dialog-message", "process-exit", "fs-read-dir", "window-hide", "os-all", "clipboard-all", "dialog-open", "dialog-save", "fs-create-dir", "fs-remove-dir", "fs-write-file", "fs-remove-file", "fs-read-file", "path-all", "fs-exists", "window-close", "window-set-title", "window-unminimize", "window-show", "window-set-focus", "http-request"] }
|
||||
tauri-utils = "1.5.3"
|
||||
url = "2.5.0"
|
||||
walkdir = "2.4.0"
|
||||
|
||||
@@ -61,7 +61,20 @@
|
||||
},
|
||||
"shell": {
|
||||
"all": false,
|
||||
"open": true
|
||||
"open": true,
|
||||
"execute": true,
|
||||
"scope": [
|
||||
{
|
||||
"name": "win_open",
|
||||
"cmd": "explorer",
|
||||
"args": true
|
||||
},
|
||||
{
|
||||
"name": "mac_open",
|
||||
"cmd": "open",
|
||||
"args": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
|
||||
@@ -42,11 +42,12 @@
|
||||
</v-list>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { dialog, fs } from "@tauri-apps/api";
|
||||
import { dialog, fs, path } from "@tauri-apps/api";
|
||||
|
||||
import TGSqlite from "../../plugins/Sqlite";
|
||||
import { useAppStore } from "../../store/modules/app";
|
||||
import { backUpUserData } from "../../utils/dataBS";
|
||||
import TGShell from "../../utils/TGShell";
|
||||
import showConfirm from "../func/confirm";
|
||||
import showSnackbar from "../func/snackbar";
|
||||
|
||||
@@ -175,7 +176,7 @@ async function openPath(type: "db" | "user" | "log"): Promise<void> {
|
||||
let targetPath: string;
|
||||
switch (type) {
|
||||
case "db":
|
||||
targetPath = appStore.dbPath;
|
||||
targetPath = await path.appConfigDir();
|
||||
break;
|
||||
case "user":
|
||||
targetPath = appStore.userDir;
|
||||
@@ -184,11 +185,7 @@ async function openPath(type: "db" | "user" | "log"): Promise<void> {
|
||||
targetPath = appStore.logDir;
|
||||
break;
|
||||
}
|
||||
await dialog.open({
|
||||
directory: false,
|
||||
defaultPath: targetPath,
|
||||
multiple: false,
|
||||
});
|
||||
await TGShell.openPath(targetPath);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
29
src/utils/TGShell.ts
Normal file
29
src/utils/TGShell.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @file utils/TGShell.ts
|
||||
* @description Shell工具
|
||||
* @since Beta v0.4.4
|
||||
*/
|
||||
|
||||
import { os, shell } from "@tauri-apps/api";
|
||||
|
||||
/**
|
||||
* @description Shell工具
|
||||
* @since Beta v0.4.4
|
||||
*/
|
||||
class TGShell {
|
||||
/**
|
||||
* @description 打开文件
|
||||
* @since Beta v0.4.4
|
||||
* @param {string} path - 文件路径
|
||||
* @returns {Promise<void>} 无返回值
|
||||
*/
|
||||
async openPath(path: string): Promise<void> {
|
||||
const platform = await os.platform();
|
||||
let command: string;
|
||||
if (platform === "win32") command = "win_open";
|
||||
else command = "mac_open";
|
||||
await new shell.Command(command, [path]).execute();
|
||||
}
|
||||
}
|
||||
|
||||
export default new TGShell();
|
||||
Reference in New Issue
Block a user