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 privacy mode for desktop on win & mac (#1620)
Muhammad Ali95e1daf7f7a7
diff --git a/apps/web/desktop/config/privacyMode.js b/apps/web/desktop/config/privacyMode.jsnew file mode 100644index 000000000..7f6ec9b8e--- /dev/null+++ b/apps/web/desktop/config/privacyMode.js@@ -0,0 +1,31 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2022 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 { JSONStorage } from "../jsonstorage";++function getPrivacyMode() {+ let mode = JSONStorage.get("privacyMode");+ return mode === undefined ? false : mode;+}++function setPrivacyMode(mode) {+ return JSONStorage.set("privacyMode", mode);+}++export { setPrivacyMode, getPrivacyMode };diff --git a/apps/web/desktop/electron.js b/apps/web/desktop/electron.jsindex 020b04e9b..7d3902472 100644--- a/apps/web/desktop/electron.js+++ b/apps/web/desktop/electron.js@@ -33,6 +33,7 @@ import { WindowState } from "./config/windowstate";import { sendMessageToRenderer } from "./ipc/utils";import { EVENTS } from "./events";import "./ipc/index.js";+import getPrivacyMode from "./ipc/calls/getPrivacyMode";if (!RELEASE) {require("electron-reloader")(module);@@ -81,6 +82,10 @@ async function createWindow() {if (isDevelopment())mainWindow.webContents.openDevTools({ mode: "right", activate: true });+ if (getPrivacyMode()) {+ global.win.setContentProtection(true);+ }+try {await mainWindow.loadURL(isDevelopment() ? "http://localhost:3000" : PROTOCOL_URLdiff --git a/apps/web/desktop/ipc/actions/index.js b/apps/web/desktop/ipc/actions/index.jsindex 361d6cde8..4fdf8c870 100644--- a/apps/web/desktop/ipc/actions/index.js+++ b/apps/web/desktop/ipc/actions/index.js@@ -24,6 +24,7 @@ import installUpdate from "./installUpdate";import open from "./open";import saveFile from "./saveFile";import setZoomFactor from "./setZoomFactor";+import setPrivacyMode from "./setPrivacyMode";const actions = {changeAppTheme,@@ -32,7 +33,8 @@ const actions = {installUpdate,open,saveFile,- setZoomFactor+ setZoomFactor,+ setPrivacyMode};export function getAction(actionName) {diff --git a/apps/web/desktop/ipc/actions/setPrivacyMode.js b/apps/web/desktop/ipc/actions/setPrivacyMode.jsnew file mode 100644index 000000000..118ae407a--- /dev/null+++ b/apps/web/desktop/ipc/actions/setPrivacyMode.js@@ -0,0 +1,27 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2022 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 { setPrivacyMode } from "../../config/privacyMode";++export default (args) => {+ if (!global.win) return;+ const { privacyMode } = args;+ global.win.setContentProtection(privacyMode);+ setPrivacyMode(privacyMode);+};diff --git a/apps/web/desktop/ipc/calls/getPrivacyMode.js b/apps/web/desktop/ipc/calls/getPrivacyMode.jsnew file mode 100644index 000000000..32c6aeba0--- /dev/null+++ b/apps/web/desktop/ipc/calls/getPrivacyMode.js@@ -0,0 +1,24 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2022 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 { getPrivacyMode } from "../../config/privacyMode";++export default function () {+ return getPrivacyMode();+}diff --git a/apps/web/desktop/ipc/calls/index.js b/apps/web/desktop/ipc/calls/index.jsindex 4af981a88..cd57113fb 100644--- a/apps/web/desktop/ipc/calls/index.js+++ b/apps/web/desktop/ipc/calls/index.js@@ -18,11 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import getZoomFactor from "./getZoomFactor";+import getPrivacyMode from "./getPrivacyMode";import selectDirectory from "./selectDirectory";import { gunzip, gzip } from "./gzip";const calls = {getZoomFactor,+ getPrivacyMode,selectDirectory,gunzip,gzipdiff --git a/apps/web/desktop/preload.js b/apps/web/desktop/preload.jsindex 60d75e30f..bcdc3e7f8 100644--- a/apps/web/desktop/preload.js+++ b/apps/web/desktop/preload.js@@ -51,6 +51,11 @@ contextBridge.exposeInMainWorld("config", {return ipcRenderer.invoke("fromRenderer", {type: "getZoomFactor"});+ },+ privacyMode: () => {+ return ipcRenderer.invoke("fromRenderer", {+ type: "getPrivacyMode"+ });}});diff --git a/apps/web/src/commands/set-privacy-mode.js b/apps/web/src/commands/set-privacy-mode.jsnew file mode 100644index 000000000..a6704b5ad--- /dev/null+++ b/apps/web/src/commands/set-privacy-mode.js@@ -0,0 +1,24 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2022 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 { invokeCommand } from "./index";++export default function setPrivacyMode(privacyMode) {+ invokeCommand("setPrivacyMode", { privacyMode });+}diff --git a/apps/web/src/hooks/use-privacy-mode.js b/apps/web/src/hooks/use-privacy-mode.jsnew file mode 100644index 000000000..c18b885c8--- /dev/null+++ b/apps/web/src/hooks/use-privacy-mode.js@@ -0,0 +1,39 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2022 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 { useCallback, useEffect, useState } from "react";+import setPrivacyMode from "../commands/set-privacy-mode";++export default function usePrivacyMode() {+ const [_privacyMode, _setPrivacyMode = useState(false);++ useEffect(() => {+ if (!window.config) return;+ (async function () {+ _setPrivacyMode(await window.config.privacyMode());+ })();+ }, []);++ const set = useCallback((privacyMode) => {+ setPrivacyMode(privacyMode);+ _setPrivacyMode(privacyMode);+ }, []);++ return [_privacyMode, set];+}diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.jsindex e361831d0..fce85125e 100644--- a/apps/web/src/views/settings.js+++ b/apps/web/src/views/settings.js@@ -56,7 +56,12 @@ import { appVersion } from "../utils/version";import { CHECK_IDS } from "@notesnook/core/common";import Tip from "../components/tip";import Toggle from "../components/toggle";-import { isDesktop, isMacStoreApp, isTesting } from "../utils/platform";+import {+ getPlatform,+ isDesktop,+ isMacStoreApp,+ isTesting+} from "../utils/platform";import Vault from "../common/vault";import { isUserPremium } from "../hooks/use-is-user-premium";import { Slider } from "@theme-ui/components";@@ -68,6 +73,7 @@ import { debounce } from "../utils/debounce";import { clearLogs, downloadLogs } from "../utils/logger";import { exportNotes } from "../common/export";import { scheduleBackups } from "../common/reminders";+import usePrivacyMode from "../hooks/use-privacy-mode";function subscriptionStatusToString(user) {const status = user?.subscription?.type;@@ -182,6 +188,7 @@ function Settings() {"telemetry",true);+ const [privacyMode, setPrivacyMode] = usePrivacyMode();const [showReminderNotifications, setShowReminderNotifications] =usePersistentState("reminderNotifications", true);const [corsProxy, setCorsProxy] = usePersistentState(@@ -818,6 +825,17 @@ function Settings() {tip="Read details of all usage data we collect."/></Button>+ {isDesktop() && getPlatform() !== "linux" && (+ <Toggle+ title="Privacy Mode"+ onTip="Allow screen capturing of the Notesnook app."+ offTip="Prevent screen capturing of the Notesnook app. (Apps like TeamViewer & AnyDesk won't be able to capture Notesnook)."+ onToggled={() => {+ setPrivacyMode(!privacyMode);+ }}+ isToggled={privacyMode}+ />+ )}</>)}