mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-17 04:07:51 +01:00
desktop: add custom dns toggle in settings
This commit is contained in:
committed by
Abdullah Atta
parent
a46409ff44
commit
641e7484e3
@@ -32,6 +32,7 @@ import { AssetManager } from "../utils/asset-manager";
|
|||||||
import { isFlatpak } from "../utils";
|
import { isFlatpak } from "../utils";
|
||||||
import { setupDesktopIntegration } from "../utils/desktop-integration";
|
import { setupDesktopIntegration } from "../utils/desktop-integration";
|
||||||
import { rm } from "fs/promises";
|
import { rm } from "fs/promises";
|
||||||
|
import { disableCustomDns, enableCustomDns } from "../utils/custom-dns";
|
||||||
|
|
||||||
const t = initTRPC.create();
|
const t = initTRPC.create();
|
||||||
|
|
||||||
@@ -55,6 +56,15 @@ export const osIntegrationRouter = t.router({
|
|||||||
config.zoomFactor = factor;
|
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),
|
proxyRules: t.procedure.query(() => config.proxyRules),
|
||||||
setProxyRules: t.procedure
|
setProxyRules: t.procedure
|
||||||
.input(z.string().optional())
|
.input(z.string().optional())
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import path from "path";
|
|||||||
import { bringToFront } from "./utils/bring-to-front";
|
import { bringToFront } from "./utils/bring-to-front";
|
||||||
import { bridge } from "./api/bridge";
|
import { bridge } from "./api/bridge";
|
||||||
import { setupDesktopIntegration } from "./utils/desktop-integration";
|
import { setupDesktopIntegration } from "./utils/desktop-integration";
|
||||||
|
import { disableCustomDns, enableCustomDns } from "./utils/custom-dns";
|
||||||
|
|
||||||
// only run a single instance
|
// only run a single instance
|
||||||
if (!MAC_APP_STORE && !app.requestSingleInstanceLock()) {
|
if (!MAC_APP_STORE && !app.requestSingleInstanceLock()) {
|
||||||
@@ -151,14 +152,8 @@ async function createWindow() {
|
|||||||
app.once("ready", async () => {
|
app.once("ready", async () => {
|
||||||
console.info("App ready. Opening window.");
|
console.info("App ready. Opening window.");
|
||||||
|
|
||||||
app.configureHostResolver({
|
if (config.customDns) enableCustomDns();
|
||||||
secureDnsServers: [
|
else disableCustomDns();
|
||||||
"https://mozilla.cloudflare-dns.com/dns-query",
|
|
||||||
"https://dns.quad9.net/dns-query"
|
|
||||||
],
|
|
||||||
enableBuiltInResolver: true,
|
|
||||||
secureDnsMode: "automatic"
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isDevelopment()) registerProtocol();
|
if (!isDevelopment()) registerProtocol();
|
||||||
await createWindow();
|
await createWindow();
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export const config = {
|
|||||||
theme: nativeTheme.themeSource,
|
theme: nativeTheme.themeSource,
|
||||||
automaticUpdates: true,
|
automaticUpdates: true,
|
||||||
proxyRules: "",
|
proxyRules: "",
|
||||||
|
customDns: true,
|
||||||
|
|
||||||
backgroundColor: nativeTheme.themeSource === "dark" ? "#0f0f0f" : "#ffffff",
|
backgroundColor: nativeTheme.themeSource === "dark" ? "#0f0f0f" : "#ffffff",
|
||||||
windowControlsIconColor:
|
windowControlsIconColor:
|
||||||
|
|||||||
37
apps/desktop/src/utils/custom-dns.ts
Normal file
37
apps/desktop/src/utils/custom-dns.ts
Normal file
@@ -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
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -111,6 +111,26 @@ What data is collected & when?`,
|
|||||||
section: "privacy",
|
section: "privacy",
|
||||||
header: "Advanced",
|
header: "Advanced",
|
||||||
settings: [
|
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",
|
key: "custom-cors",
|
||||||
title: "Custom CORS proxy",
|
title: "Custom CORS proxy",
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class SettingStore extends BaseStore<SettingStore> {
|
|||||||
|
|
||||||
zoomFactor = 1.0;
|
zoomFactor = 1.0;
|
||||||
privacyMode = false;
|
privacyMode = false;
|
||||||
|
customDns = true;
|
||||||
hideNoteTitle = Config.get("hideNoteTitle", false);
|
hideNoteTitle = Config.get("hideNoteTitle", false);
|
||||||
telemetry = isTelemetryEnabled();
|
telemetry = isTelemetryEnabled();
|
||||||
dateFormat = "DD-MM-YYYY";
|
dateFormat = "DD-MM-YYYY";
|
||||||
@@ -67,6 +68,7 @@ class SettingStore extends BaseStore<SettingStore> {
|
|||||||
desktopIntegrationSettings:
|
desktopIntegrationSettings:
|
||||||
await desktop?.integration.desktopIntegration.query(),
|
await desktop?.integration.desktopIntegration.query(),
|
||||||
privacyMode: await desktop?.integration.privacyMode.query(),
|
privacyMode: await desktop?.integration.privacyMode.query(),
|
||||||
|
customDns: await desktop?.integration.customDns.query(),
|
||||||
zoomFactor: await desktop?.integration.zoomFactor.query(),
|
zoomFactor: await desktop?.integration.zoomFactor.query(),
|
||||||
autoUpdates: await desktop?.updater.autoUpdates.query(),
|
autoUpdates: await desktop?.updater.autoUpdates.query(),
|
||||||
proxyRules: await desktop?.integration.proxyRules.query()
|
proxyRules: await desktop?.integration.proxyRules.query()
|
||||||
@@ -177,6 +179,12 @@ class SettingStore extends BaseStore<SettingStore> {
|
|||||||
await desktop?.integration.setPrivacyMode.mutate({ enabled: !privacyMode });
|
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 () => {
|
toggleHideTitle = async () => {
|
||||||
const { hideNoteTitle } = this.get();
|
const { hideNoteTitle } = this.get();
|
||||||
this.set({ hideNoteTitle: !hideNoteTitle });
|
this.set({ hideNoteTitle: !hideNoteTitle });
|
||||||
|
|||||||
Reference in New Issue
Block a user