Skip to content

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

fix readonly mode

Ammar Ahmed67a8e5ddd2fd
diff --git a/apps/mobile/.gitignore b/apps/mobile/.gitignore
index a210b970c..832ca3a05 100644
--- a/apps/mobile/.gitignore
+++ b/apps/mobile/.gitignore
@@ -32,6 +32,7 @@ build/
.gradle
local.properties
*.iml
+web.bundle
# node.js
#
diff --git a/apps/mobile/android/app/src/main/assets/.gitignore b/apps/mobile/android/app/src/main/assets/.gitignore
index bfc4ab10e..510022b0f 100644
--- a/apps/mobile/android/app/src/main/assets/.gitignore
+++ b/apps/mobile/android/app/src/main/assets/.gitignore
@@ -1,7 +1,2 @@
-# exclude all files
-*
-# except index.css
-!index.css
-!*.ttf
-!fonts
-!.gitignore
\ No newline at end of file
+!fonts/*
+*
\ No newline at end of file
diff --git a/apps/mobile/index.js b/apps/mobile/index.js
index 81c82bb73..c449c3715 100644
--- a/apps/mobile/index.js
+++ b/apps/mobile/index.js
@@ -9,7 +9,7 @@ import { enableScreens } from 'react-native-screens';
import { name as appName } from './app.json';
import Notifications from './src/services/notifications';
import './src/utils/logger/index';
-
+console.log(`V8 version is ${global._v8runtime().version}`);
global.Buffer = require('buffer').Buffer;
enableLayoutAnimations(true);
diff --git a/apps/mobile/src/components/launcher/index.js b/apps/mobile/src/components/launcher/index.js
index 434704a6f..d2ff7e801 100644
--- a/apps/mobile/src/components/launcher/index.js
+++ b/apps/mobile/src/components/launcher/index.js
@@ -1,9 +1,8 @@
import React, { useEffect, useRef, useState } from 'react';
-import { NativeModules, Platform, StatusBar, View } from 'react-native';
+import { Platform, View } from 'react-native';
import RNBootSplash from 'react-native-bootsplash';
import { checkVersion } from 'react-native-check-version';
import { editorState } from '../../screens/editor/tiptap/utils';
-import SettingsBackupAndRestore from '../../screens/settings/backup-restore';
import BackupService from '../../services/backup';
import BiometricService from '../../services/biometrics';
import { DDS } from '../../services/device-detection';
@@ -12,7 +11,6 @@ import { setRateAppMessage } from '../../services/message';
import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
import { initialize } from '../../stores';
-import { useFavoriteStore } from '../../stores/use-favorite-store';
import { useMessageStore } from '../../stores/use-message-store';
import { useNoteStore } from '../../stores/use-notes-store';
import { useSettingStore } from '../../stores/use-setting-store';
@@ -40,8 +38,6 @@ import { Walkthrough } from '../walkthroughs';
const Launcher = React.memo(
() => {
const colors = useThemeStore(state => state.colors);
- const setNotes = useNoteStore(state => state.setNotes);
- const setFavorites = useFavoriteStore(state => state.setFavorites);
const setLoading = useNoteStore(state => state.setLoading);
const loading = useNoteStore(state => state.loading);
const user = useUserStore(state => state.user);
diff --git a/apps/mobile/src/components/mergeconflicts/index.js b/apps/mobile/src/components/mergeconflicts/index.js
index 2ac5c5fff..a7ed64db4 100644
--- a/apps/mobile/src/components/mergeconflicts/index.js
+++ b/apps/mobile/src/components/mergeconflicts/index.js
@@ -24,8 +24,6 @@ import { IconButton } from '../ui/icon-button';
import Seperator from '../ui/seperator';
import Paragraph from '../ui/typography/paragraph';
-const sourceUri = '';
-
const MergeConflicts = () => {
const colors = useThemeStore(state => state.colors);
const [visible, setVisible] = useState(false);
diff --git a/apps/mobile/src/components/ui/iconbutton/index.tsx b/apps/mobile/src/components/ui/iconbutton/index.tsx
index d6f8983f3..2eb075c44 100644
--- a/apps/mobile/src/components/ui/iconbutton/index.tsx
+++ b/apps/mobile/src/components/ui/iconbutton/index.tsx
@@ -18,7 +18,7 @@ import { PressableButton, PressableButtonProps } from '../pressable';
interface IconButtonProps extends PressableButtonProps {
name: string;
color?: ColorValue;
- size: number;
+ size?: number;
left?: number;
right?: number;
top?: number;
diff --git a/apps/mobile/src/screens/editor/index.tsx b/apps/mobile/src/screens/editor/index.tsx
index 20bd0398c..52cb71419 100755
--- a/apps/mobile/src/screens/editor/index.tsx
+++ b/apps/mobile/src/screens/editor/index.tsx
@@ -4,15 +4,18 @@ import { Linking, ViewStyle } from 'react-native';
import WebView from 'react-native-webview';
import { ShouldStartLoadRequest } from 'react-native-webview/lib/WebViewTypes';
import { notesnook } from '../../../e2e/test.ids';
+import { IconButton } from '../../components/ui/icon-button';
+import { useEditorStore } from '../../stores/use-editor-store';
+import { getElevation } from '../../utils';
+import { db } from '../../utils/database';
+import { NoteType } from '../../utils/types';
import EditorOverlay from './loading';
-import { EditorProps } from './tiptap/types';
+import { EDITOR_URI } from './source';
+import { EditorProps, useEditorType } from './tiptap/types';
import { useEditor } from './tiptap/use-editor';
import { useEditorEvents } from './tiptap/use-editor-events';
import { editorController } from './tiptap/utils';
-const sourceUri = '';
-const source = { uri: sourceUri + 'index.html' };
-
const style: ViewStyle = {
height: '100%',
maxHeight: '100%',
@@ -111,13 +114,14 @@ const Editor = React.memo(
allowUniversalAccessFromFileURLs={true}
originWhitelist={['*']}
source={{
- uri: 'http://localhost:3000'
+ uri: __DEV__ ? 'http://localhost:3000' : EDITOR_URI
}}
style={style}
autoManageStatusBarEnabled={false}
onMessage={onMessage || undefined}
/>
<EditorOverlay editorId={editorId || ''} editor={editor} />
+ <ReadonlyButton editor={editor} />
</>
);
},
@@ -126,4 +130,32 @@ const Editor = React.memo(
export default Editor;
+const ReadonlyButton = ({ editor }: { editor: useEditorType }) => {
+ const readonly = useEditorStore(state => state.readonly);
+
+ const onPress = async () => {
+ if (editor.note.current) {
+ await db.notes?.note(editor.note.current.id).readonly();
+ editor.note.current = db.notes?.note(editor.note.current.id).data as NoteType;
+ useEditorStore.getState().setReadonly(false);
+ }
+ };
+ return readonly ? (
+ <IconButton
+ name="pencil-lock"
+ type="grayBg"
+ onPress={onPress}
+ color="accent"
+ customStyle={{
+ position: 'absolute',
+ bottom: 20,
+ width: 60,
+ height: 60,
+ right: 12,
+ ...getElevation(5)
+ }}
+ />
+ ) : null;
+};
+
// test uri "http://192.168.10.8:3000/index.html"
diff --git a/apps/mobile/src/screens/editor/source.ts b/apps/mobile/src/screens/editor/source.ts
new file mode 100644
index 000000000..86d8532c7
--- /dev/null
+++ b/apps/mobile/src/screens/editor/source.ts
@@ -0,0 +1,4 @@
+import { Platform } from 'react-native';
+
+export const EDITOR_URI =
+ Platform.OS === 'android' ? 'file:///android_asset/index.html' : 'web.bundle/index.html';
diff --git a/apps/mobile/src/screens/editor/tiptap/commands.ts b/apps/mobile/src/screens/editor/tiptap/commands.ts
index 2498ccaf3..ece7e4116 100644
--- a/apps/mobile/src/screens/editor/tiptap/commands.ts
+++ b/apps/mobile/src/screens/editor/tiptap/commands.ts
@@ -1,15 +1,17 @@
-import { createRef, MutableRefObject, RefObject } from 'react';
+import {
+ Attachment,
+ AttachmentProgress
+} from 'notesnook-editor/dist/cjs/extensions/attachment/index';
+import { ImageAttributes } from 'notesnook-editor/dist/cjs/extensions/image/index';
+import { createRef, RefObject } from 'react';
import { Platform } from 'react-native';
import { EdgeInsets } from 'react-native-safe-area-context';
import WebView from 'react-native-webview';
import { db } from '../../../utils/database';
import { sleep } from '../../../utils/time';
-import { Note, Settings } from './types';
-import { getResponse, randId, textInput } from './utils';
-import { Attachment, AttachmentProgress } from 'notesnook-editor/dist/extensions/attachment/index';
-import { ImageAttributes } from 'notesnook-editor/dist/extensions/image/index';
import { NoteType } from '../../../utils/types';
-import { sanitizeFilename } from '../../../utils/sanitizer';
+import { Settings } from './types';
+import { getResponse, randId, textInput } from './utils';
type Action = { job: string; id: string };
@@ -33,7 +35,8 @@ const fn = (fn: string) => {
${fn}
post("${id}",response);
} catch(e) {
- logger('error', "webview: ", e.message, e.stack);
+ const DEV_MODE = ${__DEV__};
+ if (DEV_MODE) logger('error', "webview: ", e.message, e.stack);
}
})();`,
id: id
diff --git a/apps/mobile/src/screens/editor/tiptap/useEditor.ts b/apps/mobile/src/screens/editor/tiptap/useEditor.ts
index 4567b4927..839f5353f 100644
--- a/apps/mobile/src/screens/editor/tiptap/useEditor.ts
+++ b/apps/mobile/src/screens/editor/tiptap/useEditor.ts
@@ -112,6 +112,7 @@ export const useEditor = (editorId = '', readonly?: boolean) => {
currentContent.current = null;
sessionHistoryId.current = undefined;
saveCount.current = 0;
+ useEditorStore.getState().setReadonly(false);
await commands.clearContent();
console.log('reset state: ', resetState);
if (resetState) {
@@ -130,8 +131,9 @@ export const useEditor = (editorId = '', readonly?: boolean) => {
sessionId: currentSessionId,
sessionHistoryId: currentSessionHistoryId
}: SavePayload) => {
+ if (readonly || useEditorStore.getState().readonly || currentNote.current?.readonly) return;
+
console.log('saving note', id);
- if (readonly) return;
try {
if (id && !db.notes?.note(id)) {
isDefaultEditor && useEditorStore.getState().setCurrentlyEditingNote(null);
@@ -183,7 +185,9 @@ export const useEditor = (editorId = '', readonly?: boolean) => {
//@ts-ignore
await db.vault?.save(noteData);
}
+ console.log(id, sessionIdRef.current, currentSessionId);
if (id && sessionIdRef.current === currentSessionId) {
+ console.log('updating state');
note = db.notes?.note(id)?.data as Note;
await commands.setStatus(timeConverter(note.dateEdited), 'Saved');
@@ -228,9 +232,11 @@ export const useEditor = (editorId = '', readonly?: boolean) => {
currentNote.current && (await reset());
let nextSessionId = makeSessionId(item);
setSessionId(nextSessionId);
+ sessionIdRef.current = nextSessionId;
sessionHistoryId.current = Date.now();
await commands.setSessionId(nextSessionId);
await commands.focus();
+ useEditorStore.getState().setReadonly(false);
} else {
//@ts-ignore todo
if (!item.forced && currentNote.current?.id === item.id) return;
@@ -241,11 +247,13 @@ export const useEditor = (editorId = '', readonly?: boolean) => {
let nextSessionId = makeSessionId(item);
sessionHistoryId.current = Date.now();
setSessionId(nextSessionId);
+ sessionIdRef.current = nextSessionId;
await commands.setSessionId(nextSessionId);
currentNote.current = item;
await commands.setStatus(timeConverter(item.dateEdited), 'Saved');
await postMessage(EditorEvents.title, item.title);
await postMessage(EditorEvents.html, currentContent.current?.data);
+ useEditorStore.getState().setReadonly(item.readonly);
loadImages();
await commands.setTags(currentNote.current);
overlay(false);
@@ -297,7 +305,7 @@ export const useEditor = (editorId = '', readonly?: boolean) => {
500
);
},
- []
+ [sessionIdRef, sessionId]
);
const onLoad = useCallback(async () => {
diff --git a/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts b/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
index b34e5b66a..72cddcebe 100644
--- a/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
+++ b/apps/mobile/src/screens/editor/tiptap/useEditorEvents.ts
@@ -113,7 +113,10 @@ const showActionsheet = async (editor: useEditorType) => {
}
};
-export const useEditorEvents = (editor: useEditorType, editorProps: Partial<EditorProps>) => {
+export const useEditorEvents = (
+ editor: useEditorType,
+ { readonly: editorPropReadonly, noHeader, noToolbar }: Partial<EditorProps>
+) => {
const deviceMode = useSettingStore(state => state.deviceMode);
const fullscreen = useSettingStore(state => state.fullscreen);
const handleBack = useRef<NativeEventSubscription>();
@@ -123,22 +126,24 @@ export const useEditorEvents = (editor: useEditorType, editorProps: Partial<Edit
if (!editor) return null;
useEffect(() => {
+ console.log('settings', readonly);
editor.commands.setSettings({
deviceMode: deviceMode || 'mobile',
fullscreen: fullscreen,
premium: isPremium,
- readonly: readonly,
+ readonly: readonly || editorPropReadonly,
tools: tools,
- ...editorProps
+ noHeader: noHeader,
+ noToolbar: readonly || editorPropReadonly || noToolbar
});
}, [fullscreen, isPremium, readonly, editor.sessionId, editor.loading, tools]);
const onBackPress = useCallback(async () => {
const editorHandledBack = await editor.commands.handleBack();
- // if (!editorHandledBack) {
- // logger.info('editor handled back event', editorHandledBack);
- // return;
- // }
+ if (!editorHandledBack) {
+ logger.info('editor handled back event', editorHandledBack);
+ return;
+ }
setTimeout(async () => {
if (deviceMode !== 'mobile' && fullscreen) {
if (fullscreen) {
@@ -312,7 +317,7 @@ export const useEditorEvents = (editor: useEditorType, editorProps: Partial<Edit
}
eSendEvent(editorMessage.type, editorMessage);
},
- [editor.sessionId]
+ [editor.sessionId, editor.saveContent]
);
return onMessage;
diff --git a/apps/mobile/src/screens/settings/editor/toolbardefinition.ts b/apps/mobile/src/screens/settings/editor/toolbardefinition.ts
index 2fa3c8ae1..cb12e112d 100644
--- a/apps/mobile/src/screens/settings/editor/toolbardefinition.ts
+++ b/apps/mobile/src/screens/settings/editor/toolbardefinition.ts
@@ -1,7 +1,7 @@
-import { Icons } from 'notesnook-editor/dist/toolbar/icons';
-import { DEFAULT_TOOLS, getAllTools } from 'notesnook-editor/dist/toolbar/tooldefinitions';
-import { ToolId } from 'notesnook-editor/dist/toolbar/tools';
-import { ToolbarGroupDefinition } from 'notesnook-editor/dist/toolbar/types';
+import { Icons } from 'notesnook-editor/dist/es/toolbar/icons';
+import { DEFAULT_TOOLS, getAllTools } from 'notesnook-editor/dist/es/toolbar/tooldefinitions';
+import { ToolId } from 'notesnook-editor/dist/es/toolbar/tools';
+import { ToolbarGroupDefinition } from 'notesnook-editor/dist/es/toolbar/index';
import { useThemeStore } from '../../../stores/use-theme-store';
export const tools = getAllTools();
diff --git a/apps/mobile/version.js b/apps/mobile/version.js
index 656376f4b..9eac73a53 100644
--- a/apps/mobile/version.js
+++ b/apps/mobile/version.js
@@ -1 +1 @@
-export const APP_VERSION=1809;
\ No newline at end of file
+export const APP_VERSION = 1810;