Skip to content

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

feat: add developer options

thecodrr54f7967c5717
diff --git a/apps/web/desktop/ipc/actions/index.js b/apps/web/desktop/ipc/actions/index.js
index 0f206c2c4..4ccd2da36 100644
--- a/apps/web/desktop/ipc/actions/index.js
+++ b/apps/web/desktop/ipc/actions/index.js
@@ -2,7 +2,7 @@ const changeAppTheme = require("./changeAppTheme");
const checkForUpdate = require("./checkForUpdate");
const downloadUpdate = require("./downloadUpdate");
const installUpdate = require("./installUpdate");
-const openLink = require("./openLink");
+const open = require("./open");
const saveFile = require("./saveFile");
const setZoomFactor = require("./setZoomFactor");
@@ -11,7 +11,7 @@ const actions = {
checkForUpdate,
downloadUpdate,
installUpdate,
- openLink,
+ open,
saveFile,
setZoomFactor,
};
diff --git a/apps/web/desktop/ipc/actions/open.js b/apps/web/desktop/ipc/actions/open.js
new file mode 100644
index 000000000..bf03256c1
--- /dev/null
+++ b/apps/web/desktop/ipc/actions/open.js
@@ -0,0 +1,6 @@
+const { shell } = require("electron");
+const { resolvePath } = require("../utils");
+module.exports = (args) => {
+ const { link, linkType } = args;
+ if (linkType === "path") return shell.openPath(resolvePath(link));
+};
diff --git a/apps/web/desktop/ipc/actions/openLink.js b/apps/web/desktop/ipc/actions/openLink.js
deleted file mode 100644
index 990e939ca..000000000
--- a/apps/web/desktop/ipc/actions/openLink.js
+++ /dev/null
@@ -1,5 +0,0 @@
-const { shell } = require("electron");
-module.exports = (args) => {
- const { link } = args;
- return shell.openExternal(link);
-};
diff --git a/apps/web/desktop/paths.js b/apps/web/desktop/paths.js
index ffb2c4ace..ec532033a 100644
--- a/apps/web/desktop/paths.js
+++ b/apps/web/desktop/paths.js
@@ -1,3 +1,4 @@
module.exports.PATHS = {
backupsDirectory: "documents/Notesnook/backups",
+ logsDirectory: "logs/",
};
diff --git a/apps/web/package.json b/apps/web/package.json
index 1de6d34dc..d3f5fe43c 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -13,7 +13,7 @@
"@rebass/forms": "^4.0.6",
"@streetwritersco/tinymce-plugins": "^1.1.2",
"@tinymce/tinymce-react": "^3.12.6",
- "clipboard": "^2.0.6",
+ "clipboard-polyfill": "^3.0.3",
"cogo-toast": "^4.2.3",
"compressorjs": "^1.0.7",
"currency-symbol-map": "^5.0.1",
diff --git a/apps/web/src/commands/open.js b/apps/web/src/commands/open.js
new file mode 100644
index 000000000..cbbfebfb0
--- /dev/null
+++ b/apps/web/src/commands/open.js
@@ -0,0 +1,5 @@
+import { invokeCommand } from "./index";
+
+export function openPath(path) {
+ invokeCommand("open", { link: path, linkType: "path" });
+}
diff --git a/apps/web/src/commands/openLink.js b/apps/web/src/commands/openLink.js
deleted file mode 100644
index 13054d33a..000000000
--- a/apps/web/src/commands/openLink.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import { isDesktop } from "../utils/platform";
-import { invokeCommand } from "./index";
-
-const windowOpen = window.open.bind(window);
-export default function openLink(link, target = "_blank") {
- if (isDesktop() && target === "_blank") {
- invokeCommand("openLink", { link });
- } else {
- windowOpen(link, target);
- }
-}
diff --git a/apps/web/src/components/dialogs/recovery-key-dialog.js b/apps/web/src/components/dialogs/recovery-key-dialog.js
index 1b1f20fd8..386317440 100644
--- a/apps/web/src/components/dialogs/recovery-key-dialog.js
+++ b/apps/web/src/components/dialogs/recovery-key-dialog.js
@@ -4,7 +4,7 @@ import Dialog from "./dialog";
import { db } from "../../common/db";
import Logo from "../../assets/notesnook-logo.png";
import download from "../../utils/download";
-import ClipboardJS from "clipboard";
+import * as clipboard from "clipboard-polyfill/text";
import { Suspense } from "react";
const QRCode = React.lazy(() => import("../../re-exports/react-qrcode-logo"));
@@ -22,23 +22,6 @@ function RecoveryKeyDialog(props) {
})();
}, []);
- useEffect(() => {
- var clipboard = new ClipboardJS(".copyKey");
- clipboard.on("success", function (e) {
- setCopyText("Copied!");
- setTimeout(() => {
- setCopyText("Copy to clipboard");
- }, 2000);
- e.clearSelection();
- });
- clipboard.on("error", function () {
- console.error("Error while copying text.");
- });
- return () => {
- clipboard?.destroy();
- };
- }, []);
-
return (
<Dialog isOpen={true} title="Backup your recovery key">
<Flex flexDirection="column" flex={1} sx={{ overflow: "hidden" }}>
@@ -78,13 +61,21 @@ function RecoveryKeyDialog(props) {
<Flex flexDirection="column">
<Button
- data-clipboard-text={key}
mt={1}
className="copyKey"
fontSize="body"
onClick={async () => {
- // await copyToClipboard(key);
- // setCopyText("Copied!");
+ clipboard
+ .writeText(key)
+ .then(() => {
+ setCopyText("Copied!");
+ setTimeout(() => {
+ setCopyText("Copy to clipboard");
+ }, 2000);
+ })
+ .catch((e) => {
+ console.error("Error while copying text.", e);
+ });
}}
>
{copyText}
diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.js
index a9369b0ca..108362529 100644
--- a/apps/web/src/components/list-item/index.js
+++ b/apps/web/src/components/list-item/index.js
@@ -7,6 +7,9 @@ import {
} from "../../stores/selection-store";
import { useOpenContextMenu } from "../../utils/useContextMenu";
import { SELECTION_OPTIONS_MAP } from "../../common";
+import Config from "../../utils/config";
+import { db } from "../../common/db";
+import * as clipboard from "clipboard-polyfill/text";
function selectMenuItem(isSelected, toggleSelection) {
return {
@@ -25,6 +28,29 @@ function selectMenuItem(isSelected, toggleSelection) {
};
}
+function debugMenuItems(type) {
+ if (!type) return [];
+ return [
+ {
+ key: "copy-data",
+ title: () => "Copy data",
+ icon: Icon.Copy,
+ onClick: async ({ [type]: item }) => {
+ if (type === "note" && item.contentId) {
+ item.additionalData = {
+ content: db.debug.strip(await db.content.raw(item.contentId)),
+ };
+ }
+ item.additionalData = {
+ ...item.additionalData,
+ lastSynced: await db.lastSynced(),
+ };
+ await clipboard.writeText(db.debug.strip(item));
+ },
+ },
+ ];
+}
+
const ItemSelector = ({ isSelected, toggleSelection }) => {
return isSelected ? (
<Icon.CheckCircle
@@ -103,9 +129,12 @@ function ListItem(props) {
}
if (props.selectable)
items = [selectMenuItem(isSelected, toggleSelection), ...items];
+ if (Config.get("debugMode", false))
+ items = [...items, ...debugMenuItems(props.item.type)];
return items;
}, [
props.menu?.items,
+ props.item.type,
isSelected,
isSelectionMode,
toggleSelection,
diff --git a/apps/web/src/components/publish-view/index.js b/apps/web/src/components/publish-view/index.js
index 86e5ff684..0df560d98 100644
--- a/apps/web/src/components/publish-view/index.js
+++ b/apps/web/src/components/publish-view/index.js
@@ -5,7 +5,7 @@ import * as Icon from "../icons";
import Toggle from "../toggle";
import Field from "../field";
import { db } from "../../common/db";
-import ClipboardJS from "clipboard";
+import * as clipboard from "clipboard-polyfill/text";
import ThemeProvider from "../theme-provider";
import { showToast } from "../../utils/toast";
@@ -22,20 +22,6 @@ function PublishView(props) {
setPublishId(db.monographs.monograph(noteId));
}, [noteId]);
- useEffect(() => {
- var clipboard = new ClipboardJS(".copyPublishLink");
- clipboard.on("success", function (e) {
- e.clearSelection();
- });
- clipboard.on("error", function () {
- console.error("Error while copying text.");
- });
-
- return () => {
- clipboard?.destroy();
- };
- }, []);
-
return (
<Flex
sx={{
@@ -91,9 +77,13 @@ function PublishView(props) {
<Button
variant="anchor"
className="copyPublishLink"
- data-clipboard-text={`https://monograph.notesnook.com/${publishId}`}
+ onClick={() => {
+ clipboard.writeText(
+ `https://monograph.notesnook.com/${publishId}`
+ );
+ }}
>
- <Icon.Copy size={20} color="primary" onClick={() => {}} />
+ <Icon.Copy size={20} color="primary" />
</Button>
</Flex>
)}
diff --git a/apps/web/src/index.js b/apps/web/src/index.js
index 6311fc8a0..ce8f235db 100644
--- a/apps/web/src/index.js
+++ b/apps/web/src/index.js
@@ -3,7 +3,6 @@ import React from "react";
import { initializeDatabase } from "./common/db";
import "./index.css";
import * as serviceWorker from "./serviceWorkerRegistration";
-import "./utils/overrides";
import { loadTrackerScript } from "./utils/analytics";
import Config from "./utils/config";
import { isTesting } from "./utils/platform";
diff --git a/apps/web/src/utils/overrides.js b/apps/web/src/utils/overrides.js
deleted file mode 100644
index 7041105ef..000000000
--- a/apps/web/src/utils/overrides.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import openLink from "../commands/openLink";
-
-window.open = function (url, target) {
- openLink(url, target);
-};
diff --git a/apps/web/src/views/email-confirmed.js b/apps/web/src/views/email-confirmed.js
index 6a519f81a..1af9d0755 100644
--- a/apps/web/src/views/email-confirmed.js
+++ b/apps/web/src/views/email-confirmed.js
@@ -4,7 +4,6 @@ import ThemeProvider from "../components/theme-provider";
import { ANALYTICS_EVENTS, trackEvent } from "../utils/analytics";
import { useQueryParams } from "../navigation";
import * as Icon from "../components/icons";
-import openLink from "../commands/openLink";
function EmailConfirmed() {
const [{ userId }] = useQueryParams();
@@ -130,7 +129,7 @@ function BlogPromoBanner(props) {
hoverColor={account.hoverColor}
title={account.title}
onClick={() => {
- openLink(account.link, "_blank");
+ window.open(account.link, "_blank");
trackEvent(ANALYTICS_EVENTS.socialLink, account.title);
}}
size={30}
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index 56d69fc55..9652cb1bd 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -27,7 +27,6 @@ import { CHECK_IDS } from "notes-core/common";
import { openPaddleDialog } from "../common/checkout";
import Tip from "../components/tip";
import Toggle from "../components/toggle";
-import openLink from "../commands/openLink";
import { isDesktop } from "../utils/platform";
import Vault from "../common/vault";
import { isUserPremium } from "../hooks/use-is-user-premium";
@@ -35,6 +34,7 @@ import { Slider } from "@rebass/forms";
import useZoomFactor from "../hooks/use-zoom-factor";
import debounce from "just-debounce";
import { PATHS } from "@notesnook/desktop/paths";
+import { openPath } from "../commands/open";
function importBackup() {
return new Promise((resolve, reject) => {
@@ -124,6 +124,7 @@ function Settings(props) {
appearance: false,
backup: false,
privacy: false,
+ developer: false,
other: true,
});
const isSystemThemeDark = useSystemTheme();
@@ -152,6 +153,7 @@ function Settings(props) {
"backupReminderOffset",
0
);
+ const [debugMode, setDebugMode] = usePersistentState("debugMode", false);
const [homepage, setHomepage] = usePersistentState("homepage", 0);
const [backupStorageLocation, setBackupStorageLocation] = usePersistentState(
"backupStorageLocation",
@@ -441,7 +443,7 @@ function Settings(props) {
key={"importer"}
variant="list"
onClick={() => {
- openLink("https://importer.notesnook.com/", "_blank");
+ window.open("https://importer.notesnook.com/", "_blank");
}}
>
<Tip
@@ -585,6 +587,39 @@ function Settings(props) {
</Button>
</>
)}
+
+ <Header
+ title="Developer options"
+ isOpen={groups.developer}
+ onClick={() => {
+ setGroups((g) => ({ ...g, developer: !g.developer }));
+ }}
+ />
+ {groups.developer && (
+ <>
+ <Toggle
+ title="Debug mode"
+ onTip="Show debug options on items"
+ offTip="Hide debug options from items"
+ onToggled={() => setDebugMode(!debugMode)}
+ isToggled={debugMode}
+ />
+ {isDesktop() && (
+ <Button
+ variant="list"
+ onClick={() => {
+ openPath(PATHS.logsDirectory);
+ }}
+ >
+ <Tip
+ text="Open logs directory"
+ tip="Show the directory where log files are stored."
+ />
+ </Button>
+ )}
+ </>
+ )}
+
<Header
title="Other"
isOpen={groups.other}
@@ -600,7 +635,7 @@ function Settings(props) {
key={item.title}
variant="list"
onClick={() => {
- openLink(item.link, "_blank");
+ window.open(item.link, "_blank");
}}
>
<Tip text={item.title} tip={item.description} />