mobile: fix session id mismatch causing editor to get stuck.(#3613)

This commit is contained in:
Ammar Ahmed
2023-10-24 09:18:55 +05:00
committed by GitHub
parent 74172dc3fa
commit 75142ff1b2
4 changed files with 20 additions and 30 deletions

View File

@@ -167,7 +167,7 @@ const Editor = React.memo(
globalThis.noToolbar=${noToolbar};
globalThis.noHeader=${noHeader};
`}
injectedJavaScript={`globalThis.sessionId="${editor.sessionId}";`}
useSharedProcessPool={false}
javaScriptEnabled={true}
focusable={true}
onContentProcessDidTerminate={onError}

View File

@@ -113,7 +113,7 @@ typeof globalThis.statusBar !== "undefined" && statusBar.current.set({date:"",sa
};
setSessionId = async (id: string | null) =>
await this.doAsync(`globalThis.sessionId = "${id}"`);
await this.doAsync(`globalThis.sessionId = "${id}";`);
setStatus = async (date: string | undefined, saved: string) =>
await this.doAsync(

View File

@@ -205,7 +205,6 @@ export const useEditorEvents = (
fullscreen,
isPremium,
readonly,
editor.sessionId,
editor.loading,
deviceMode,
tools,
@@ -229,6 +228,8 @@ export const useEditorEvents = (
logger.info("editor handled back event", editorHandledBack);
return;
}
editorState().currentlyEditing = false;
editor.reset();
setTimeout(async () => {
if (deviceMode !== "mobile" && fullscreen) {
if (fullscreen) {
@@ -241,14 +242,10 @@ export const useEditorEvents = (
editorState().movedAway = true;
tabBarRef.current?.goToPage(0);
}
setImmediate(() => {
useEditorStore.getState().setCurrentlyEditingNote(null);
setTimeout(() => {
Navigation.queueRoutesForUpdate();
}, 500);
});
editorState().currentlyEditing = false;
editor.reset();
setTimeout(() => {
Navigation.queueRoutesForUpdate();
}, 500);
}, 1);
}, [editor, deviceMode, fullscreen]);
@@ -344,8 +341,12 @@ export const useEditorEvents = (
});
}
if (editorMessage.type === EventTypes.back) {
return onBackPress();
}
if (
editorMessage.sessionId !== editor.sessionId &&
editorMessage.sessionId !== editor.sessionId.current &&
editorMessage.type !== EditorEvents.status
) {
return;
@@ -431,9 +432,6 @@ export const useEditorEvents = (
editorState().isFullscreen = true;
eSendEvent(eOpenFullscreenEditor);
break;
case EventTypes.back:
onBackPress();
break;
case EventTypes.link:
openLinkInBrowser(editorMessage.value as string);
break;

View File

@@ -63,8 +63,7 @@ export const useEditor = (
const theme = useThemeEngineStore((state) => state.theme);
const [loading, setLoading] = useState(false);
const [sessionId, setSessionId] = useState<string>(makeSessionId());
const sessionIdRef = useRef(sessionId);
const sessionIdRef = useRef(makeSessionId());
const editorRef = useRef<WebView>(null);
const currentNote = useRef<NoteType | null>();
const currentContent = useRef<Content | null>();
@@ -99,10 +98,6 @@ export const useEditor = (
postMessage(EditorEvents.theme, theme);
}, [theme, postMessage]);
useEffect(() => {
sessionIdRef.current = sessionId;
}, [sessionId]);
useEffect(() => {
commands.setTags(currentNote.current);
}, [commands, tags]);
@@ -142,6 +137,7 @@ export const useEditor = (
clearTimeout(timers.current["loading-images"]);
sessionHistoryId.current = undefined;
saveCount.current = 0;
loadingState.current = undefined;
lock.current = false;
useEditorStore.getState().setReadonly(false);
resetContent && postMessage(EditorEvents.title, "");
@@ -151,8 +147,8 @@ export const useEditor = (
if (resetState) {
const newSessionId = makeSessionId();
sessionIdRef.current = newSessionId;
await commands.setSessionId(newSessionId);
setSessionId(newSessionId);
isDefaultEditor &&
useEditorStore.getState().setCurrentlyEditingNote(null);
@@ -363,7 +359,6 @@ export const useEditor = (
if (item && item.type === "new") {
currentNote.current && (await reset());
const nextSessionId = makeSessionId(item as NoteType);
setSessionId(nextSessionId);
sessionIdRef.current = nextSessionId;
sessionHistoryId.current = Date.now();
await commands.setSessionId(nextSessionId);
@@ -405,12 +400,10 @@ export const useEditor = (
}
lastContentChangeTime.current = item.dateEdited;
const nextSessionId = makeSessionId(item as NoteType);
sessionIdRef.current = nextSessionId;
lockedSessionId.current = nextSessionId;
sessionHistoryId.current = Date.now();
setSessionId(nextSessionId);
commands.setSessionId(nextSessionId);
sessionIdRef.current = nextSessionId;
await commands.setSessionId(nextSessionId);
currentNote.current = item as NoteType;
await commands.setStatus(getFormattedDate(item.dateEdited), "Saved");
await postMessage(EditorEvents.title, item.title);
@@ -638,7 +631,7 @@ export const useEditor = (
useEffect(() => {
state.current.saveCount = 0;
}, [sessionId, loading]);
}, [loading]);
const onReady = useCallback(async () => {
if (!(await isEditorLoaded(editorRef, sessionIdRef.current))) {
@@ -690,8 +683,7 @@ export const useEditor = (
loading,
setLoading,
state,
sessionId,
setSessionId,
sessionId: sessionIdRef,
note: currentNote,
onReady,
saveContent,