Browse Source

fix an issue about the tray window is closed.

oldj 4 năm trước cách đây
mục cha
commit
5d3d80ad9a
3 tập tin đã thay đổi với 15 bổ sung5 xóa
  1. 2 3
      src/main/main.ts
  2. 12 2
      src/main/tray/window.ts
  3. 1 0
      src/main/types.d.ts

+ 2 - 3
src/main/main.ts

@@ -17,7 +17,6 @@ import * as path from 'path'
 import { v4 as uuid4 } from 'uuid'
 
 let win: BrowserWindow | null
-let is_will_quit: boolean = false
 
 const createWindow = async () => {
   const configs = await configAll()
@@ -78,7 +77,7 @@ const createWindow = async () => {
   }
 
   win.on('close', (e: Electron.Event) => {
-    if (is_will_quit) {
+    if (global.is_will_quit) {
       win = null
     } else {
       e.preventDefault()
@@ -134,6 +133,6 @@ app.on('window-all-closed', () => {
   }
 })
 
-app.on('before-quit', () => is_will_quit = true)
+app.on('before-quit', () => global.is_will_quit = true)
 app.on('activate', onActive)
 message.on('active_main_window', onActive)

+ 12 - 2
src/main/tray/window.ts

@@ -10,7 +10,8 @@ import { BrowserWindow } from 'electron'
 import path from 'path'
 
 const makeWindow = () => {
-  let win = new BrowserWindow({
+  let win: BrowserWindow | null
+  win = new BrowserWindow({
     frame: false,
     // titleBarStyle: 'hidden',
     hasShadow: true,
@@ -34,7 +35,16 @@ const makeWindow = () => {
     .catch(e => console.error(e))
 
   win.hide()
-  win.on('blur', () => win.hide())
+  win.on('blur', () => win?.hide())
+
+  win.on('close', (e: Electron.Event) => {
+    if (global.is_will_quit) {
+      win = null
+    } else {
+      e.preventDefault()
+      win?.hide()
+    }
+  })
 
   if (isDev()) {
     // Open DevTools, see https://github.com/electron/electron/issues/12438 for why we wait for dom-ready

+ 1 - 0
src/main/types.d.ts

@@ -32,6 +32,7 @@ declare global {
       main_win: BrowserWindow;
       last_path?: string; // the last path opened by SwitchHosts
       tracer: Tracer;
+      is_will_quit?: boolean;
     }
   }
 }