tray: open on startup, handle notion:// protocol

This commit is contained in:
dragonwocky 2021-12-03 00:55:49 +11:00
parent e761b309bf
commit 97ef140789
4 changed files with 26 additions and 1 deletions

View File

@ -44,6 +44,7 @@ export default async function (api, db) {
await web.whenReady([topbarSelector, topbarActionsSelector]);
const $topbar = document.querySelector(topbarSelector),
$dragarea = web.html`<div class="integrated_titlebar--dragarea" style="height:${dragareaHeight}px"></div>`;
$topbar.style.height = `${45 + dragareaHeight}px`;
$topbar.prepend($dragarea);
const $topbarActions = document.querySelector(topbarActionsSelector),

View File

@ -6,9 +6,10 @@
'use strict';
module.exports = async function (api, db, __exports, __eval) {
module.exports = async function ({ env }, db, __exports, __eval) {
const electron = require('electron'),
{ isMenuOpen } = require('notion-enhancer/worker.cjs'),
urlHelpers = env.notionRequire('helpers/urlHelpers'),
runInBackground = await db.get(['run_in_background']);
if (!runInBackground) return;
@ -34,10 +35,23 @@ module.exports = async function (api, db, __exports, __eval) {
throw new Error('<fake error>: prevent window close');
}
});
// no other windows yet + opened at startup = hide
const wasOpenedAtStartup =
process.argv.includes('--startup') ||
app.getLoginItemSettings({ args: ['--startup'] }).wasOpenedAtLogin;
if (!windows.length && wasOpenedAtStartup) {
window.once('ready-to-show', () => window.hide());
}
return window;
} else {
// prevents duplicate windows on dock/taskbar click
windows[0].focus();
if (relativeUrl) {
// handle requests passed via the notion:// protocol
windows[0].loadURL(urlHelpers.getIndexUrl(relativeUrl));
}
return windows[0];
}
};

View File

@ -13,6 +13,7 @@ module.exports = async function ({ env, registry }, db, __exports, __eval) {
path = require('path'),
enhancerIcon = path.resolve(`${__dirname}/../../media/colour-x16.png`),
hotkey = await db.get(['hotkey']),
openAtStartup = await db.get(['startup']),
runInBackground = await db.get(['run_in_background']),
menuHotkey = await (
await registry.db('a6621988-551d-495a-97d8-3c568bca2e9e')
@ -34,6 +35,8 @@ module.exports = async function ({ env, registry }, db, __exports, __eval) {
};
await electron.app.whenReady();
electron.app.setLoginItemSettings({ openAtLogin: openAtStartup, args: ['--startup'] });
tray = new electron.Tray(enhancerIcon);
tray.setToolTip('notion-enhancer');
tray.on('click', () => toggleWindows(false));

View File

@ -22,6 +22,13 @@
]
},
"options": [
{
"type": "toggle",
"key": "startup",
"label": "open notion on startup",
"tooltip": "**if the 'run notion in the background' option is also enabled, the app will open in background on startup** (this option may require relaunching the app BEFORE restarting your system to properly take effect)",
"value": false
},
{
"type": "toggle",
"key": "run_in_background",