Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
387 changes: 274 additions & 113 deletions desktopBg.cjs

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions desktopInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@

var showWin = function () {
try {
if (localStorage.getItem('onlykeySuppressShow') === '1') return;
var fs = require('fs');
var path = require('path');
if (fs.existsSync(path.join(nw.App.startPath, 'tmp', 'suppress-show.json'))) return;
if (desktop && typeof desktop.shouldKeepWindowHidden === 'function' && desktop.shouldKeepWindowHidden()) {
return;
}
} catch {
// suppress-show probe is best-effort
// show the window if the hidden-launch check itself fails
}
if (win.isMinimized && win.restore) win.restore();
if (!win.isVisible) win.show(true);
Expand Down
6 changes: 4 additions & 2 deletions docs/desktop-tray.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Do **not** pass `title: undefined` into `nw.Tray` — macOS draws that string ne
1. `package.json` → `window.inject_js_start: desktopInject.js` calls `desktopBg.cjs` → `start()`.
2. `window.show` is **false**. `desktopInject.js` shows the window at document-start, except an autostart launch (`--hidden`), which stays in the tray. Do not set `show` back to `true` — that flashes a window on login.
3. `start()` clears stale `tmp/tray-*`, binds close-to-tray, calls `initTray()` in the **main renderer**, polls `tmp/tray-command.json` (for tests / fallback). It also polls `~/.config/OnlyKey/app-tmp/tray-command.json`, which the Linux `onlykey-launch` wrapper writes.
4. Tray menu `click` handlers call `dispatchTrayCommand()` → `processTrayCommand()` in the same renderer. The autostart checkbox label is **Autostart to tray** (`isHidden: true`, macOS LaunchAgent).
4. Tray menu `click` handlers call `dispatchTrayCommand()` → `processTrayCommand()` in the same renderer. The autostart checkbox label is **Autostart to tray**. `loginAutostart.cjs` registers one login entry that passes `--hidden --onlykey-autostart`: Windows `HKCU\...\Run\OnlyKey` (and clears a disabled StartupApproved flag; the old value was named `nw` and Task Manager left it off), macOS LaunchAgent `to.crp.onlykey` via `open -gj` on the app bundle (legacy helper agents are removed so Dock icons do not accumulate; Login Items are removed later, while the window is visible), Linux `~/.config/autostart/OnlyKey.desktop` through `onlykey-launch`.

The first time a visible window is about to ask System Events to list Login Items, `LoginItemAccessHost` shows the shared confirm dialog. The desktop shell waits for Continue or Not now by calling `onlykeyAskLoginItemAccess` on the page window (`nw.Window.get().window`). The document-start inject script does not share that page's JavaScript globals, so the shell keeps checking the page window until React registers the callback. Continue, then choose Allow on the macOS prompt. Not now leaves those Login Items until the next time the window is opened. The tray is already up, so the note does not block it. A `--hidden --onlykey-autostart` launch does not show that note and does not run the AppleScript; the LaunchAgent is still registered. A stored autostart "off" is not turned back on. `NSAppleEventsUsageDescription` in `resources/osx/Info.plist` is the purpose line macOS can show on the prompt.
5. A second launch while the window is hidden (Start menu, Dock, Applications, taskbar pin, CLI — anything that hits the same executable) is Chromium single-instance. `nw.App` `open` (Windows/Linux) and `reopen` (macOS) call `executeShowMainWindow()`. A second `--hidden` autostart does not.
6. `scripts/start-desktop.mjs` clears tray tmp files before launch and `taskkill`s stale `nw.exe` on exit.

Expand All @@ -54,7 +56,7 @@ On Cinnamon/Mint/GNOME StatusNotifier, **never** mutate an already-assigned tray

Correct pattern (see `buildTrayMenu` / `assignTrayMenu` in `desktopBg.cjs`):

1. Resolve auto-launch enabled state **before** first menu paint.
1. Resolve autostart enabled state **before** first menu paint.
2. Build a full `nw.Menu` with final checkbox values.
3. Assign `tray.menu` once (re-assign on Linux after ~250ms).
4. On preference toggles, **rebuild** a new menu and reassign — do not remove/insert in place.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
}
var showWin = function () {
try {
if (localStorage.getItem('onlykeySuppressShow') === '1') return;
if (fs.existsSync(path.join(nw.App.startPath, 'tmp', 'suppress-show.json'))) return;
if (desktopApi.shouldKeepWindowHidden && desktopApi.shouldKeepWindowHidden()) return;
} catch (e) {}
if (win.isMinimized && win.restore) win.restore();
if (!win.isVisible) win.show(true);
Expand Down
Loading
Loading