Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

desktop: fix start as minimized on windows

Abdullah Attac2ab5ded4750
diff --git a/apps/web/desktop/autolaunch.ts b/apps/web/desktop/autolaunch.ts
index de858fb13..e68ab5d22 100644
--- a/apps/web/desktop/autolaunch.ts
+++ b/apps/web/desktop/autolaunch.ts
@@ -47,7 +47,11 @@ export class AutoLaunch {
LINUX_DESKTOP_ENTRY(hidden)
);
} else {
- app.setLoginItemSettings({ openAtLogin: true, openAsHidden: hidden });
+ app.setLoginItemSettings({
+ openAtLogin: true,
+ openAsHidden: hidden,
+ args: ["--hidden"]
+ });
}
}
diff --git a/apps/web/desktop/cli.ts b/apps/web/desktop/cli.ts
index 1498feb3f..9848d0d16 100644
--- a/apps/web/desktop/cli.ts
+++ b/apps/web/desktop/cli.ts
@@ -24,15 +24,18 @@ export type CLIOptions = {
note?: boolean | string;
notebook?: boolean | string;
reminder?: boolean | string;
+ hidden?: boolean;
};
export async function parseArguments(): Promise<CLIOptions> {
const result: CLIOptions = {
note: false,
notebook: false,
- reminder: false
+ reminder: false,
+ hidden: false
};
- await yargs(hideBin(process.argv))
+ const { hidden } = await yargs(hideBin(process.argv))
+ .boolean("hidden")
.command("new", "Create a new item", (yargs) => {
return yargs
.command("note", "Create a new note", {}, () => {
@@ -76,5 +79,6 @@ export async function parseArguments(): Promise<CLIOptions> {
);
})
.parse();
+ result.hidden = hidden;
return result;
}
diff --git a/apps/web/desktop/electron.js b/apps/web/desktop/electron.js
index 8cc221b2e..7ec22070f 100644
--- a/apps/web/desktop/electron.js
+++ b/apps/web/desktop/electron.js
@@ -64,6 +64,7 @@ async function createWindow() {
setTheme(getTheme());
const mainWindow = new BrowserWindow({
+ show: false,
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
@@ -87,11 +88,17 @@ async function createWindow() {
}
});
+ mainWindow.on("show", () => {
+ if (getPrivacyMode()) {
+ setPrivacyMode({ privacyMode: getPrivacyMode() });
+ }
+ });
+
mainWindowState.manage(mainWindow);
globalThis.window = mainWindow;
setupMenu();
setupJumplist();
- setupDesktopIntegration();
+ setupDesktopIntegration(cliOptions.hidden);
mainWindow.webContents.session.setSpellCheckerDictionaryDownloadURL(
"http://dictionaries.notesnook.com/"
@@ -100,10 +107,6 @@ async function createWindow() {
if (isDevelopment())
mainWindow.webContents.openDevTools({ mode: "right", activate: true });
- if (getPrivacyMode()) {
- setPrivacyMode({ privacyMode: getPrivacyMode() });
- }
-
try {
await mainWindow.loadURL(`${createURL(cliOptions)}`);
} catch (e) {
@@ -169,7 +172,7 @@ function createURL(options) {
return url;
}
-function setupDesktopIntegration() {
+function setupDesktopIntegration(hidden) {
const desktopIntegration = getDesktopIntegration();
if (
@@ -179,6 +182,17 @@ function setupDesktopIntegration() {
setupTray();
}
+ globalThis.window.on("ready-to-show", () => {
+ if (!hidden) {
+ globalThis.window.show();
+ }
+
+ if (hidden && !desktopIntegration.minimizeToSystemTray) {
+ globalThis.window.show();
+ globalThis.window.minimize();
+ }
+ });
+
// when close to system tray is enabled, it becomes nigh impossible
// to "quit" the app. This is necessary in order to fix that.
if (desktopIntegration.closeToSystemTray) {
@@ -212,9 +226,5 @@ function setupDesktopIntegration() {
if (desktopIntegration.autoStart) {
AutoLaunch.enable(desktopIntegration.startMinimized);
-
- if (process.platform === "win32" && desktopIntegration.startMinimized) {
- globalThis.window.minimize();
- }
}
}
diff --git a/apps/web/desktop/ipc/actions/setDesktopIntegration.js b/apps/web/desktop/ipc/actions/setDesktopIntegration.js
index e38162921..7d7a7343a 100644
--- a/apps/web/desktop/ipc/actions/setDesktopIntegration.js
+++ b/apps/web/desktop/ipc/actions/setDesktopIntegration.js
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { AutoLaunch } from "../../autolaunch";
import { setDesktopIntegration } from "../../config/desktopIntegration";
+import { destroyTray, setupTray } from "../../tray";
export default (args) => {
if (!globalThis.window) return;
@@ -29,5 +30,11 @@ export default (args) => {
AutoLaunch.disable();
}
+ if (args.closeToSystemTray || args.minimizeToSystemTray) {
+ setupTray();
+ } else {
+ destroyTray();
+ }
+
setDesktopIntegration(args);
};
diff --git a/apps/web/desktop/tray.ts b/apps/web/desktop/tray.ts
index ea5f7b228..257c98f58 100644
--- a/apps/web/desktop/tray.ts
+++ b/apps/web/desktop/tray.ts
@@ -25,6 +25,10 @@ import { sendMessageToRenderer } from "./ipc/utils";
import { isFlatpak } from "./utils";
let tray: Tray | undefined = undefined;
+export function destroyTray() {
+ if (tray) tray.destroy();
+}
+
export function setupTray() {
if (tray) tray.destroy();