From aaaf27af6eb0523e479faad813b04a106de24a8f Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Fri, 24 May 2019 17:34:18 +0100 Subject: [PATCH] Android: Fixed resource loading issue, and improved logging on desktop --- ElectronClient/app/gui/NoteText.jsx | 4 + ElectronClient/app/gui/note-viewer/index.html | 527 +++++++++--------- ReactNativeClient/lib/MdToHtml/utils.js | 7 +- ReactNativeClient/lib/MdToHtml/webviewLib.js | 18 + .../lib/components/note-body-viewer.js | 4 +- 5 files changed, 297 insertions(+), 263 deletions(-) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index cdda76c55..3a2f3cf71 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -671,6 +671,10 @@ class NoteTextComponent extends React.Component { const newBody = shared.toggleCheckbox(msg, this.state.note.body); this.saveOneProperty('body', newBody); + } else if (msg.indexOf('error:') === 0) { + const s = msg.split(':'); + s.splice(0, 1); + reg.logger().error(s.join(':')); } else if (msg === 'setMarkerCount') { const ls = Object.assign({}, this.state.localSearch); ls.resultCount = arg0; diff --git a/ElectronClient/app/gui/note-viewer/index.html b/ElectronClient/app/gui/note-viewer/index.html index b9d25593f..597ddeda3 100644 --- a/ElectronClient/app/gui/note-viewer/index.html +++ b/ElectronClient/app/gui/note-viewer/index.html @@ -38,281 +38,286 @@ diff --git a/ReactNativeClient/lib/MdToHtml/utils.js b/ReactNativeClient/lib/MdToHtml/utils.js index ccc391f78..d830ba6bb 100644 --- a/ReactNativeClient/lib/MdToHtml/utils.js +++ b/ReactNativeClient/lib/MdToHtml/utils.js @@ -46,7 +46,12 @@ utils.errorImage = function() { } utils.loaderImage = function() { - return ''; + // https://github.com/ForkAwesome/Fork-Awesome/blob/master/src/icons/svg/hourglass-half.svg + return ` + + + + `; } utils.resourceStatusImage = function(state) { diff --git a/ReactNativeClient/lib/MdToHtml/webviewLib.js b/ReactNativeClient/lib/MdToHtml/webviewLib.js index 44792a687..29b645d7d 100644 --- a/ReactNativeClient/lib/MdToHtml/webviewLib.js +++ b/ReactNativeClient/lib/MdToHtml/webviewLib.js @@ -63,6 +63,24 @@ webviewLib.getParentAnchorElement = function(element) { } } +webviewLib.cloneError = function(error) { + return { + message: error.message, + stack: error.stack + }; +} + +webviewLib.logEnabledEventHandler = function(fn) { + return function(event) { + try { + return fn(event); + } catch (error) { + webviewLib.options_.postMessage('error:' + JSON.stringify(webviewLib.cloneError(error))); + throw error; + } + } +} + webviewLib.initialize = function(options) { webviewLib.options_ = options; } diff --git a/ReactNativeClient/lib/components/note-body-viewer.js b/ReactNativeClient/lib/components/note-body-viewer.js index 8b90a30c7..fa701806d 100644 --- a/ReactNativeClient/lib/components/note-body-viewer.js +++ b/ReactNativeClient/lib/components/note-body-viewer.js @@ -108,7 +108,7 @@ class NoteBodyViewer extends Component { const injectedJs = [this.mdToHtml_.injectedJavaScript()]; injectedJs.push(shim.injectedJs('webviewLib')); - injectedJs.push('webviewLib.initialize({ postMessage: postMessage });'); + injectedJs.push('webviewLib.initialize({ postMessage: msg => { return postMessage(msg); } });'); injectedJs.push(` const readyStateCheckInterval = setInterval(function() { if (document.readyState === "complete") { @@ -177,6 +177,8 @@ class NoteBodyViewer extends Component { onMessage={(event) => { let msg = event.nativeEvent.data; + console.info('Got IPC message: ', msg); + if (msg.indexOf('checkboxclick:') === 0) { const newBody = shared.toggleCheckbox(msg, this.props.note.body); if (this.props.onCheckboxChange) this.props.onCheckboxChange(newBody);