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: add custom dns toggle in settings
Abdullah Atta641e7484e36a
diff --git a/apps/desktop/src/api/os-integration.ts b/apps/desktop/src/api/os-integration.tsindex 39ced0928..768f124ad 100644--- a/apps/desktop/src/api/os-integration.ts+++ b/apps/desktop/src/api/os-integration.ts@@ -32,6 +32,7 @@ import { AssetManager } from "../utils/asset-manager";import { isFlatpak } from "../utils";import { setupDesktopIntegration } from "../utils/desktop-integration";import { rm } from "fs/promises";+import { disableCustomDns, enableCustomDns } from "../utils/custom-dns";const t = initTRPC.create();@@ -55,6 +56,15 @@ export const osIntegrationRouter = t.router({config.zoomFactor = factor;}),+ customDns: t.procedure.query(() => config.customDns),+ setCustomDns: t.procedure+ .input(z.boolean())+ .mutation(({ input: customDns }) => {+ if (customDns) enableCustomDns();+ else disableCustomDns();+ config.customDns = customDns;+ }),+proxyRules: t.procedure.query(() => config.proxyRules),setProxyRules: t.procedure.input(z.string().optional())diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex fe8e3c709..d24770a1c 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -35,6 +35,7 @@ import path from "path";import { bringToFront } from "./utils/bring-to-front";import { bridge } from "./api/bridge";import { setupDesktopIntegration } from "./utils/desktop-integration";+import { disableCustomDns, enableCustomDns } from "./utils/custom-dns";// only run a single instanceif (!MAC_APP_STORE && !app.requestSingleInstanceLock()) {@@ -151,14 +152,8 @@ async function createWindow() {app.once("ready", async () => {console.info("App ready. Opening window.");- app.configureHostResolver({- secureDnsServers: [- "https://mozilla.cloudflare-dns.com/dns-query",- "https://dns.quad9.net/dns-query"- ],- enableBuiltInResolver: true,- secureDnsMode: "automatic"- });+ if (config.customDns) enableCustomDns();+ else disableCustomDns();if (!isDevelopment()) registerProtocol();await createWindow();diff --git a/apps/desktop/src/utils/config.ts b/apps/desktop/src/utils/config.tsindex da6a5622c..23a58a180 100644--- a/apps/desktop/src/utils/config.ts+++ b/apps/desktop/src/utils/config.ts@@ -43,6 +43,7 @@ export const config = {theme: nativeTheme.themeSource,automaticUpdates: true,proxyRules: "",+ customDns: true,backgroundColor: nativeTheme.themeSource === "dark" ? "#0f0f0f" : "#ffffff",windowControlsIconColor:diff --git a/apps/desktop/src/utils/custom-dns.ts b/apps/desktop/src/utils/custom-dns.tsnew file mode 100644index 000000000..f70e40e24--- /dev/null+++ b/apps/desktop/src/utils/custom-dns.ts@@ -0,0 +1,37 @@+/*+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 { app } from "electron";++export function enableCustomDns() {+ app.configureHostResolver({+ secureDnsServers: [+ "https://mozilla.cloudflare-dns.com/dns-query",+ "https://dns.quad9.net/dns-query"+ ],+ enableBuiltInResolver: true+ });+}++export function disableCustomDns() {+ app.configureHostResolver({+ secureDnsServers: [],+ enableBuiltInResolver: true+ });+}diff --git a/apps/web/src/dialogs/settings/privacy-settings.ts b/apps/web/src/dialogs/settings/privacy-settings.tsindex 3052dec5d..2c897ca34 100644--- a/apps/web/src/dialogs/settings/privacy-settings.ts+++ b/apps/web/src/dialogs/settings/privacy-settings.ts@@ -111,6 +111,26 @@ What data is collected & when?`,section: "privacy",header: "Advanced",settings: [+ {+ key: "custom-dns",+ title: "Use custom DNS",+ description: `Notesnook uses the following DNS providers:++1. Cloudflare DNS+2. Quad9++This can sometimes bypass local ISP blockages on Notesnook traffic. Disable this if you want the app to use system's DNS settings.`,+ onStateChange: (listener) =>+ useSettingStore.subscribe((s) => s.customDns, listener),+ isHidden: () => !IS_DESKTOP_APP,+ components: [+ {+ type: "toggle",+ isToggled: () => useSettingStore.getState().customDns,+ toggle: () => useSettingStore.getState().toggleCustomDns()+ }+ ]+ },{key: "custom-cors",title: "Custom CORS proxy",diff --git a/apps/web/src/stores/setting-store.ts b/apps/web/src/stores/setting-store.tsindex 5092df597..e52f02111 100644--- a/apps/web/src/stores/setting-store.ts+++ b/apps/web/src/stores/setting-store.ts@@ -42,6 +42,7 @@ class SettingStore extends BaseStore<SettingStore> {zoomFactor = 1.0;privacyMode = false;+ customDns = true;hideNoteTitle = Config.get("hideNoteTitle", false);telemetry = isTelemetryEnabled();dateFormat = "DD-MM-YYYY";@@ -67,6 +68,7 @@ class SettingStore extends BaseStore<SettingStore> {desktopIntegrationSettings:await desktop?.integration.desktopIntegration.query(),privacyMode: await desktop?.integration.privacyMode.query(),+ customDns: await desktop?.integration.customDns.query(),zoomFactor: await desktop?.integration.zoomFactor.query(),autoUpdates: await desktop?.updater.autoUpdates.query(),proxyRules: await desktop?.integration.proxyRules.query()@@ -177,6 +179,12 @@ class SettingStore extends BaseStore<SettingStore> {await desktop?.integration.setPrivacyMode.mutate({ enabled: !privacyMode });};+ toggleCustomDns = async () => {+ const customDns = this.get().customDns;+ this.set({ customDns: !customDns });+ await desktop?.integration.setCustomDns.mutate(!customDns);+ };+toggleHideTitle = async () => {const { hideNoteTitle } = this.get();this.set({ hideNoteTitle: !hideNoteTitle });