bubblepipe42 5 月之前
父節點
當前提交
a57a36a739
共有 3 個文件被更改,包括 37 次插入37 次删除
  1. 37 37
      electron/main.js
  2. 二進制
      electron/tray-iconTemplate.png
  3. 二進制
      electron/tray-iconTemplate@2x.png

+ 37 - 37
electron/main.js

@@ -110,8 +110,43 @@ function waitForServer(resolve, reject, retries = 30) {
   req.end();
   req.end();
 }
 }
 
 
+function createWindow() {
+  mainWindow = new BrowserWindow({
+    width: 1400,
+    height: 900,
+    webPreferences: {
+      preload: path.join(__dirname, 'preload.js'),
+      nodeIntegration: false,
+      contextIsolation: true
+    },
+    title: 'New API',
+    icon: path.join(__dirname, 'icon.png')
+  });
+
+  mainWindow.loadURL(`http://localhost:${PORT}`);
+
+  if (process.env.NODE_ENV === 'development') {
+    mainWindow.webContents.openDevTools();
+  }
+
+  // Close to tray instead of quitting
+  mainWindow.on('close', (event) => {
+    if (!app.isQuitting) {
+      event.preventDefault();
+      mainWindow.hide();
+      if (process.platform === 'darwin') {
+        app.dock.hide();
+      }
+    }
+  });
+
+  mainWindow.on('closed', () => {
+    mainWindow = null;
+  });
+}
+
 function createTray() {
 function createTray() {
-  tray = new Tray(path.join(__dirname, 'tray-icon.png'));
+  tray = new Tray(path.join(__dirname, 'tray-iconTemplate.png'));
 
 
   const contextMenu = Menu.buildFromTemplate([
   const contextMenu = Menu.buildFromTemplate([
     {
     {
@@ -140,7 +175,7 @@ function createTray() {
   tray.setToolTip('New API');
   tray.setToolTip('New API');
   tray.setContextMenu(contextMenu);
   tray.setContextMenu(contextMenu);
 
 
-  // On macOS, clicking the tray icon shows the menu
+  // On macOS, clicking the tray icon shows the window
   tray.on('click', () => {
   tray.on('click', () => {
     if (mainWindow === null) {
     if (mainWindow === null) {
       createWindow();
       createWindow();
@@ -153,41 +188,6 @@ function createTray() {
   });
   });
 }
 }
 
 
-function createWindow() {
-  mainWindow = new BrowserWindow({
-    width: 1400,
-    height: 900,
-    webPreferences: {
-      preload: path.join(__dirname, 'preload.js'),
-      nodeIntegration: false,
-      contextIsolation: true
-    },
-    title: 'New API',
-    icon: path.join(__dirname, 'icon.png')
-  });
-
-  mainWindow.loadURL(`http://localhost:${PORT}`);
-
-  if (process.env.NODE_ENV === 'development') {
-    mainWindow.webContents.openDevTools();
-  }
-
-  // Close to tray instead of quitting
-  mainWindow.on('close', (event) => {
-    if (!app.isQuitting) {
-      event.preventDefault();
-      mainWindow.hide();
-      if (process.platform === 'darwin') {
-        app.dock.hide();
-      }
-    }
-  });
-
-  mainWindow.on('closed', () => {
-    mainWindow = null;
-  });
-}
-
 app.whenReady().then(async () => {
 app.whenReady().then(async () => {
   try {
   try {
     await startServer();
     await startServer();

二進制
electron/tray-iconTemplate.png


二進制
electron/tray-iconTemplate@2x.png