A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
desktop: fix external links opening in-app instead of default browser on desktop (#9417)
Copilot5c252c78430a
diff --git a/apps/desktop/src/api/window.ts b/apps/desktop/src/api/window.tsindex 4c75903c5..7490ac3f6 100644--- a/apps/desktop/src/api/window.ts+++ b/apps/desktop/src/api/window.ts@@ -34,6 +34,17 @@ export const windowRouter = t.router({}),maximized: t.procedure.query(() => globalThis.window?.isMaximized()),fullscreen: t.procedure.query(() => globalThis.window?.isFullScreen()),+ onClose: t.procedure.subscription(() => {+ return observable<void>((emit) => {+ function listener() {+ emit.next();+ }+ globalThis.window?.addListener("close", listener);+ return () => {+ globalThis.window?.removeListener("close", listener);+ };+ });+ }),onWindowStateChanged: t.procedure.subscription(() => {return observable<{ maximized: boolean; fullscreen: boolean }>((emit) => {function listener() {diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex ce0bdb502..cc9acf8c6 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -52,6 +52,9 @@ locale.then(({ default: locale }) => {});setI18nGlobal(i18n);+const appHostnames = isDevelopment()+ ? ["localhost", "127.0.0.1"]+ : ["app.notesnook.com"];// only run a single instanceif (!MAC_APP_STORE && !app.requestSingleInstanceLock()) {console.log("Another instance is already running!");@@ -173,6 +176,19 @@ async function createWindow() {return { action: "deny" };});+ mainWindow.webContents.on("will-navigate", (event, url) => {+ try {+ const parsedUrl = new URL(url);+ if (!appHostnames.includes(parsedUrl.hostname)) {+ event.preventDefault();+ shell.openExternal(url);+ }+ } catch (e) {+ console.error("will-navigate: failed to parse URL", url, e);+ event.preventDefault();+ }+ });+nativeTheme.on("updated", () => {setupTray();setupJumplist();diff --git a/apps/web/src/common/db.ts b/apps/web/src/common/db.tsindex 391f171f0..f92828847 100644--- a/apps/web/src/common/db.ts+++ b/apps/web/src/common/db.ts@@ -24,12 +24,7 @@ import { createDialect } from "./sqlite";import { isFeatureSupported } from "../utils/feature-check";import { generatePassword } from "../utils/password-generator";import { deriveKey, useKeyStore } from "../interfaces/key-store";-import {- hosts,- logManager,- SubscriptionPlan,- SubscriptionStatus-} from "@notesnook/core";+import { hosts, SubscriptionPlan, SubscriptionStatus } from "@notesnook/core";import Config from "../utils/config";import { FileStorage } from "../interfaces/fs";@@ -130,13 +125,6 @@ async function initializeDatabase(persistence: DatabasePersistence) {await db.init();performance.mark("end:initdb");- window.addEventListener("beforeunload", async () => {- if (IS_DESKTOP_APP) {- await db.sql().destroy();- await logManager?.close();- }- });-if (db.migrations?.required()) {await import("../dialogs/migration-dialog").then(({ MigrationDialog }) =>MigrationDialog.show({})diff --git a/apps/web/src/common/desktop-bridge/index.desktop.ts b/apps/web/src/common/desktop-bridge/index.desktop.tsindex 89bc30085..e5ceab717 100644--- a/apps/web/src/common/desktop-bridge/index.desktop.ts+++ b/apps/web/src/common/desktop-bridge/index.desktop.ts@@ -24,10 +24,13 @@ import { AppEventManager, AppEvents } from "../app-events";import { TaskScheduler } from "../../utils/task-scheduler";import { checkForUpdate } from "../../utils/updater";import { showToast } from "../../utils/toast";+import { db } from "../db";+import { logManager } from "@notesnook/core";-export const desktop = createTRPCProxyClient<AppRouter>({- links: [ipcLink()]-});+export const desktop: ReturnType<typeof createTRPCProxyClient<AppRouter>> =+ createTRPCProxyClient<AppRouter>({+ links: [ipcLink()]+ });attachListeners();function attachListeners() {@@ -63,6 +66,13 @@ function attachListeners() {attachListener(AppEvents.updateError));+ desktop.window.onClose.subscribe(undefined, {+ async onData() {+ await db.sql().destroy();+ await logManager?.close();+ }+ });+TaskScheduler.register("updateCheck", "0 0 */12 * * * *", () => {checkForUpdate();});