Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

desktop: add setting to toggle the spell checker

Abdullah Attacd9867273fb2
diff --git a/apps/web/desktop/config/spellChecker.js b/apps/web/desktop/config/spellChecker.js
new file mode 100644
index 000000000..5b0e068b4
--- /dev/null
+++ b/apps/web/desktop/config/spellChecker.js
@@ -0,0 +1,31 @@
+/*
+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 { JSONStorage } from "../jsonstorage";
+
+function getIsSpellCheckerEnabled() {
+ let mode = JSONStorage.get("isSpellCheckerEnabled");
+ return mode === undefined ? true : mode;
+}
+
+function setIsSpellCheckerEnabled(mode) {
+ return JSONStorage.set("isSpellCheckerEnabled", mode);
+}
+
+export { getIsSpellCheckerEnabled, setIsSpellCheckerEnabled };
diff --git a/apps/web/desktop/electron.js b/apps/web/desktop/electron.js
index a69585d87..251fbc60d 100644
--- a/apps/web/desktop/electron.js
+++ b/apps/web/desktop/electron.js
@@ -35,6 +35,7 @@ import { EVENTS } from "./events";
import "./ipc/index.js";
import getPrivacyMode from "./ipc/calls/getPrivacyMode";
import setPrivacyMode from "./ipc/actions/setPrivacyMode";
+import { getIsSpellCheckerEnabled } from "./config/spellChecker";
if (!RELEASE) {
require("electron-reloader")(module);
@@ -71,7 +72,7 @@ async function createWindow() {
enableRemoteModule: false,
contextIsolation: true,
nativeWindowOpen: true,
- spellcheck: false,
+ spellcheck: getIsSpellCheckerEnabled(),
preload: __dirname + "/preload.js"
}
});
diff --git a/apps/web/desktop/ipc/actions/index.js b/apps/web/desktop/ipc/actions/index.js
index 9309fe8ad..5544f3e1c 100644
--- a/apps/web/desktop/ipc/actions/index.js
+++ b/apps/web/desktop/ipc/actions/index.js
@@ -27,6 +27,7 @@ import setZoomFactor from "./setZoomFactor";
import setPrivacyMode from "./setPrivacyMode";
import showNotification from "./showNotification";
import bringToFront from "./bringToFront";
+import toggleSpellChecker from "./toggleSpellChecker";
const actions = {
changeAppTheme,
@@ -38,7 +39,8 @@ const actions = {
setZoomFactor,
setPrivacyMode,
showNotification,
- bringToFront
+ bringToFront,
+ toggleSpellChecker
};
export function getAction(actionName) {
diff --git a/apps/web/desktop/ipc/actions/toggleSpellChecker.js b/apps/web/desktop/ipc/actions/toggleSpellChecker.js
new file mode 100644
index 000000000..0e642c3e8
--- /dev/null
+++ b/apps/web/desktop/ipc/actions/toggleSpellChecker.js
@@ -0,0 +1,27 @@
+/*
+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 { setIsSpellCheckerEnabled } from "../../config/spellChecker";
+
+export default (args) => {
+ if (!globalThis.window) return;
+ const { enabled } = args;
+ globalThis.window.webContents.session.setSpellCheckerEnabled(enabled);
+ setIsSpellCheckerEnabled(enabled);
+};
diff --git a/apps/web/desktop/ipc/calls/getSpellChecker.js b/apps/web/desktop/ipc/calls/getSpellChecker.js
new file mode 100644
index 000000000..23ad2c526
--- /dev/null
+++ b/apps/web/desktop/ipc/calls/getSpellChecker.js
@@ -0,0 +1,35 @@
+/*
+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 { getIsSpellCheckerEnabled } from "../../config/spellChecker";
+
+
+/**
+ *
+ * @param {*} args
+ * @param {import("electron").BrowserWindow} win
+ * @returns
+ */
+export default function (_args, win) {
+ if (!win) return;
+
+ return {
+ enabled: getIsSpellCheckerEnabled(),
+ };
+}
diff --git a/apps/web/desktop/ipc/calls/index.js b/apps/web/desktop/ipc/calls/index.js
index b894a3103..02f0bbe24 100644
--- a/apps/web/desktop/ipc/calls/index.js
+++ b/apps/web/desktop/ipc/calls/index.js
@@ -21,13 +21,15 @@ import getZoomFactor from "./getZoomFactor";
import getPrivacyMode from "./getPrivacyMode";
import selectDirectory from "./selectDirectory";
import { gunzip, gzip } from "./gzip";
+import getSpellChecker from "./getSpellChecker";
const calls = {
getZoomFactor,
getPrivacyMode,
selectDirectory,
gunzip,
- gzip
+ gzip,
+ getSpellChecker
};
export const getCall = function getAction(callName) {
diff --git a/apps/web/desktop/preload.js b/apps/web/desktop/preload.js
index b7eb4644a..d9cd5b7d8 100644
--- a/apps/web/desktop/preload.js
+++ b/apps/web/desktop/preload.js
@@ -56,6 +56,11 @@ contextBridge.exposeInMainWorld("config", {
return ipcRenderer.invoke("fromRenderer", {
type: "getPrivacyMode"
});
+ },
+ spellChecker: () => {
+ return ipcRenderer.invoke("fromRenderer", {
+ type: "getSpellChecker"
+ });
}
});
diff --git a/apps/web/src/commands/toggle-spell-checker.js b/apps/web/src/commands/toggle-spell-checker.js
new file mode 100644
index 000000000..88fa8a2da
--- /dev/null
+++ b/apps/web/src/commands/toggle-spell-checker.js
@@ -0,0 +1,24 @@
+/*
+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 { invokeCommand } from "./index";
+
+export default function toggleSpellChecker(enabled) {
+ invokeCommand("toggleSpellChecker", { enabled });
+}
diff --git a/apps/web/src/global.d.ts b/apps/web/src/global.d.ts
index 1dd74ffc6..580672864 100644
--- a/apps/web/src/global.d.ts
+++ b/apps/web/src/global.d.ts
@@ -17,7 +17,13 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+type SpellCheckerOptions = {
+ enabled: boolean;
+};
declare interface Window {
+ config: {
+ static spellChecker(): Promise<SpellCheckerOptions>;
+ };
native: {
static gzip({
data,
diff --git a/apps/web/src/hooks/use-spell-checker.ts b/apps/web/src/hooks/use-spell-checker.ts
new file mode 100644
index 000000000..ad2c6adfe
--- /dev/null
+++ b/apps/web/src/hooks/use-spell-checker.ts
@@ -0,0 +1,53 @@
+/*
+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 { useCallback, useEffect, useState } from "react";
+import toggleSpellChecker from "../commands/toggle-spell-checker";
+
+export default function useSpellChecker() {
+ const [spellChecker, setSpellChecker] = useState<SpellCheckerOptions>();
+
+ const loadSpellChecker = useCallback(async () => {
+ const options = await window.config.spellChecker();
+ setSpellChecker(options);
+ return options;
+ }, []);
+
+ useEffect(() => {
+ if (!window.config) return;
+ (async function () {
+ await loadSpellChecker();
+ })();
+ }, [loadSpellChecker]);
+
+ const toggle = useCallback(
+ async (enabled: boolean) => {
+ toggleSpellChecker(enabled);
+ await loadSpellChecker();
+ },
+ [loadSpellChecker]
+ );
+
+
+ return {
+ ...spellChecker,
+ toggle,
+ loadSpellChecker
+ };
+}
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index c9be6fa96..23208bd5f 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -75,6 +75,7 @@ import { exportNotes } from "../common/export";
import { scheduleBackups } from "../common/reminders";
import usePrivacyMode from "../hooks/use-privacy-mode";
import { useTelemetry } from "../hooks/use-telemetry";
+import useSpellChecker from "../hooks/use-spell-checker";
function subscriptionStatusToString(user) {
const status = user?.subscription?.type;
@@ -189,8 +190,8 @@ function Settings() {
"backupStorageLocation",
PATHS.backupsDirectory
);
- const [enableTelemetry, setEnableTelemetry, isTelemetryDisabled] =
- useTelemetry();
+ const [enableTelemetry, setEnableTelemetry] = useTelemetry();
+ const spellChecker = useSpellChecker();
const [privacyMode, setPrivacyMode] = usePrivacyMode();
const [showReminderNotifications, setShowReminderNotifications] =
usePersistentState("reminderNotifications", true);
@@ -565,6 +566,12 @@ function Settings() {
tip="Customize the editor toolbar to fit your needs."
/>
</Button>
+
+ <Toggle
+ title="Enable spellchecker"
+ onToggled={() => spellChecker.toggle(!spellChecker.enabled)}
+ isToggled={spellChecker.enabled}
+ />
</>
)}