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
fix sometimes content of note is not loaded.
ammarahm-edb7e3879396e7
diff --git a/apps/mobile/android/app/src/main/assets/index.html b/apps/mobile/android/app/src/main/assets/index.htmlindex a33efa6b6..fe9ccfcd3 100644--- a/apps/mobile/android/app/src/main/assets/index.html+++ b/apps/mobile/android/app/src/main/assets/index.html@@ -38,6 +38,7 @@<script src="./constants.js"></script><script src="./init.js"></script><script>+ attachMessageListener();init_tiny("calc(100vh - 55px)");</script>diff --git a/apps/mobile/android/app/src/main/assets/listeners.js b/apps/mobile/android/app/src/main/assets/listeners.jsindex ec55a3d5c..4578b850e 100644--- a/apps/mobile/android/app/src/main/assets/listeners.js+++ b/apps/mobile/android/app/src/main/assets/listeners.js@@ -32,7 +32,7 @@ function attachTitleInputListeners() {if (tinymce.activeEditor) {tinymce.activeEditor && tinymce.activeEditor.focus();}-+onTitleChange();};@@ -42,24 +42,24 @@ function attachTitleInputListeners() {if (tinymce.activeEditor) {tinymce.activeEditor && tinymce.activeEditor.focus();}-onTitleChange();return false;}};- document.getElementById('titleInput').addEventListener('focus', function (evt) {- if (window.ReactNativeWebView) {- window.ReactNativeWebView.postMessage(- JSON.stringify({- type: 'focus',- value: 'title',- }),- );- }- });-+ document+ .getElementById('titleInput')+ .addEventListener('focus', function (evt) {+ if (window.ReactNativeWebView) {+ window.ReactNativeWebView.postMessage(+ JSON.stringify({+ type: 'focus',+ value: 'title',+ }),+ );+ }+ });document.getElementById('titleInput').onchange = function (evt) {autosize();@@ -70,6 +70,7 @@ function attachTitleInputListeners() {}function onTitleChange(ele) {+ autosize();if (isLoading) {return;}@@ -84,7 +85,6 @@ function onTitleChange(ele) {tinymce.activeEditor.plugins.wordcount.getCount() + ' words';}- autosize();if (titleMessage && typeof titleMessage.value === 'string') {if (window.ReactNativeWebView) {window.ReactNativeWebView?.postMessage(JSON.stringify(titleMessage));@@ -94,7 +94,9 @@ function onTitleChange(ele) {function autosize() {let ele = document.getElementById('textCopy');- ele.innerHTML = document.getElementById('titleInput').value.replace(/\n/g, '<br/>');+ ele.innerHTML = document+ .getElementById('titleInput')+ .value.replace(/\n/g, '<br/>');let newHeight = document.getElementById('titlebar').scrollHeight;let css = document.createElement('style');css.type = 'text/css';@@ -106,3 +108,36 @@ function autosize() {css.appendChild(document.createTextNode(node));document.getElementsByTagName('head')[0].appendChild(css);}++function attachMessageListener() {+ document.addEventListener('message', (data) => {+ let message = JSON.parse(data.data);+ let type = message.type;+ let value = message.value;++ switch (type) {+ case 'html':+ isLoading = true;+ tinymce.activeEditor.mode.set('readonly');+ tinymce.activeEditor.setContent(value);+ setTimeout(() => {+ document.activeElement.blur();+ window.blur();+ tinymce.activeEditor.mode.set('design');+ document.activeElement.blur();+ window.blur();+ }, 300);+ info.querySelector('#infowords').innerText =+ tinymce.activeEditor.plugins.wordcount.getCount() + ' words';+ break;+ case 'title':+ document.getElementById('titleInput').value = value;+ setTimeout(() => {+ autosize();+ }, 100);+ break;+ default:+ break;+ }+ });+}diff --git a/apps/mobile/android/app/src/main/assets/plaineditor.html b/apps/mobile/android/app/src/main/assets/plaineditor.htmlindex c85e906ff..500ec4ed4 100644--- a/apps/mobile/android/app/src/main/assets/plaineditor.html+++ b/apps/mobile/android/app/src/main/assets/plaineditor.html@@ -20,6 +20,7 @@<script src="./constants.js"></script><script src="./init.js"></script><script>+ attachMessageListener();init_tiny("100vh");</script>diff --git a/apps/mobile/html/Web.bundle/site/index.html b/apps/mobile/html/Web.bundle/site/index.htmlindex 811f607c4..dbea89afb 100644--- a/apps/mobile/html/Web.bundle/site/index.html+++ b/apps/mobile/html/Web.bundle/site/index.html@@ -1,5 +1,6 @@<!DOCTYPE html><html>+<head><meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1.0"><meta charset="utf-8" />@@ -8,7 +9,7 @@</head><body>- <div class="app-main" >+ <div class="app-main"><input id="image-input" accept='image/png, image/gif, image/jpeg, image/bmp, image/x-icon' type="file"name="name" style="display: none;" /><div id="titlebar">@@ -28,9 +29,9 @@<textarea hidden id="tiny_textarea"></textarea></div><script>- let editor = null;- let isLoading = true;- let regex = /\n/gm;+ let editor = null;+ let isLoading = true;+ let regex = /\n/gm;</script><script src="./compressor.min.js"></script><script src="./listeners.js"></script>@@ -38,7 +39,8 @@<script src="./constants.js"></script><script src="./init.js"></script><script>-++attachMessageListener()init_tiny("calc(100vh - 55px)");</script>diff --git a/apps/mobile/html/Web.bundle/site/listeners.js b/apps/mobile/html/Web.bundle/site/listeners.jsindex ec55a3d5c..fbca7b2ac 100644--- a/apps/mobile/html/Web.bundle/site/listeners.js+++ b/apps/mobile/html/Web.bundle/site/listeners.js@@ -32,34 +32,35 @@ function attachTitleInputListeners() {if (tinymce.activeEditor) {tinymce.activeEditor && tinymce.activeEditor.focus();}-+onTitleChange();};document.getElementById('titleInput').onkeypress = function (evt) {+ autosize();if (evt.keyCode === 13 || evt.which === 13) {evt.preventDefault();if (tinymce.activeEditor) {tinymce.activeEditor && tinymce.activeEditor.focus();}-onTitleChange();return false;}};- document.getElementById('titleInput').addEventListener('focus', function (evt) {- if (window.ReactNativeWebView) {- window.ReactNativeWebView.postMessage(- JSON.stringify({- type: 'focus',- value: 'title',- }),- );- }- });-+ document+ .getElementById('titleInput')+ .addEventListener('focus', function (evt) {+ if (window.ReactNativeWebView) {+ window.ReactNativeWebView.postMessage(+ JSON.stringify({+ type: 'focus',+ value: 'title',+ }),+ );+ }+ });document.getElementById('titleInput').onchange = function (evt) {autosize();@@ -70,6 +71,7 @@ function attachTitleInputListeners() {}function onTitleChange(ele) {+ autosize();if (isLoading) {return;}@@ -84,7 +86,6 @@ function onTitleChange(ele) {tinymce.activeEditor.plugins.wordcount.getCount() + ' words';}- autosize();if (titleMessage && typeof titleMessage.value === 'string') {if (window.ReactNativeWebView) {window.ReactNativeWebView?.postMessage(JSON.stringify(titleMessage));@@ -94,7 +95,9 @@ function onTitleChange(ele) {function autosize() {let ele = document.getElementById('textCopy');- ele.innerHTML = document.getElementById('titleInput').value.replace(/\n/g, '<br/>');+ ele.innerHTML = document+ .getElementById('titleInput')+ .value.replace(/\n/g, '<br/>');let newHeight = document.getElementById('titlebar').scrollHeight;let css = document.createElement('style');css.type = 'text/css';@@ -106,3 +109,35 @@ function autosize() {css.appendChild(document.createTextNode(node));document.getElementsByTagName('head')[0].appendChild(css);}++function attachMessageListener() {+ window.addEventListener('message', (data) => {+ let message = JSON.parse(data.data);+ let type = message.type;+ let value = message.value;++ switch (type) {+ case 'html':+ isLoading = true;+ tinymce.activeEditor.mode.set('readonly');+ tinymce.activeEditor.setContent(value);+ setTimeout(() => {+ document.activeElement.blur();+ window.blur();+ tinymce.activeEditor.mode.set('design');+ document.activeElement.blur();+ window.blur();+ }, 300);+ info.querySelector('#infowords').innerText =+ tinymce.activeEditor.plugins.wordcount.getCount() + ' words';+ break;+ case 'title':+ document.getElementById('titleInput').value = value;+ setTimeout(() => {+ autosize();+ }, 100);+ default:+ break;+ }+ });+}diff --git a/apps/mobile/html/Web.bundle/site/plaineditor.html b/apps/mobile/html/Web.bundle/site/plaineditor.htmlindex c85e906ff..3a955c19f 100644--- a/apps/mobile/html/Web.bundle/site/plaineditor.html+++ b/apps/mobile/html/Web.bundle/site/plaineditor.html@@ -20,6 +20,7 @@<script src="./constants.js"></script><script src="./init.js"></script><script>+ attachMessageListener()init_tiny("100vh");</script>diff --git a/apps/mobile/src/components/MergeEditor/index.js b/apps/mobile/src/components/MergeEditor/index.jsindex 0560b1f95..ee07e2b57 100644--- a/apps/mobile/src/components/MergeEditor/index.js+++ b/apps/mobile/src/components/MergeEditor/index.js@@ -105,13 +105,14 @@ const MergeEditor = () => {const insets = useSafeAreaInsets();const onPrimaryWebViewLoad = () => {+ console.log(primaryData.data.length, secondaryData.data.length);let htmlDiff = {before: primaryData.data,};if (secondaryData.data) {htmlDiff = diff.diff_dual_pane(primaryData.data, secondaryData.data);}- tiny.call(primaryWebView, tiny.html(htmlDiff.before), true);+ postMessage(primaryWebView, 'html', htmlDiff.before);let theme = {...colors};theme.factor = normalize(1);tiny.call(primaryWebView, tiny.updateTheme(JSON.stringify(theme)), true);@@ -124,12 +125,21 @@ const MergeEditor = () => {if (secondaryData.data) {htmlDiff = diff.diff_dual_pane(primaryData.data, secondaryData.data);}- tiny.call(secondaryWebView, tiny.html(htmlDiff.after), true);+ postMessage(secondaryWebView, 'html', htmlDiff.after);let theme = {...colors};theme.factor = normalize(1);tiny.call(secondaryWebView, tiny.updateTheme(JSON.stringify(theme)), true);};+ function postMessage(webview, type, value = null) {+ let message = {+ type,+ value,+ };+ console.log(message,webview.current);+ webview.current?.postMessage(JSON.stringify(message));+ }+const _onShouldStartLoadWithRequest = (request) => {if (request.url.includes('http')) {openLinkInBrowser(request.url, colors)diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex 099de0bd5..ac2ab45ea 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -131,6 +131,8 @@ const EditorHeader = () => {}}top={50}onPress={async () => {+ EditorWebView.current?.postMessage("hello world");+ return;await loadNote({type: 'new'});}}/>diff --git a/apps/mobile/src/views/Editor/EditorTitle.js b/apps/mobile/src/views/Editor/EditorTitle.jsindex 4e6f30058..3a8127931 100644--- a/apps/mobile/src/views/Editor/EditorTitle.js+++ b/apps/mobile/src/views/Editor/EditorTitle.js@@ -71,7 +71,7 @@ export const EditorTitle = () => {placeholder="Note title"onChangeText={(text) => {setTitle(text);- tiny.call(EditorWebView,tiny.setTitle(text));+ post("title",text)_onMessage({nativeEvent: {data: JSON.stringify({diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex 424ea5efd..9cc08d157 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -118,9 +118,8 @@ export function post(type, value = null) {}export const _onShouldStartLoadWithRequest = async (request) => {-if (request.url.includes('https')) {- if (Platform.OS === "ios" && !request.isTopFrame) return;+ if (Platform.OS === 'ios' && !request.isTopFrame) return;openLinkInBrowser(request.url, appColors).catch((e) => {}).then((r) => {});@@ -129,7 +128,6 @@ export const _onShouldStartLoadWithRequest = async (request) => {} else {return true;}-};export function checkNote() {@@ -494,7 +492,7 @@ const loadNoteInEditor = async () => {if (!webviewInit) return;saveCounter = 0;if (note?.id) {- tiny.call(EditorWebView, tiny.setTitle(title));+ post('title', title);intent = false;if (!content || !content.data || content?.data?.length === 0) {@@ -510,7 +508,7 @@ const loadNoteInEditor = async () => {`,);} else {- tiny.call(EditorWebView, tiny.html(content.data));+ post('html', content.data);}setColors();diff --git a/apps/mobile/src/views/Editor/tiny/tiny.js b/apps/mobile/src/views/Editor/tiny/tiny.jsindex a783e7980..93dd24d74 100644--- a/apps/mobile/src/views/Editor/tiny/tiny.js+++ b/apps/mobile/src/views/Editor/tiny/tiny.js@@ -1,5 +1,5 @@import {editing} from '../../../utils';-import {EditorWebView, getWebviewInit} from '../Functions';+import {EditorWebView, getWebviewInit, post} from '../Functions';const reset = `isLoading = true;@@ -104,21 +104,7 @@ const notLoading = `isLoading = false;`;-const html = (value) => `-isLoading = true;-tinymce.activeEditor.mode.set("readonly")-tinymce.activeEditor.setContent(\`${value}\`);-setTimeout(() => {- document.activeElement.blur();- window.blur();- tinymce.activeEditor.mode.set("design")- document.activeElement.blur();- window.blur();--},300)-info.querySelector('#infowords').innerText =-tinymce.activeEditor.plugins.wordcount.getCount() + " words";-`;+const html = (value) => post('html', value);const focusEditor = `tinymce.activeEditor.focus();