mirror of
https://github.com/EasyTier/EasytierGame.git
synced 2025-05-19 10:27:56 +00:00
修复每次打开窗口信息可能会出现不同步的bug(如日志信息不更新)(子网代理按钮点不起等)
This commit is contained in:
+33
-22
@@ -5,16 +5,31 @@ import type { WebviewLabel, WebviewOptions } from "@tauri-apps/api/webview";
|
||||
import useMainStore from "@/stores/index";
|
||||
import { onBeforeUnmount } from "vue";
|
||||
|
||||
const _listenersMaps: { [key: string]: [UnlistenFn | null, UnlistenFn | null] } = {};
|
||||
const _listenersMaps: { [key: string]: [UnlistenFn | null] } = {};
|
||||
|
||||
const dealCloseListener = async (
|
||||
dialog: WebviewWindow,
|
||||
label: string,
|
||||
beforeCloseFunc?: () => void | null
|
||||
) => {
|
||||
const unlistenFnList: [UnlistenFn | null] = _listenersMaps[label] || [null];
|
||||
let [unListenlogClose] = unlistenFnList;
|
||||
|
||||
unListenlogClose && (await unListenlogClose());
|
||||
|
||||
unListenlogClose = await dialog.onCloseRequested(async () => {
|
||||
beforeCloseFunc && (await beforeCloseFunc());
|
||||
unListenlogClose && (await unListenlogClose());
|
||||
console.log("close")
|
||||
});
|
||||
};
|
||||
export default async (
|
||||
label: WebviewLabel,
|
||||
options?: Omit<WebviewOptions, "x" | "y" | "width" | "height"> & WindowOptions,
|
||||
afterCreatedFunc?: (webviewWindow: WebviewWindow, appWindow: Window) => void | null,
|
||||
beforeCloseFunc?: () => void | null
|
||||
) => {
|
||||
const unlistenFnList: [UnlistenFn | null, UnlistenFn | null] = _listenersMaps[label] || [null, null];
|
||||
let [unlistenLogCreated, unListenlogClose] = unlistenFnList;
|
||||
const unlistenFnList: [UnlistenFn | null] = _listenersMaps[label] || [null];
|
||||
let dialog = await WebviewWindow.getByLabel(label);
|
||||
if (!dialog) {
|
||||
let defaultOpts: { [key: string]: any; parent: Window | undefined } = {
|
||||
@@ -38,28 +53,20 @@ export default async (
|
||||
defaultOpts.x = logicalPosition.x;
|
||||
defaultOpts.y = logicalPosition.y;
|
||||
}
|
||||
unlistenLogCreated && (await (unlistenLogCreated as Function)());
|
||||
unListenlogClose && (await unListenlogClose());
|
||||
dialog = new WebviewWindow(label, { ...defaultOpts, ...options });
|
||||
unlistenLogCreated = await dialog.listen("tauri://webview-created", async () => {
|
||||
if (dialog) {
|
||||
await dealCloseListener(dialog, label, beforeCloseFunc);
|
||||
afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow));
|
||||
await dialog.show();
|
||||
}
|
||||
});
|
||||
unlistenFnList[0] = unlistenLogCreated;
|
||||
unListenlogClose = await dialog.onCloseRequested(async () => {
|
||||
beforeCloseFunc && (await beforeCloseFunc());
|
||||
unListenlogClose && (await unListenlogClose());
|
||||
unlistenLogCreated && (await (unlistenLogCreated as Function)());
|
||||
});
|
||||
unlistenFnList[1] = unlistenLogCreated;
|
||||
_listenersMaps[label] = unlistenFnList;
|
||||
|
||||
} else {
|
||||
const visible = await dialog.isVisible();
|
||||
if (visible) {
|
||||
await dialog.close();
|
||||
unlistenLogCreated && (await (unlistenLogCreated as Function)());
|
||||
} else {
|
||||
const appWindow = getCurrentWindow();
|
||||
await dealCloseListener(dialog, label, beforeCloseFunc);
|
||||
afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow));
|
||||
await dialog.show();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -68,15 +75,19 @@ export const dataSubscribe = async (cb?: (...args: any) => any) => {
|
||||
if (!cb) return;
|
||||
const mainStore = useMainStore();
|
||||
const abort = new AbortController();
|
||||
window.addEventListener("storage", async () => {
|
||||
window.addEventListener(
|
||||
"storage",
|
||||
async () => {
|
||||
mainStore.$hydrate();
|
||||
if (cb && cb instanceof Function) {
|
||||
await cb();
|
||||
}
|
||||
}, {
|
||||
},
|
||||
{
|
||||
signal: abort.signal
|
||||
})
|
||||
}
|
||||
);
|
||||
onBeforeUnmount(() => {
|
||||
abort?.abort();
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
+1
-1
@@ -1827,7 +1827,7 @@
|
||||
cidrTimer && clearInterval(cidrTimer);
|
||||
cidrTimer = setInterval(() => {
|
||||
appWindow.emitTo({ kind: "WebviewWindow", label: "cidr" }, "route", data.isStart);
|
||||
}, 1000);
|
||||
}, 650);
|
||||
},
|
||||
() => {
|
||||
cidrTimer && clearInterval(cidrTimer);
|
||||
|
||||
Reference in New Issue
Block a user