🐛 修复一些bug

*修复窗口`destory`失败
*修复`miyoushe`域名不识别
*修复子窗口权限报错
This commit is contained in:
目棃
2024-08-27 22:37:47 +08:00
parent 1cd6c3c42d
commit 021a141546
10 changed files with 118 additions and 35 deletions

View File

@@ -124,7 +124,6 @@ function onAvatarClick(avatar: TGApp.Sqlite.Character.UserRole): void {
.tdo-avatar {
cursor: pointer;
transform: translateY(-10px);
}
.tdo-card-container {

View File

@@ -67,14 +67,16 @@
<img src="/source/UI/empty.webp" alt="empty" />
</div>
</div>
<TuaDetailOverlay
v-model="showOverlay"
:avatar="dataVal"
:avatars="selectedList"
v-model:mode="showMode"
@to-next="handleSwitch"
@to-avatar="selectRole"
/>
<suspense>
<TuaDetailOverlay
v-model="showOverlay"
:avatar="dataVal"
:avatars="selectedList"
v-model:mode="showMode"
@to-next="handleSwitch"
@to-avatar="selectRole"
/>
</suspense>
<TwoSelectC v-model="showSelect" @select-c="handleSelect" v-model:reset="resetSelect" />
</template>
<script lang="ts" setup>
@@ -310,7 +312,9 @@ function getUpdateTime(): string {
function selectRole(role: TGApp.Sqlite.Character.UserRole): void {
dataVal.value = role;
selectIndex.value = roleList.value.indexOf(role);
if (!showOverlay.value) showOverlay.value = true;
if (!showOverlay.value) {
showOverlay.value = true;
}
}
function handleSelect(val: SelectedCValue) {

View File

@@ -1,7 +1,7 @@
/**
* @file utils/TGClient.ts
* @desc 负责米游社客户端的 callback 处理
* @since Beta v0.5.1
* @since Beta v0.5.5
*/
import { event, core, webviewWindow } from "@tauri-apps/api";
@@ -436,7 +436,7 @@ class TGClient {
/**
* @func open
* @since Beta v0.5.0
* @since Beta v0.5.5
* @desc 打开米游社客户端
* @param {string} func - 方法名
* @param {string} url - url
@@ -446,7 +446,7 @@ class TGClient {
if (url === undefined) url = this.getUrl(func);
this.route = [url];
await TGLogger.Info(`[TGClient][open][${func}] ${url}`);
const windowFind = webviewWindow.WebviewWindow.getByLabel("mhy_client");
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind !== null) {
try {
await windowFind.destroy();
@@ -455,6 +455,7 @@ class TGClient {
text: `[TGClient][open] ${e}`,
color: "error",
});
await TGLogger.Error(`[TGClient][open] ${e}`);
}
}
await core.invoke<InvokeArg>("create_mhy_client", { func, url });
@@ -472,7 +473,10 @@ class TGClient {
async closePage(arg: TGApp.Plugins.JSBridge.NullArg): Promise<void> {
this.route.pop();
if (this.route.length === 0) {
await webviewWindow.WebviewWindow.getByLabel("mhy_client")?.destroy();
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind != null) {
await windowFind.destroy();
}
return;
}
const url = this.route[this.route.length - 1];
@@ -578,7 +582,7 @@ class TGClient {
/**
* @func getCookieToken
* @since Beta v0.5.0
* @since Beta v0.5.5
* @desc 获取米游社客户端的 cookie_token
* @param {TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.GetCookieTokenPayload>} arg - 请求参数
* @returns {void} - 无返回值
@@ -598,14 +602,20 @@ class TGClient {
}
// todo 优化代码
const executeJS = `javascript:(function(){
document.cookie = "account_id_v2=${user.cookie.account_id};domain=.mihoyo.com;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "cookie_token=${user.cookie.cookie_token};domain=.mihoyo.com;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltuid_v2=${user.cookie.ltuid};domain=.mihoyo.com;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltoken=${user.cookie.ltoken};domain=.mihoyo.com;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "account_id=${user.cookie.account_id};domain=.mihoyo.com;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "account_mid_v2=${user.cookie.mid};domain=.mihoyo.com;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltuid_v2=${user.cookie.ltuid};domain=.mihoyo.com;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltmid_v2=${user.cookie.mid};domain=.mihoyo.com;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
let domainCur = window.location.hostname;
if(domainCur.endsWith('.miyoushe.com')) {
domainCur = '.miyoushe.com';
} else {
domainCur = '.mihoyo.com';
}
document.cookie = "account_id_v2=${user.cookie.account_id};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "cookie_token=${user.cookie.cookie_token};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltuid_v2=${user.cookie.ltuid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltoken=${user.cookie.ltoken};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "account_id=${user.cookie.account_id};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "account_mid_v2=${user.cookie.mid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltuid_v2=${user.cookie.ltuid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = "ltmid_v2=${user.cookie.mid};domain=" + domainCur + ";path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
})();`;
console.info(`[getCookieToken] ${executeJS}`);
await core.invoke("execute_js", { label: "mhy_client", js: executeJS });
@@ -720,7 +730,7 @@ class TGClient {
/**
* @func openApplication
* @since Beta v0.5.0
* @since Beta v0.5.5
* @desc 打开应用
* @param {TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.OpenApplicationPayload>} arg - 方法参数
* @returns {void} - 无返回值
@@ -729,7 +739,7 @@ class TGClient {
arg: TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.OpenApplicationPayload>,
): Promise<void> {
console.log(`[openApplication] ${JSON.stringify(arg.payload)}`);
const appWindow = webviewWindow.WebviewWindow.getByLabel("TeyvatGuide");
const appWindow = await webviewWindow.WebviewWindow.getByLabel("TeyvatGuide");
await appWindow?.setFocus();
showSnackbar({
text: `不支持的操作OpenApplication(${JSON.stringify(arg.payload)})`,
@@ -740,7 +750,7 @@ class TGClient {
resolve();
}, 1500);
});
const windowFind = webviewWindow.WebviewWindow.getByLabel("mhy_client");
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind !== null) {
await windowFind.setFocus();
}
@@ -748,7 +758,7 @@ class TGClient {
/**
* @func pushPage
* @since Beta v0.5.0
* @since Beta v0.5.5
* @desc 打开米游社客户端的页面
* @param {TGApp.Plugins.JSBridge.Arg<TGApp.Plugins.JSBridge.PushPagePayload>} arg - 方法参数
* @returns {Promise<void>} - 无返回值
@@ -758,8 +768,10 @@ class TGClient {
): Promise<void> {
const res = await parseLink(arg.payload.page, true);
if (!res) {
const appWindow = webviewWindow.WebviewWindow.getByLabel("TeyvatGuide");
await appWindow?.setFocus();
const appWindow = await webviewWindow.WebviewWindow.getByLabel("TeyvatGuide");
if (appWindow != null) {
await appWindow.setFocus();
}
showSnackbar({
text: `未知链接:${arg.payload.page}`,
color: "error",
@@ -770,7 +782,7 @@ class TGClient {
resolve();
}, 3000);
});
const windowFind = webviewWindow.WebviewWindow.getByLabel("mhy_client");
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind !== null) {
await windowFind.setFocus();
}
@@ -786,7 +798,7 @@ class TGClient {
await this.loadJSBridge();
await this.hideSideBar();
await this.hideOverlay();
const windowFind = webviewWindow.WebviewWindow.getByLabel("mhy_client");
const windowFind = await webviewWindow.WebviewWindow.getByLabel("mhy_client");
if (windowFind !== null) {
await windowFind.show();
await windowFind.setFocus();

View File

@@ -1,7 +1,7 @@
/**
* @file src/utils/linkParser.ts
* @description 处理链接
* @since Beta v0.5.1
* @since Beta v0.5.5
*/
import { emit } from "@tauri-apps/api/event";
@@ -52,7 +52,7 @@ export async function parsePost(link: string): Promise<false | string> {
/**
* @function parseLink
* @since Beta v0.5.1
* @since Beta v0.5.5
* @description 处理链接
* @param {string} link - 链接
* @param {boolean} useInner - 是否采用内置 JSBridge 打开
@@ -133,6 +133,7 @@ export async function parseLink(
"act.mihoyo.com",
"mhyurl.cn",
"webstatic.mihoyo.com",
"webstatic.miyoushe.com",
"bbs.mihoyo.com",
"qaa.miyoushe.com",
];

View File

@@ -9,7 +9,6 @@
</div>
</template>
<script lang="ts" setup>
import { webviewWindow } from "@tauri-apps/api";
import { onMounted, reactive, ref } from "vue";
import JsonViewer from "vue-json-viewer";
import { useRoute } from "vue-router";
@@ -17,6 +16,7 @@ import { useRoute } from "vue-router";
import TSwitchTheme from "../components/app/t-switchTheme.vue";
import ToLoading from "../components/overlay/to-loading.vue";
import Mys from "../plugins/Mys/index.js";
import TGLogger from "../utils/TGLogger.js";
// loading
const loading = ref<boolean>(true);
@@ -41,16 +41,19 @@ onMounted(async () => {
} catch (e) {
loadingTitle.value = "获取数据失败";
loadingEmpty.value = true;
await TGLogger.Error(`[${postId}]获取帖子数据失败:${e}`);
return;
}
try {
parseData = JSON.parse(jsonData.post.content);
} catch (e) {
} catch (err) {
try {
parseData = JSON.parse(jsonData.post.structured_content);
} catch (e) {
isEmpty.value = true;
await TGLogger.Error(`[${postId}]解析帖子数据失败:${e}`);
}
console.warn(`[${postId}]解析帖子数据失败:${err}`);
}
loading.value = false;
});