diff --git a/composables/windows.ts b/composables/windows.ts new file mode 100644 index 0000000..507be60 --- /dev/null +++ b/composables/windows.ts @@ -0,0 +1,53 @@ +import { type UnlistenFn } from "@tauri-apps/api/event"; +import { getCurrentWindow, PhysicalPosition, type WindowOptions, Window } from "@tauri-apps/api/window"; +import { WebviewWindow } from "@tauri-apps/api/webviewWindow"; +import type { WebviewLabel, WebviewOptions, } from "@tauri-apps/api/webview"; +export default async ( + label: WebviewLabel, + options?: Omit & WindowOptions, + afterCreatedFunc?: (webviewWindow: WebviewWindow, appWindow: Window) => void | null, + beforeCloseFunc?: () => void | null +) => { + let defaultOpts = { + parent: undefined, + closable: true, + resizable: true, + decorations: true, + maximizable: false, + minimizable: false, + x: 0, + y: 0 + }; + const appWindow = getCurrentWindow(); + if (appWindow) { + const appSize = await appWindow.outerSize(); + const factor = await appWindow.scaleFactor(); + const appPosition = await appWindow.outerPosition(); + const logicalPosition = new PhysicalPosition(appPosition.x + appSize.width, appPosition.y).toLogical(factor); + defaultOpts.parent = appWindow as any; + defaultOpts.x = logicalPosition.x; + defaultOpts.y = logicalPosition.y; + } + let unListenlogClose: UnlistenFn | null = null; + let unlistenLogCreated: UnlistenFn | null = null; + let dialog = await WebviewWindow.getByLabel(label); + if (!dialog) { + dialog = new WebviewWindow(label, {...defaultOpts, ...options}); + unlistenLogCreated = await dialog.once("tauri://webview-created", async () => { + if (dialog) { + afterCreatedFunc && (await afterCreatedFunc(dialog, appWindow)); + await dialog.show(); + } + }); + unListenlogClose = await dialog.onCloseRequested(async () => { + beforeCloseFunc && (await beforeCloseFunc()); + unListenlogClose && (await unListenlogClose()); + }); + } else { + const visible = await dialog.isVisible(); + if (visible) { + await dialog.close(); + unlistenLogCreated && (await (unlistenLogCreated as Function)()); + } + } +}; diff --git a/pages/cidr.vue b/pages/cidr.vue new file mode 100644 index 0000000..14a60e8 --- /dev/null +++ b/pages/cidr.vue @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/pages/index.vue b/pages/index.vue index 808c413..9b5329a 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -16,7 +16,7 @@ effect="dark" :type="data.isSuccessGetIp ? 'success' : 'info'" > - {{ data.isSuccessGetIp ? "联机成功" : "联机中" }} + {{ data.isSuccessGetIp ? "联机成功" : data.isStart && !data.isSuccessGetIp ? "联机中" : "未联机" }} -
+
+ +
@@ -211,14 +213,14 @@ v-model="config.disbleP2p" size="small" > - 禁用p2p + 强制中转 - 禁用ipv6 - + --> 开机自启 - 禁用端口监听 - + --> +
+ 子网代理 + 高级配置 +
diff --git a/pages/log.vue b/pages/log.vue index 02b482d..cd39490 100644 --- a/pages/log.vue +++ b/pages/log.vue @@ -1,7 +1,7 @@