Skip to content

Commit

Permalink
feat(Windows): Add option to quit Franz from Taskbar icon
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Feb 12, 2019
1 parent 91a510a commit 8808601
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ protocols:
name: Franz
schemes: [franz]

asarUnpack: "./dictionaries"
asarUnpack:
- ./dictionaries
- ./assets/images/taskbar
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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'));
3 changes: 3 additions & 0 deletions src/helpers/asar-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function asarPath(dir = '') {
return dir.replace('app.asar', 'app.asar.unpacked');
}
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
});
}
Expand Down Expand Up @@ -265,10 +272,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',
}]);
}

Expand Down

0 comments on commit 8808601

Please sign in to comment.