mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-21 04:49:46 +08:00
♻️ use opener instead of window.open/shell
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
/**
|
||||
* @file utils/TGClient.ts
|
||||
* @desc 负责米游社客户端的 callback 处理
|
||||
* @since Beta v0.6.3
|
||||
* @since Beta v0.7.2
|
||||
*/
|
||||
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import TGSqlite from "@Sqlite/index.js";
|
||||
import { core, event, webviewWindow } from "@tauri-apps/api";
|
||||
import type { Event, UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
|
||||
import { parseLink } from "./linkParser.js";
|
||||
import TGLogger from "./TGLogger.js";
|
||||
@@ -709,7 +710,7 @@ class Client {
|
||||
): Promise<void> {
|
||||
console.log(`[openSystemBrowser] ${JSON.stringify(arg)}`);
|
||||
const url = arg.payload.open_url;
|
||||
window.open(url);
|
||||
await openUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* @file utils/TGShell.ts
|
||||
* @description Shell工具
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { Command } from "@tauri-apps/plugin-shell";
|
||||
|
||||
/**
|
||||
* @description Shell工具
|
||||
* @since Beta v0.5.0
|
||||
*/
|
||||
class Shell {
|
||||
private constructor() {}
|
||||
|
||||
private static instance: Shell | null = null;
|
||||
|
||||
static getInstance(): Shell {
|
||||
if (this.instance === null) this.instance = new Shell();
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打开文件
|
||||
* @since Beta v0.5.0
|
||||
* @param {string} path - 文件路径
|
||||
* @returns {Promise<void>} 无返回值
|
||||
*/
|
||||
async openPath(path: string): Promise<void> {
|
||||
const plat = platform();
|
||||
let command: string;
|
||||
if (plat !== "windows" && plat !== "macos") {
|
||||
showSnackbar.warn("暂不支持该平台");
|
||||
return;
|
||||
}
|
||||
if (plat === "windows") command = "win_open";
|
||||
else command = "mac_open";
|
||||
await Command.create(command, [path]).execute();
|
||||
}
|
||||
}
|
||||
|
||||
const TGShell = Shell.getInstance();
|
||||
|
||||
export default TGShell;
|
||||
Reference in New Issue
Block a user