From 2c3a15b5301d80e70bd94e6fcd63bfb88038097d Mon Sep 17 00:00:00 2001 From: ahkohd Date: Sun, 27 Oct 2019 23:40:04 +0100 Subject: [PATCH] =?UTF-8?q?->=20Clean=20up=20.gitignore=20=F0=9F=94=A7=20-?= =?UTF-8?q?>=20Properly=20implement=20close=20switch=20mac=20=E2=9C=A8=20-?= =?UTF-8?q?>=20Clean=20up=20tray=20meu=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +--- main.js | 9 +++++++-- preload.js | 24 ++++++++++++++++-------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 40b9e8b..205f6e4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,6 @@ node_modules dist/* app/* !app/.gitkeep -service-binaries/*.dll -service-binaries/*.node -service-binaries/**/*.exe +service-binaries diff --git a/main.js b/main.js index 6d7928f..d7bbaac 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,5 @@ // Modules to control application life and create native browser window -const { app, BrowserWindow } = require("electron"); +const { app, BrowserWindow, ipcMain } = require("electron"); const path = require("path"); const Positioner = require("electron-positioner"); const { execFile } = require("child_process"); @@ -104,7 +104,8 @@ if (!gotTheLock) { placement == "right" ? mainWindow.setPosition(pos[0] - 10, pos[1]) : mainWindow.setPosition(pos[0] + 10, pos[1]); - mainWindow.show(); + // delay a bit + setTimeout(() => mainWindow.show(), 1000); }); // spawn the executable approraite for the windows os. @@ -139,4 +140,8 @@ if (!gotTheLock) { // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. + + ipcMain.on("quit-switch", function(event, arg) { + app.exit(0); + }); } diff --git a/preload.js b/preload.js index 3dc8afd..58429bd 100644 --- a/preload.js +++ b/preload.js @@ -1,4 +1,4 @@ -const { remote, app } = require("electron"); +const { remote, app, ipcRenderer } = require("electron"); const find = require("find-process"); const ps = require("ps-node"); @@ -113,7 +113,7 @@ createSettingsWindow = () => { const trayMenuTemplate = [ { - label: "Show dock", + label: "Show dock...", click: () => { try { window.SWITCH_SERVICE_CHANNEL.emit( @@ -127,14 +127,19 @@ const trayMenuTemplate = [ }, { - label: "Settings", + label: "Preferences...", click: () => createSettingsWindow(), enabled: !settingsWindowOpened }, + { + type: "separator" + }, { label: "Quit", - click: function() { - app.quit(); + click: () => { + // stop swicth service... + if (process.platform == "darwin") StartOrStopSwitchMacService(false); + ipcRenderer.send("quit-switch"); } } ]; @@ -143,7 +148,10 @@ if (process.platform == "darwin") { // If platform is mac add extra menu item to cater for starting // and stoping services ... trayMenuTemplate.unshift({ - label: "Off 🧯", + type: "separator" + }); + trayMenuTemplate.unshift({ + label: "Turn Off", click: () => { StartOrStopSwitchMacService(false); } @@ -193,12 +201,12 @@ function StartOrStopSwitchMacService(start = true) { child = SPWAN_SWITCH_SERVICE_MAC(); }); - trayMenuTemplate[0].label = "Off 🧯"; + trayMenuTemplate[0].label = "Turn Off"; trayMenuTemplate[0].click = () => { StartOrStopSwitchMacService(false); }; } else { - trayMenuTemplate[0].label = "On 🔥"; + trayMenuTemplate[0].label = "Turn On"; trayMenuTemplate[0].click = () => { StartOrStopSwitchMacService(true); };