Skip to content

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

desktop: add icons for tray items & jumplist

Abdullah Atta45c6daabe78b
diff --git a/apps/web/desktop/asset-manager.ts b/apps/web/desktop/asset-manager.ts
new file mode 100644
index 000000000..733ae7d7e
--- /dev/null
+++ b/apps/web/desktop/asset-manager.ts
@@ -0,0 +1,42 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+
+import { nativeTheme } from "electron";
+import path from "path";
+import { isDevelopment } from "./utils";
+
+const APP_DIR = isDevelopment()
+ ? process.cwd()
+ : path.dirname(process.execPath);
+export class AssetManager {
+ static appIcon(options: {
+ size?: 16 | 24 | 32 | 48 | 64 | 128 | 256 | 512 | 1024;
+ format?: "ico" | "png" | "icns";
+ }) {
+ const { size = 32, format } = options;
+ if (format === "ico") return path.join("assets", "icons", "app.ico");
+ if (format === "icns") return path.join("assets", "icons", "app.icns");
+ return path.join("assets", "icons", `${size}x${size}.png`);
+ }
+
+ static icon(name: "note-add" | "notebook-add" | "reminder-add" | "quit") {
+ const prefix = nativeTheme.shouldUseDarkColors ? ".dark" : "";
+ return path.join(APP_DIR, "assets", "icons", `${name}${prefix}.png`);
+ }
+}
diff --git a/apps/web/desktop/assets/icons/note-add.dark.png b/apps/web/desktop/assets/icons/note-add.dark.png
new file mode 100644
index 000000000..c7bb3f953
Binary files /dev/null and b/apps/web/desktop/assets/icons/note-add.dark.png differ
diff --git a/apps/web/desktop/assets/icons/note-add.png b/apps/web/desktop/assets/icons/note-add.png
new file mode 100644
index 000000000..f51319af1
Binary files /dev/null and b/apps/web/desktop/assets/icons/note-add.png differ
diff --git a/apps/web/desktop/assets/icons/notebook-add.dark.png b/apps/web/desktop/assets/icons/notebook-add.dark.png
new file mode 100644
index 000000000..2484c63a0
Binary files /dev/null and b/apps/web/desktop/assets/icons/notebook-add.dark.png differ
diff --git a/apps/web/desktop/assets/icons/notebook-add.png b/apps/web/desktop/assets/icons/notebook-add.png
new file mode 100644
index 000000000..978256188
Binary files /dev/null and b/apps/web/desktop/assets/icons/notebook-add.png differ
diff --git a/apps/web/desktop/assets/icons/quit.dark.png b/apps/web/desktop/assets/icons/quit.dark.png
new file mode 100644
index 000000000..d56be9d97
Binary files /dev/null and b/apps/web/desktop/assets/icons/quit.dark.png differ
diff --git a/apps/web/desktop/assets/icons/quit.png b/apps/web/desktop/assets/icons/quit.png
new file mode 100644
index 000000000..151c23c5d
Binary files /dev/null and b/apps/web/desktop/assets/icons/quit.png differ
diff --git a/apps/web/desktop/assets/icons/reminder-add.dark.png b/apps/web/desktop/assets/icons/reminder-add.dark.png
new file mode 100644
index 000000000..007f010d3
Binary files /dev/null and b/apps/web/desktop/assets/icons/reminder-add.dark.png differ
diff --git a/apps/web/desktop/assets/icons/reminder-add.png b/apps/web/desktop/assets/icons/reminder-add.png
new file mode 100644
index 000000000..627c7622c
Binary files /dev/null and b/apps/web/desktop/assets/icons/reminder-add.png differ
diff --git a/apps/web/desktop/config/theme.js b/apps/web/desktop/config/theme.js
index 6c22d0d6c..8251d537d 100644
--- a/apps/web/desktop/config/theme.js
+++ b/apps/web/desktop/config/theme.js
@@ -21,7 +21,7 @@ import { JSONStorage } from "../jsonstorage";
import { nativeTheme } from "electron";
function getTheme() {
- return JSONStorage.get("theme") || "light";
+ return JSONStorage.get("theme") || nativeTheme.themeSource;
}
function setTheme(theme) {
diff --git a/apps/web/desktop/electron.js b/apps/web/desktop/electron.js
index 59ba23177..9fd23de6c 100644
--- a/apps/web/desktop/electron.js
+++ b/apps/web/desktop/electron.js
@@ -91,8 +91,8 @@ async function createWindow() {
globalThis.window = mainWindow;
setupMenu();
setupJumplist();
- setupTray();
setupDesktopIntegration();
+ setupTray();
if (isDevelopment())
mainWindow.webContents.openDevTools({ mode: "right", activate: true });
@@ -117,6 +117,9 @@ async function createWindow() {
});
nativeTheme.on("updated", () => {
+ setupTray();
+ setupJumplist();
+
if (getTheme() === "system") {
sendMessageToRenderer(EVENTS.themeChanged, {
theme: nativeTheme.shouldUseDarkColors ? "dark" : "light"
diff --git a/apps/web/desktop/jumplist.ts b/apps/web/desktop/jumplist.ts
index 7be76bd1b..da49d16a4 100644
--- a/apps/web/desktop/jumplist.ts
+++ b/apps/web/desktop/jumplist.ts
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { app } from "electron";
+import { AssetManager } from "./asset-manager";
export function setupJumplist() {
if (process.platform === "win32") {
@@ -27,13 +28,13 @@ export function setupJumplist() {
function windows() {
app.setJumpList([
- { type: "frequent" },
{
- type: "tasks",
+ type: "custom",
+ name: "Quick actions",
items: [
{
program: process.execPath,
- iconPath: process.execPath,
+ iconPath: AssetManager.icon("note-add"),
args: "new note",
description: "Create a new note",
title: "New note",
@@ -41,7 +42,7 @@ function windows() {
},
{
program: process.execPath,
- iconPath: process.execPath,
+ iconPath: AssetManager.icon("notebook-add"),
args: "new notebook",
description: "Create a new notebook",
title: "New notebook",
@@ -49,7 +50,7 @@ function windows() {
},
{
program: process.execPath,
- iconPath: process.execPath,
+ iconPath: AssetManager.icon("reminder-add"),
args: "new reminder",
description: "Add a new reminder",
title: "New reminder",
diff --git a/apps/web/desktop/tray.ts b/apps/web/desktop/tray.ts
index 393f4d33a..72da4b733 100644
--- a/apps/web/desktop/tray.ts
+++ b/apps/web/desktop/tray.ts
@@ -18,25 +18,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { app, Menu, Tray } from "electron";
+import { AssetManager } from "./asset-manager";
import { EVENTS } from "./events";
import bringToFront from "./ipc/actions/bringToFront";
import { sendMessageToRenderer } from "./ipc/utils";
-import { APP_ICON_PATH } from "./utils";
+let tray: Tray | undefined = undefined;
export function setupTray() {
- const tray = new Tray(APP_ICON_PATH);
+ if (tray) tray.destroy();
+ tray = new Tray(AssetManager.appIcon({ size: 32 }));
const contextMenu = Menu.buildFromTemplate([
{
- label: "Show Notesnook",
+ label: "Show app",
type: "normal",
- icon: APP_ICON_PATH,
+ icon: AssetManager.appIcon({ size: 32 }),
click: bringToFront
},
{ type: "separator" },
{
label: "New note",
type: "normal",
+ icon: AssetManager.icon("note-add"),
click: () => {
bringToFront();
sendMessageToRenderer(EVENTS.createItem, { itemType: "note" });
@@ -45,6 +48,7 @@ export function setupTray() {
{
label: "New notebook",
type: "normal",
+ icon: AssetManager.icon("notebook-add"),
click: () => {
bringToFront();
sendMessageToRenderer(EVENTS.createItem, { itemType: "notebook" });
@@ -52,7 +56,8 @@ export function setupTray() {
},
{ type: "separator" },
{
- label: "Quit Notesnook",
+ label: "Quit",
+ icon: AssetManager.icon("quit"),
type: "normal",
click: () => {
app.exit(0);