mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-18 10:18:14 +08:00
♻️ 姑且没登录的功能都给试了下
This commit is contained in:
@@ -1,28 +1,35 @@
|
||||
/**
|
||||
* @file utils/TGShell.ts
|
||||
* @description Shell工具
|
||||
* @since Beta v0.4.4
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import { os, shell } from "@tauri-apps/api";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { Command } from "@tauri-apps/plugin-shell";
|
||||
|
||||
import showSnackbar from "../components/func/snackbar.js";
|
||||
|
||||
/**
|
||||
* @description Shell工具
|
||||
* @since Beta v0.4.4
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
class TGShell {
|
||||
/**
|
||||
* @description 打开文件
|
||||
* @since Beta v0.4.4
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} path - 文件路径
|
||||
* @returns {Promise<void>} 无返回值
|
||||
*/
|
||||
async openPath(path: string): Promise<void> {
|
||||
const platform = await os.platform();
|
||||
const plat = platform();
|
||||
let command: string;
|
||||
if (platform === "win32") command = "win_open";
|
||||
else command = "mac_open";
|
||||
await new shell.Command(command, [path]).execute();
|
||||
if (plat === "windows") command = "win_open";
|
||||
else if (plat === "macos") command = "mac_open";
|
||||
else {
|
||||
showSnackbar({ text: "暂不支持该平台", color: "warn" });
|
||||
return;
|
||||
}
|
||||
await Command.create(command, [path]).execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user