调用系统命令打开目录

This commit is contained in:
目棃
2024-02-29 20:09:43 +08:00
parent 0a54841585
commit 4a41a00243
5 changed files with 60 additions and 9 deletions

View File

@@ -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
View 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();