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 useMainStore from "@/stores/index";
|
||||||
import { onBeforeUnmount } from "vue";
|
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 (
|
export default async (
|
||||||
label: WebviewLabel,
|
label: WebviewLabel,
|
||||||
options?: Omit<WebviewOptions, "x" | "y" | "width" | "height"> & WindowOptions,
|
options?: Omit<WebviewOptions, "x" | "y" | "width" | "height"> & WindowOptions,
|
||||||
afterCreatedFunc?: (webviewWindow: WebviewWindow, appWindow: Window) => void | null,
|
afterCreatedFunc?: (webviewWindow: WebviewWindow, appWindow: Window) => void | null,
|
||||||
beforeCloseFunc?: () => void | null
|
beforeCloseFunc?: () => void | null
|
||||||
) => {
|
) => {
|
||||||
const unlistenFnList: [UnlistenFn | null, UnlistenFn | null] = _listenersMaps[label] || [null, null];
|
const unlistenFnList: [UnlistenFn | null] = _listenersMaps[label] || [null];
|
||||||
let [unlistenLogCreated, unListenlogClose] = unlistenFnList;
|
|
||||||
let dialog = await WebviewWindow.getByLabel(label);
|
let dialog = await WebviewWindow.getByLabel(label);
|
||||||
if (!dialog) {
|
if (!dialog) {
|
||||||
let defaultOpts: { [key: string]: any; parent: Window | undefined } = {
|
let defaultOpts: { [key: string]: any; parent: Window | undefined } = {
|
||||||
@@ -38,28 +53,20 @@ export default async (
|
|||||||
defaultOpts.x = logicalPosition.x;
|
defaultOpts.x = logicalPosition.x;
|
||||||
defaultOpts.y = logicalPosition.y;
|
defaultOpts.y = logicalPosition.y;
|
||||||
}
|
}
|
||||||
unlistenLogCreated && (await (unlistenLogCreated as Function)());
|
|
||||||
unListenlogClose && (await unListenlogClose());
|
|
||||||
dialog = new WebviewWindow(label, { ...defaultOpts, ...options });
|
dialog = new WebviewWindow(label, { ...defaultOpts, ...options });
|
||||||
unlistenLogCreated = await dialog.listen("tauri://webview-created", async () => {
|
await dealCloseListener(dialog, label, beforeCloseFunc);
|
||||||
if (dialog) {
|
|
||||||
afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow));
|
afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow));
|
||||||
await dialog.show();
|
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 {
|
} else {
|
||||||
const visible = await dialog.isVisible();
|
const visible = await dialog.isVisible();
|
||||||
if (visible) {
|
if (visible) {
|
||||||
await dialog.close();
|
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;
|
if (!cb) return;
|
||||||
const mainStore = useMainStore();
|
const mainStore = useMainStore();
|
||||||
const abort = new AbortController();
|
const abort = new AbortController();
|
||||||
window.addEventListener("storage", async () => {
|
window.addEventListener(
|
||||||
|
"storage",
|
||||||
|
async () => {
|
||||||
mainStore.$hydrate();
|
mainStore.$hydrate();
|
||||||
if (cb && cb instanceof Function) {
|
if (cb && cb instanceof Function) {
|
||||||
await cb();
|
await cb();
|
||||||
}
|
}
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
signal: abort.signal
|
signal: abort.signal
|
||||||
})
|
}
|
||||||
|
);
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
abort?.abort();
|
abort?.abort();
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1827,7 +1827,7 @@
|
|||||||
cidrTimer && clearInterval(cidrTimer);
|
cidrTimer && clearInterval(cidrTimer);
|
||||||
cidrTimer = setInterval(() => {
|
cidrTimer = setInterval(() => {
|
||||||
appWindow.emitTo({ kind: "WebviewWindow", label: "cidr" }, "route", data.isStart);
|
appWindow.emitTo({ kind: "WebviewWindow", label: "cidr" }, "route", data.isStart);
|
||||||
}, 1000);
|
}, 650);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
cidrTimer && clearInterval(cidrTimer);
|
cidrTimer && clearInterval(cidrTimer);
|
||||||
|
|||||||
Reference in New Issue
Block a user