diff --git a/repo/core/mac+linux.png b/repo/core/mac+linux.png new file mode 100644 index 0000000..83412d4 Binary files /dev/null and b/repo/core/mac+linux.png differ diff --git a/repo/core/mod.js b/repo/core/mod.js index 1b3d9cc..05a8f88 100644 --- a/repo/core/mod.js +++ b/repo/core/mod.js @@ -4,6 +4,13 @@ * (https://dragonwocky.me/) under the MIT license */ +const defaults = { + openhidden: false, + maximized: false, + tray: false, + hotkey: 'CmdOrCtrl+Shift+A', +}; + module.exports = { id: '0f0bf8b6-eae6-4273-b307-8fc43f2ee082', type: 'core', @@ -16,6 +23,7 @@ module.exports = { 'https://camo.githubusercontent.com/5c5bca9e987d986b8cc7e51066f90c6f8a84af08/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3733313634373938343332333931393933332f3733313732373235393239353032333132342f494d475f323137302e6a7067', options: [], hacks: { + // 'main/main.js': require('./tray.js')(defaults), 'renderer/preload.js': function (store) { const data = store({ name: 'dragonwocky' }); console.log(data.name); diff --git a/repo/core/tray.js b/repo/core/tray.js new file mode 100644 index 0000000..729680c --- /dev/null +++ b/repo/core/tray.js @@ -0,0 +1,81 @@ +/* + * notion-enhancer + * (c) 2020 dragonwocky <thedragonring.bod@gmail.com> + * (c) 2020 TarasokUA + * (https://dragonwocky.me/) under the MIT license + */ + +let tray; +const electron = require('electron'), + path = require('path'), + is_mac = process.platform === 'darwin', + is_win = process.platform === 'win32', + settings = {}; + +electron.app.on('ready', () => { + tray = new electron.Tray( + is_win + ? path.resolve(__dirname, 'windows.ico') + : new electron.nativeImage.createFromPath( + path.resolve(__dirname, 'mac+linux.png') + ).resize({ + width: 16, + height: 16, + }) + ); + + const contextMenu = electron.Menu.buildFromTemplate([ + { + type: 'normal', + label: 'Bug Report', + }, + { + type: 'normal', + label: 'Feature Request', + }, + { + type: 'separator', + }, + { + type: 'normal', + label: 'Docs', + }, + { + type: 'normal', + label: 'Enhancements', + }, + { + type: 'separator', + }, + { + label: 'Quit', + role: 'quit', + }, + ]); + tray.setContextMenu(contextMenu); + tray.setToolTip('Notion'); + + function showWindows() { + const windows = electron.BrowserWindow.getAllWindows(); + if (is_mac) electron.app.show(); + if (settings.maximized) windows.forEach((win) => [win.maximize()]); + else windows.forEach((win) => win.show()); + electron.app.focus({ steal: true }); + } + function hideWindows() { + const windows = electron.BrowserWindow.getAllWindows(); + windows.forEach((win) => [win.isFocused() && win.blur(), win.hide()]); + if (is_mac) electron.app.hide(); + } + tray.on('click', () => { + const windows = electron.BrowserWindow.getAllWindows(); + if (windows.some((win) => win.isVisible())) hideWindows(); + else showWindows(); + }); + electron.globalShortcut.register(settings.hotkey, () => { + const windows = electron.BrowserWindow.getAllWindows(); + if (windows.some((win) => win.isFocused() && win.isVisible())) + hideWindows(); + else showWindows(); + }); +}); diff --git a/repo/core/windows.ico b/repo/core/windows.ico new file mode 100644 index 0000000..b46f68c Binary files /dev/null and b/repo/core/windows.ico differ