diff --git a/apps/web/desktop/cli.ts b/apps/web/desktop/cli.ts
new file mode 100644
index 000000000..1498feb3f
--- /dev/null
+++ b/apps/web/desktop/cli.ts
@@ -0,0 +1,80 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+import yargs from "yargs";
+import { hideBin } from "yargs/helpers";
+
+export type CLIOptions = {
+ note?: boolean | string;
+ notebook?: boolean | string;
+ reminder?: boolean | string;
+};
+
+export async function parseArguments(): Promise {
+ const result: CLIOptions = {
+ note: false,
+ notebook: false,
+ reminder: false
+ };
+ await yargs(hideBin(process.argv))
+ .command("new", "Create a new item", (yargs) => {
+ return yargs
+ .command("note", "Create a new note", {}, () => {
+ result.note = true;
+ })
+ .command("notebook", "Create a new notebook", {}, () => {
+ result.notebook = true;
+ })
+ .command("reminder", "Add a new reminder", {}, () => {
+ result.reminder = true;
+ });
+ })
+ .command("open", "Open a specific item", (yargs) => {
+ return yargs
+ .command(
+ "note",
+ "Open a note",
+ { id: { string: true, description: "Id of the note" } },
+ (args) => {
+ result.note = args.id;
+ }
+ )
+ .command(
+ "notebook",
+ "Open a notebook",
+ { id: { string: true, description: "Id of the notebook" } },
+ (args) => {
+ result.notebook = args.id;
+ }
+ )
+ .command(
+ "topic",
+ "Open a topic",
+ {
+ id: { string: true, description: "Id of the topic" },
+ notebookId: { string: true, description: "Id of the notebook" }
+ },
+ (args) => {
+ result.notebook = `${args.notebookId}/${args.id}`;
+ }
+ );
+ })
+ .parse();
+ return result;
+}
diff --git a/apps/web/desktop/electron.js b/apps/web/desktop/electron.js
index 64693461f..59ba23177 100644
--- a/apps/web/desktop/electron.js
+++ b/apps/web/desktop/electron.js
@@ -39,6 +39,9 @@ import { hideBin } from "yargs/helpers";
import { getDesktopIntegration } from "./config/desktopIntegration";
import { AutoLaunch } from "./autolaunch";
import bringToFront from "./ipc/actions/bringToFront";
+import { setupJumplist } from "./jumplist";
+import { setupTray } from "./tray";
+import { parseArguments } from "./cli";
if (!RELEASE) {
require("electron-reloader")(module);
@@ -56,6 +59,8 @@ if (process.platform === "win32") {
var mainWindowState;
async function createWindow() {
+ const cliOptions = await parseArguments();
+
mainWindowState = new WindowState({});
setTheme(getTheme());
@@ -96,7 +101,6 @@ async function createWindow() {
setPrivacyMode({ privacyMode: getPrivacyMode() });
}
- const cliOptions = await parseCli();
try {
await mainWindow.loadURL(`${createURL(cliOptions)}`);
} catch (e) {
@@ -142,6 +146,9 @@ app.on("activate", () => {
}
});
+/**
+ * @param {import("./cli").CLIOptions} options
+ */
function createURL(options) {
const url = new URL(isDevelopment() ? "http://localhost:3000" : PROTOCOL_URL);
@@ -156,136 +163,6 @@ function createURL(options) {
return url;
}
-async function parseCli() {
- const result = {
- note: false,
- notebook: false,
- reminder: false
- };
- await yargs(hideBin(process.argv))
- .command("new", "Create a new item", (yargs) => {
- return yargs
- .command("note", "Create a new note", {}, () => (result.note = true))
- .command(
- "notebook",
- "Create a new notebook",
- {},
- () => (result.notebook = true)
- )
- .command(
- "reminder",
- "Add a new reminder",
- {},
- () => (result.reminder = true)
- );
- })
- .command("open", "Open a specific item", (yargs) => {
- return yargs
- .command(
- "note",
- "Open a note",
- { id: { string: true, description: "Id of the note" } },
- (args) => (result.note = args.id)
- )
- .command(
- "notebook",
- "Open a notebook",
- { id: { string: true, description: "Id of the notebook" } },
- (args) => (result.notebook = args.id)
- )
- .command(
- "topic",
- "Open a topic",
- {
- id: { string: true, description: "Id of the topic" },
- notebookId: { string: true, description: "Id of the notebook" }
- },
- (args) => (result.notebook = `${args.notebookId}/${args.id}`)
- );
- })
- .parse();
- return result;
-}
-
-function setupJumplist() {
- if (process.platform === "win32") {
- app.setJumpList([
- { type: "frequent" },
- {
- type: "tasks",
- items: [
- {
- program: process.execPath,
- iconPath: process.execPath,
- args: "new note",
- description: "Create a new note",
- title: "New note",
- type: "task"
- },
- {
- program: process.execPath,
- iconPath: process.execPath,
- args: "new notebook",
- description: "Create a new notebook",
- title: "New notebook",
- type: "task"
- },
- {
- program: process.execPath,
- iconPath: process.execPath,
- args: "new reminder",
- description: "Add a new reminder",
- title: "New reminder",
- type: "task"
- }
- ]
- }
- ]);
- }
-}
-
-function setupTray() {
- const tray = new Tray(APP_ICON_PATH);
-
- const contextMenu = Menu.buildFromTemplate([
- {
- label: "Show Notesnook",
- type: "normal",
- icon: APP_ICON_PATH,
- click: bringToFront
- },
- { type: "separator" },
- {
- label: "New note",
- type: "normal",
- click: () => {
- bringToFront();
- sendMessageToRenderer(EVENTS.createItem, { itemType: "note" });
- }
- },
- {
- label: "New notebook",
- type: "normal",
- click: () => {
- bringToFront();
- sendMessageToRenderer(EVENTS.createItem, { itemType: "notebook" });
- }
- },
- { type: "separator" },
- {
- label: "Quit Notesnook",
- type: "normal",
- click: () => {
- app.exit(0);
- }
- }
- ]);
- tray.on("double-click", bringToFront);
- tray.on("click", bringToFront);
- tray.setToolTip("Notesnook");
- tray.setContextMenu(contextMenu);
-}
-
function setupDesktopIntegration() {
const desktopIntegration = getDesktopIntegration();
diff --git a/apps/web/desktop/jumplist.ts b/apps/web/desktop/jumplist.ts
new file mode 100644
index 000000000..7be76bd1b
--- /dev/null
+++ b/apps/web/desktop/jumplist.ts
@@ -0,0 +1,61 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+import { app } from "electron";
+
+export function setupJumplist() {
+ if (process.platform === "win32") {
+ windows();
+ }
+}
+
+function windows() {
+ app.setJumpList([
+ { type: "frequent" },
+ {
+ type: "tasks",
+ items: [
+ {
+ program: process.execPath,
+ iconPath: process.execPath,
+ args: "new note",
+ description: "Create a new note",
+ title: "New note",
+ type: "task"
+ },
+ {
+ program: process.execPath,
+ iconPath: process.execPath,
+ args: "new notebook",
+ description: "Create a new notebook",
+ title: "New notebook",
+ type: "task"
+ },
+ {
+ program: process.execPath,
+ iconPath: process.execPath,
+ args: "new reminder",
+ description: "Add a new reminder",
+ title: "New reminder",
+ type: "task"
+ }
+ ]
+ }
+ ]);
+}
diff --git a/apps/web/desktop/tray.ts b/apps/web/desktop/tray.ts
new file mode 100644
index 000000000..393f4d33a
--- /dev/null
+++ b/apps/web/desktop/tray.ts
@@ -0,0 +1,66 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+import { app, Menu, Tray } from "electron";
+import { EVENTS } from "./events";
+import bringToFront from "./ipc/actions/bringToFront";
+import { sendMessageToRenderer } from "./ipc/utils";
+import { APP_ICON_PATH } from "./utils";
+
+export function setupTray() {
+ const tray = new Tray(APP_ICON_PATH);
+
+ const contextMenu = Menu.buildFromTemplate([
+ {
+ label: "Show Notesnook",
+ type: "normal",
+ icon: APP_ICON_PATH,
+ click: bringToFront
+ },
+ { type: "separator" },
+ {
+ label: "New note",
+ type: "normal",
+ click: () => {
+ bringToFront();
+ sendMessageToRenderer(EVENTS.createItem, { itemType: "note" });
+ }
+ },
+ {
+ label: "New notebook",
+ type: "normal",
+ click: () => {
+ bringToFront();
+ sendMessageToRenderer(EVENTS.createItem, { itemType: "notebook" });
+ }
+ },
+ { type: "separator" },
+ {
+ label: "Quit Notesnook",
+ type: "normal",
+ click: () => {
+ app.exit(0);
+ }
+ }
+ ]);
+ tray.on("double-click", bringToFront);
+ tray.on("click", bringToFront);
+ tray.setToolTip("Notesnook");
+ tray.setContextMenu(contextMenu);
+}