Skip to content

Commit

Permalink
desktop: add proxy settings (streetwriters#4196)
Browse files Browse the repository at this point in the history
  • Loading branch information
alihamuh authored Mar 4, 2024
1 parent 1a96dc9 commit 6fd6bd0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
8 changes: 8 additions & 0 deletions apps/desktop/src/api/os-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export const osIntegrationRouter = t.router({
config.zoomFactor = factor;
}),

proxyRules: t.procedure.query(() => config.proxyRules),
setProxyRules: t.procedure
.input(z.string().optional())
.mutation(({ input: proxyRules }) => {
globalThis.window?.webContents.session.setProxy({ proxyRules });
config.proxyRules = proxyRules || "";
}),

privacyMode: t.procedure.query(() => config.privacyMode),
setPrivacyMode: t.procedure
.input(z.object({ enabled: z.boolean() }))
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const config = {
isSpellCheckerEnabled: true,
zoomFactor: 1,
theme: nativeTheme.themeSource,
automaticUpdates: true
automaticUpdates: true,
proxyRules: ""
};

type ConfigKey = keyof typeof config;
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/dialogs/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
Privacy,
Pro,
ShieldLock,
Sync
Sync,
Proxy
} from "../../components/icons";
import { Perform } from "../../common/dialog-controller";
import NavigationItem from "../../components/navigation-menu/navigation-item";
Expand Down Expand Up @@ -65,7 +66,6 @@ import {
import { AppearanceSettings } from "./appearance-settings";
import { debounce } from "@notesnook/common";
import { SubscriptionSettings } from "./subscription-settings";
import { alpha } from "@theme-ui/color";
import { ScopedThemeProvider } from "../../components/theme-provider";

type SettingsDialogProps = { onClose: Perform };
Expand Down
26 changes: 25 additions & 1 deletion apps/web/src/dialogs/settings/privacy-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ What data is collected & when?`,
key: "custom-cors",
title: "Custom CORS proxy",
description:
"CORS proxy is required to directly download images from within the Notesnook app. It allows Notesnook to bypass browser restrictions by using a proxy. You can set a custom self-hosted proxy URL to increase your privacy",
"CORS proxy is required to directly download images from within the Notesnook app. It allows Notesnook to bypass browser restrictions by using a proxy. You can set a custom self-hosted proxy URL to increase your privacy.",
onStateChange: (listener) =>
useSettingStore.subscribe((s) => s.telemetry, listener),
components: [
Expand Down Expand Up @@ -144,6 +144,30 @@ What data is collected & when?`,
variant: "secondary"
}
]
},
{
key: "proxy-config",
title: "Proxy",
description: `Setup an HTTP/HTTPS/SOCKS proxy.
For example:
http://foobar:80
socks4://proxy.example.com
http://username:password@foobar:80
To remove the proxy, simply erase everything in the input.`,
onStateChange: (listener) =>
useSettingStore.subscribe((c) => c.proxyRules, listener),
components: [
{
type: "input",
inputType: "text",
defaultValue: () => useSettingStore.getState().proxyRules || "",
onChange: (value) => {
useSettingStore.getState().setProxyRules(value);
}
}
]
}
]
}
Expand Down
12 changes: 11 additions & 1 deletion apps/web/src/stores/setting-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class SettingStore extends BaseStore {
desktopIntegrationSettings = undefined;
autoUpdates = true;
isFlatpak = false;
/**
* @type {string|undefined}
*/
proxyRules = undefined;

refresh = async () => {
this.set({
Expand All @@ -70,7 +74,8 @@ class SettingStore extends BaseStore {
await desktop?.integration.desktopIntegration.query(),
privacyMode: await desktop?.integration.privacyMode.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()
});
};

Expand Down Expand Up @@ -99,6 +104,11 @@ class SettingStore extends BaseStore {
this.set({ zoomFactor });
};

setProxyRules = async (proxyRules) => {
await desktop?.integration.setProxyRules.mutate(proxyRules);
this.set({ proxyRules });
};

setEncryptBackups = (encryptBackups) => {
this.set({ encryptBackups });
Config.set("encryptBackups", encryptBackups);
Expand Down

0 comments on commit 6fd6bd0

Please sign in to comment.