diff --git a/composables/tray.ts b/composables/tray.ts index 5e2ab16..95b5f82 100644 --- a/composables/tray.ts +++ b/composables/tray.ts @@ -22,7 +22,7 @@ async function toggleVisibility() { } } -export async function useTray(init: boolean = false, beforExit: Function, handleConnection: Function) { +export async function useTray(init: boolean = false, beforExit: Function, handleConnection: Function, handleReconnect: Function) { let tray; try { tray = await TrayIcon.getById(DEFAULT_TRAY_NAME); @@ -31,7 +31,7 @@ export async function useTray(init: boolean = false, beforExit: Function, handle tooltip: `EasyTierGame\n${pkg.version}`, title: `EasyTierGame\n${pkg.version}`, id: DEFAULT_TRAY_NAME, - menu: await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection) }), + menu: await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection, handleReconnect) }), action: async e => { toggleVisibility(); } @@ -45,16 +45,17 @@ export async function useTray(init: boolean = false, beforExit: Function, handle if (init) { tray.setTooltip(`EasyTierGame\n${pkg.version}`); tray.setShowMenuOnLeftClick(false); - tray.setMenu(await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection) })); + tray.setMenu(await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection, handleReconnect) })); } return tray; } -export async function generateMenuItem(beforExit: Function, handleConnection: Function) { +export async function generateMenuItem(beforExit: Function, handleConnection: Function, handleReconnect: Function) { return [ await MenuItemShow("显示 / 隐藏"), await MenuItemExchangeConnection("联机 / 断开", handleConnection), + await MenuItemReconnect("重新联机", handleReconnect), await MenuItemTheme(), await PredefinedMenuItem.new({ item: "Separator" }), await MenuItemPublicPeers(), @@ -63,6 +64,16 @@ export async function generateMenuItem(beforExit: Function, handleConnection: Fu ]; } +export async function MenuItemReconnect(text: string, handleReconnect: Function) { + return await MenuItem.new({ + id: "reconnect", + text, + action: async () => { + await handleReconnect(); + } + }); +} + export async function MenuItemExit(text: string, beforExit: Function) { return await MenuItem.new({ id: "quit", diff --git a/pages/index.vue b/pages/index.vue index a432925..1909777 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -752,6 +752,9 @@ async () => { await handleConnection(); return data.isStart; + }, + async () => { + await handleReconnect(); } ); @@ -1696,7 +1699,12 @@ } if (command === "reconnect") { - if (data.isStart) { + handleReconnect(); + } + }; + + const handleReconnect = async () => { + if (data.isStart) { ElMessage.info({ message: "正在重新联机...", duration: 2200 @@ -1708,8 +1716,7 @@ }else { handleConnection(); } - } - }; + } const handleDeleteAdminConfig = async () => { const path = configAdminData.fileName;