mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-16 04:03:17 +08:00
♻️ use opener instead of window.open/shell
This commit is contained in:
@@ -21,6 +21,7 @@ import { app, core, event, webviewWindow } from "@tauri-apps/api";
|
||||
import type { Event, UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";
|
||||
import { mkdir } from "@tauri-apps/plugin-fs";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
@@ -233,7 +234,7 @@ async function checkUpdate(): Promise<void> {
|
||||
buildTime.value = getBuildTime();
|
||||
await TGSqlite.update();
|
||||
showSnackbar.success("数据库已更新!", 3000);
|
||||
window.open("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");
|
||||
await openUrl("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import TMiImg from "@comp/app/t-mi-img.vue";
|
||||
import showDialog from "@comp/func/dialog.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { emit } from "@tauri-apps/api/event";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref, shallowRef, watch } from "vue";
|
||||
|
||||
@@ -93,7 +94,7 @@ async function toNav(item: TGApp.BBS.Navigator.Navigator): Promise<void> {
|
||||
}
|
||||
// 如果不在上面的域名里面,就直接打开
|
||||
if (!mysList.includes(link.origin)) {
|
||||
window.open(item.app_path);
|
||||
await openUrl(item.app_path);
|
||||
return;
|
||||
}
|
||||
if (item.name === "签到福利" || item.name === "每日签到") {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { app } from "@tauri-apps/api";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
@@ -33,24 +34,24 @@ const versionApp = ref<string>();
|
||||
|
||||
onMounted(async () => (versionApp.value = await app.getVersion()));
|
||||
|
||||
function toRelease(): void {
|
||||
window.open("https://github.com/BTMuli/TeyvatGuide/releases/latest");
|
||||
async function toRelease(): Promise<void> {
|
||||
await openUrl("https://github.com/BTMuli/TeyvatGuide/releases/latest");
|
||||
}
|
||||
|
||||
function toGroup(): void {
|
||||
window.open("https://h5.qun.qq.com/s/3cgX0hJ4GA");
|
||||
async function toGroup(): Promise<void> {
|
||||
await openUrl("https://h5.qun.qq.com/s/3cgX0hJ4GA");
|
||||
}
|
||||
|
||||
function toGithub(): void {
|
||||
window.open("https://github.com/BTMuli/TeyvatGuide");
|
||||
async function toGithub(): Promise<void> {
|
||||
await openUrl("https://github.com/BTMuli/TeyvatGuide");
|
||||
}
|
||||
|
||||
function toStore(): void {
|
||||
window.open("https://www.microsoft.com/store/productId/9NLBNNNBNSJN");
|
||||
async function toStore(): Promise<void> {
|
||||
await openUrl("https://www.microsoft.com/store/productId/9NLBNNNBNSJN");
|
||||
}
|
||||
|
||||
function toSite(): void {
|
||||
window.open("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");
|
||||
async function toSite(): Promise<void> {
|
||||
await openUrl("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<template #append>
|
||||
<div class="config-opers">
|
||||
<v-icon @click="confirmCUD()" title="修改用户数据目录"> mdi-pencil</v-icon>
|
||||
<v-icon @click="openPath('user')" title="打开用户数据目录"> mdi-folder-open</v-icon>
|
||||
<v-icon @click="openDataPath('user')" title="打开用户数据目录"> mdi-folder-open</v-icon>
|
||||
<v-icon @click="copyPath('user')" title="复制用户数据目录路径"> mdi-content-copy</v-icon>
|
||||
</div>
|
||||
</template>
|
||||
@@ -24,7 +24,7 @@
|
||||
</template>
|
||||
<template #append>
|
||||
<div class="config-opers">
|
||||
<v-icon @click="openPath('db')" title="打开数据库目录"> mdi-folder-open</v-icon>
|
||||
<v-icon @click="openDataPath('db')" title="打开数据库目录"> mdi-folder-open</v-icon>
|
||||
<v-icon @click="copyPath('db')" title="复制数据库目录路径"> mdi-content-copy</v-icon>
|
||||
</div>
|
||||
</template>
|
||||
@@ -38,7 +38,7 @@
|
||||
<template #append>
|
||||
<div class="config-opers">
|
||||
<v-icon @click="confirmCGD()" title="修改游戏安装目录"> mdi-pencil</v-icon>
|
||||
<v-icon @click="openPath('game')" title="打开游戏安装目录"> mdi-folder-open</v-icon>
|
||||
<v-icon @click="openDataPath('game')" title="打开游戏安装目录"> mdi-folder-open</v-icon>
|
||||
<v-icon @click="copyPath('game')" title="复制游戏安装目录"> mdi-content-copy</v-icon>
|
||||
</div>
|
||||
</template>
|
||||
@@ -52,7 +52,7 @@
|
||||
<template #append>
|
||||
<div class="config-opers">
|
||||
<v-icon @click="confirmCLD()" title="清理日志文件"> mdi-delete</v-icon>
|
||||
<v-icon @click="openPath('log')" title="打开日志目录"> mdi-folder-open</v-icon>
|
||||
<v-icon @click="openDataPath('log')" title="打开日志目录"> mdi-folder-open</v-icon>
|
||||
<v-icon @click="copyPath('log')" title="复制日志目录路径"> mdi-content-copy</v-icon>
|
||||
</div>
|
||||
</template>
|
||||
@@ -68,13 +68,13 @@ import { path } from "@tauri-apps/api";
|
||||
import { sep } from "@tauri-apps/api/path";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { exists, readDir, remove } from "@tauri-apps/plugin-fs";
|
||||
import { openPath } from "@tauri-apps/plugin-opener";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted } from "vue";
|
||||
|
||||
import { useAppStore } from "@/store/modules/app.js";
|
||||
import { backUpUserData } from "@/utils/dataBS.js";
|
||||
import TGShell from "@/utils/TGShell.js";
|
||||
|
||||
const { dbPath, logDir, userDir, gameDir } = storeToRefs(useAppStore());
|
||||
|
||||
@@ -225,7 +225,7 @@ function copyPath(type: "db" | "user" | "log" | "game"): void {
|
||||
showSnackbar.success(`${targetName}路径已复制!`);
|
||||
}
|
||||
|
||||
async function openPath(type: "db" | "user" | "log" | "game"): Promise<void> {
|
||||
async function openDataPath(type: "db" | "user" | "log" | "game"): Promise<void> {
|
||||
let targetPath: string;
|
||||
switch (type) {
|
||||
case "db":
|
||||
@@ -245,7 +245,7 @@ async function openPath(type: "db" | "user" | "log" | "game"): Promise<void> {
|
||||
targetPath = gameDir.value;
|
||||
break;
|
||||
}
|
||||
await TGShell.openPath(targetPath);
|
||||
await openPath(targetPath);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<v-list class="config-list">
|
||||
<v-list-subheader :inset="true" class="config-header" title="相关信息" />
|
||||
<v-divider :inset="true" class="border-opacity-75" />
|
||||
<v-list-item title="Tauri 版本" @click="toOuter('https://v2.tauri.app/')">
|
||||
<v-list-item title="Tauri 版本" @click="openUrl('https://v2.tauri.app/')">
|
||||
<template #prepend>
|
||||
<v-img class="config-icon" src="/platforms/tauri.webp" alt="Tauri" />
|
||||
</template>
|
||||
@@ -77,6 +77,7 @@ import showSnackbar from "@comp/func/snackbar.js";
|
||||
import TGSqlite from "@Sqlite/index.js";
|
||||
import TSUserAchi from "@Sqlite/modules/userAchi.js";
|
||||
import { app } from "@tauri-apps/api";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { platform, version } from "@tauri-apps/plugin-os";
|
||||
import { onMounted, ref, shallowRef } from "vue";
|
||||
|
||||
@@ -123,10 +124,6 @@ onMounted(async () => {
|
||||
await TGLogger.Error(`加载数据库错误: ${e}`);
|
||||
}
|
||||
});
|
||||
|
||||
function toOuter(url: string): void {
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
.config-header {
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
<script lang="ts" setup>
|
||||
import TMiImg from "@comp/app/t-mi-img.vue";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
|
||||
import { parseLink } from "@/utils/linkParser.js";
|
||||
@@ -85,7 +86,7 @@ async function openPosition(): Promise<void> {
|
||||
showSnackbar.warn(`未知链接:${props.pos.url}`, 3000);
|
||||
return;
|
||||
}
|
||||
window.open(props.pos.url);
|
||||
await openUrl(props.pos.url);
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<script lang="ts" setup>
|
||||
import TMiImg from "@comp/app/t-mi-img.vue";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { computed, toRaw } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
@@ -62,7 +63,7 @@ async function toLink(): Promise<void> {
|
||||
showSnackbar.error(`未知链接:${link}`, 3000);
|
||||
return;
|
||||
}
|
||||
window.open(res);
|
||||
await openUrl(res);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { onMounted, ref, shallowRef, StyleValue, toRaw } from "vue";
|
||||
|
||||
import { parseLink, parsePost } from "@/utils/linkParser.js";
|
||||
@@ -107,7 +108,7 @@ async function toLink(): Promise<void> {
|
||||
showSnackbar.error(`未知链接:${link}`, 3000);
|
||||
return;
|
||||
}
|
||||
window.open(res);
|
||||
await openUrl(res);
|
||||
}
|
||||
|
||||
// 解析表情链接
|
||||
|
||||
@@ -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