From 952fc8b9b48de1c825c98b996afda5621db5fefe Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 12 Feb 2019 15:40:50 +0100 Subject: [PATCH] feat(Windows): Add option to quit Franz from Taskbar icon --- electron-builder.yml | 4 +++- src/config.js | 3 ++- src/helpers/asar-helpers.js | 3 +++ src/index.js | 14 +++++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/helpers/asar-helpers.js diff --git a/electron-builder.yml b/electron-builder.yml index 1d62669bf..97aafa207 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -43,4 +43,6 @@ protocols: name: Franz schemes: [franz] -asarUnpack: "./dictionaries" +asarUnpack: + - ./dictionaries + - ./assets/images/taskbar diff --git a/src/config.js b/src/config.js index 789ddd1a0..101a4379a 100644 --- a/src/config.js +++ b/src/config.js @@ -1,5 +1,6 @@ import electron from 'electron'; import path from 'path'; +import { asarPath } from './helpers/asar-helpers'; const app = process.type === 'renderer' ? electron.remote.app : electron.app; const systemPreferences = process.type === 'renderer' ? electron.remote.systemPreferences : electron.systemPreferences; @@ -57,4 +58,4 @@ export const FILE_SYSTEM_SETTINGS_TYPES = [ export const SETTINGS_PATH = path.join(app.getPath('userData'), 'config'); // Replacing app.asar is not beautiful but unforunately necessary -export const DICTIONARY_PATH = path.join(__dirname, 'dictionaries').replace('app.asar', 'app.asar.unpacked'); +export const DICTIONARY_PATH = asarPath(path.join(__dirname, 'dictionaries').replace('app.asar', 'app.asar.unpacked')); diff --git a/src/helpers/asar-helpers.js b/src/helpers/asar-helpers.js new file mode 100644 index 000000000..9e4380c06 --- /dev/null +++ b/src/helpers/asar-helpers.js @@ -0,0 +1,3 @@ +export function asarPath(dir = '') { + return dir.replace('app.asar', 'app.asar.unpacked'); +} diff --git a/src/index.js b/src/index.js index a3c770797..69cfa77e7 100644 --- a/src/index.js +++ b/src/index.js @@ -33,6 +33,7 @@ import { DEFAULT_APP_SETTINGS, DEFAULT_WINDOW_OPTIONS, } from './config'; +import { asarPath } from './helpers/asar-helpers'; /* eslint-enable import/first */ const debug = require('debug')('Franz:App'); @@ -88,6 +89,12 @@ if (!gotTheLock) { window.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100); window.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height); }, 1); + } else if (argv.includes('--quit')) { + // Needs to be delayed to not interfere with mainWindow.restore(); + setTimeout(() => { + debug('Quitting Franz via Task'); + app.quit(); + }, 1); } }); } @@ -294,10 +301,15 @@ app.on('ready', () => { app.setUserTasks([{ program: process.execPath, arguments: `${isDevMode ? `${__dirname} ` : ''}--reset-window`, - iconPath: path.join(`${__dirname}`, '../src/assets/images/taskbar/win32/display.ico'), + iconPath: asarPath(path.join(isDevMode ? `${__dirname}../src/` : __dirname, 'assets/images/taskbar/win32/display.ico')), iconIndex: 0, title: 'Move Franz to Current Display', description: 'Restore the position and size of Franz', + }, { + program: process.execPath, + arguments: `${isDevMode ? `${__dirname} ` : ''}--quit`, + iconIndex: 0, + title: 'Quit Franz', }]); }