Skip to content

Commit

Permalink
🐛 修复一些bug
Browse files Browse the repository at this point in the history
*修复窗口`destory`失败
*修复`miyoushe`域名不识别
*修复子窗口权限报错
  • Loading branch information
BTMuli committed Aug 27, 2024
1 parent 1cd6c3c commit 021a141
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 35 deletions.
1 change: 1 addition & 0 deletions src-tauri/capabilities/SubWindow.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"core:window:allow-destroy",
"core:window:allow-set-size",
"core:window:allow-set-title",
"core:window:allow-set-focus",
"core:window:allow-set-fullscreen",
"core:window:allow-show",
"core:window:default",
Expand Down
22 changes: 22 additions & 0 deletions src-tauri/gen/schemas/acl-manifests.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@
"identifier": "default",
"description": "Default permissions for the plugin.",
"permissions": [
"allow-get-all-webviews",
"allow-webview-position",
"allow-webview-size",
"allow-internal-toggle-devtools"
Expand All @@ -717,6 +718,11 @@
"description": "Enables the create_webview_window command without any pre-configured scope.",
"commands": { "allow": ["create_webview_window"], "deny": [] }
},
"allow-get-all-webviews": {
"identifier": "allow-get-all-webviews",
"description": "Enables the get_all_webviews command without any pre-configured scope.",
"commands": { "allow": ["get_all_webviews"], "deny": [] }
},
"allow-internal-toggle-devtools": {
"identifier": "allow-internal-toggle-devtools",
"description": "Enables the internal_toggle_devtools command without any pre-configured scope.",
Expand Down Expand Up @@ -777,6 +783,11 @@
"description": "Denies the create_webview_window command without any pre-configured scope.",
"commands": { "allow": [], "deny": ["create_webview_window"] }
},
"deny-get-all-webviews": {
"identifier": "deny-get-all-webviews",
"description": "Denies the get_all_webviews command without any pre-configured scope.",
"commands": { "allow": [], "deny": ["get_all_webviews"] }
},
"deny-internal-toggle-devtools": {
"identifier": "deny-internal-toggle-devtools",
"description": "Denies the internal_toggle_devtools command without any pre-configured scope.",
Expand Down Expand Up @@ -836,6 +847,7 @@
"identifier": "default",
"description": "Default permissions for the plugin.",
"permissions": [
"allow-get-all-windows",
"allow-scale-factor",
"allow-inner-position",
"allow-outer-position",
Expand Down Expand Up @@ -897,6 +909,11 @@
"description": "Enables the destroy command without any pre-configured scope.",
"commands": { "allow": ["destroy"], "deny": [] }
},
"allow-get-all-windows": {
"identifier": "allow-get-all-windows",
"description": "Enables the get_all_windows command without any pre-configured scope.",
"commands": { "allow": ["get_all_windows"], "deny": [] }
},
"allow-hide": {
"identifier": "allow-hide",
"description": "Enables the hide command without any pre-configured scope.",
Expand Down Expand Up @@ -1222,6 +1239,11 @@
"description": "Denies the destroy command without any pre-configured scope.",
"commands": { "allow": [], "deny": ["destroy"] }
},
"deny-get-all-windows": {
"identifier": "deny-get-all-windows",
"description": "Denies the get_all_windows command without any pre-configured scope.",
"commands": { "allow": [], "deny": ["get_all_windows"] }
},
"deny-hide": {
"identifier": "deny-hide",
"description": "Denies the hide command without any pre-configured scope.",
Expand Down
1 change: 1 addition & 0 deletions src-tauri/gen/schemas/capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"core:window:allow-destroy",
"core:window:allow-set-size",
"core:window:allow-set-title",
"core:window:allow-set-focus",
"core:window:allow-set-fullscreen",
"core:window:allow-show",
"core:window:default",
Expand Down
20 changes: 20 additions & 0 deletions src-tauri/gen/schemas/desktop-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,11 @@
"type": "string",
"enum": ["core:webview:allow-create-webview-window"]
},
{
"description": "core:webview:allow-get-all-webviews -> Enables the get_all_webviews command without any pre-configured scope.",
"type": "string",
"enum": ["core:webview:allow-get-all-webviews"]
},
{
"description": "core:webview:allow-internal-toggle-devtools -> Enables the internal_toggle_devtools command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -2518,6 +2523,11 @@
"type": "string",
"enum": ["core:webview:deny-create-webview-window"]
},
{
"description": "core:webview:deny-get-all-webviews -> Denies the get_all_webviews command without any pre-configured scope.",
"type": "string",
"enum": ["core:webview:deny-get-all-webviews"]
},
{
"description": "core:webview:deny-internal-toggle-devtools -> Denies the internal_toggle_devtools command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -2608,6 +2618,11 @@
"type": "string",
"enum": ["core:window:allow-destroy"]
},
{
"description": "core:window:allow-get-all-windows -> Enables the get_all_windows command without any pre-configured scope.",
"type": "string",
"enum": ["core:window:allow-get-all-windows"]
},
{
"description": "core:window:allow-hide -> Enables the hide command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -2933,6 +2948,11 @@
"type": "string",
"enum": ["core:window:deny-destroy"]
},
{
"description": "core:window:deny-get-all-windows -> Denies the get_all_windows command without any pre-configured scope.",
"type": "string",
"enum": ["core:window:deny-get-all-windows"]
},
{
"description": "core:window:deny-hide -> Denies the hide command without any pre-configured scope.",
"type": "string",
Expand Down
20 changes: 20 additions & 0 deletions src-tauri/gen/schemas/windows-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,11 @@
"type": "string",
"enum": ["core:webview:allow-create-webview-window"]
},
{
"description": "core:webview:allow-get-all-webviews -> Enables the get_all_webviews command without any pre-configured scope.",
"type": "string",
"enum": ["core:webview:allow-get-all-webviews"]
},
{
"description": "core:webview:allow-internal-toggle-devtools -> Enables the internal_toggle_devtools command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -2518,6 +2523,11 @@
"type": "string",
"enum": ["core:webview:deny-create-webview-window"]
},
{
"description": "core:webview:deny-get-all-webviews -> Denies the get_all_webviews command without any pre-configured scope.",
"type": "string",
"enum": ["core:webview:deny-get-all-webviews"]
},
{
"description": "core:webview:deny-internal-toggle-devtools -> Denies the internal_toggle_devtools command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -2608,6 +2618,11 @@
"type": "string",
"enum": ["core:window:allow-destroy"]
},
{
"description": "core:window:allow-get-all-windows -> Enables the get_all_windows command without any pre-configured scope.",
"type": "string",
"enum": ["core:window:allow-get-all-windows"]
},
{
"description": "core:window:allow-hide -> Enables the hide command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -2933,6 +2948,11 @@
"type": "string",
"enum": ["core:window:deny-destroy"]
},
{
"description": "core:window:deny-get-all-windows -> Denies the get_all_windows command without any pre-configured scope.",
"type": "string",
"enum": ["core:window:deny-get-all-windows"]
},
{
"description": "core:window:deny-hide -> Denies the hide command without any pre-configured scope.",
"type": "string",
Expand Down
1 change: 0 additions & 1 deletion src/components/userAvatar/tua-detail-overlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ function onAvatarClick(avatar: TGApp.Sqlite.Character.UserRole): void {
.tdo-avatar {
cursor: pointer;
transform: translateY(-10px);
}
.tdo-card-container {
Expand Down
22 changes: 13 additions & 9 deletions src/pages/User/Characters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
Expand Down
54 changes: 33 additions & 21 deletions src/utils/TGClient.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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 });
Expand All @@ -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];
Expand Down Expand Up @@ -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} - 无返回值
Expand All @@ -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 });
Expand Down Expand Up @@ -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} - 无返回值
Expand All @@ -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)})`,
Expand All @@ -740,15 +750,15 @@ 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();
}
}

/**
* @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>} - 无返回值
Expand All @@ -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",
Expand All @@ -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();
}
Expand All @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/utils/linkParser.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 打开
Expand Down Expand Up @@ -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",
];
Expand Down
Loading

0 comments on commit 021a141

Please sign in to comment.