diff --git a/src/components/App.vue b/src/components/App.vue index d1f0d4e5..9fbd4132 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -18,6 +18,7 @@ import SplashScreen from './SplashScreen'; import syncSvc from '../services/syncSvc'; import networkSvc from '../services/networkSvc'; import sponsorSvc from '../services/sponsorSvc'; +import tempFileSvc from '../services/tempFileSvc'; import timeSvc from '../services/timeSvc'; import store from '../store'; @@ -94,6 +95,7 @@ export default { networkSvc.init(); sponsorSvc.init(); this.ready = true; + tempFileSvc.setReady(); }) .catch((err) => { if (err && err.message !== 'reload') { diff --git a/src/components/Layout.vue b/src/components/Layout.vue index bdd66040..a587ac95 100644 --- a/src/components/Layout.vue +++ b/src/components/Layout.vue @@ -119,8 +119,13 @@ export default { editorSvc.init(editorElt, previewElt, tocElt); // Focus on the editor every time reader mode is disabled - this.$watch(() => this.styles.showEditor, - showEditor => showEditor && editorSvc.clEditor.focus()); + const focus = () => { + if (this.styles.showEditor) { + editorSvc.clEditor.focus(); + } + }; + setTimeout(focus, 100); + this.$watch(() => this.styles.showEditor, focus); }, destroyed() { window.removeEventListener('resize', this.updateStyle); diff --git a/src/services/localDbSvc.js b/src/services/localDbSvc.js index f19a4104..36af63b5 100644 --- a/src/services/localDbSvc.js +++ b/src/services/localDbSvc.js @@ -6,6 +6,7 @@ import welcomeFile from '../data/welcomeFile.md'; const dbVersion = 1; const dbStoreName = 'objects'; const exportWorkspace = utils.queryParams.exportWorkspace; +const silent = utils.queryParams.silent; const resetApp = utils.queryParams.reset; const deleteMarkerMaxAge = 1000; const checkSponsorshipAfter = (5 * 60 * 1000) + (30 * 1000); // tokenExpirationMargin + 30 sec @@ -195,6 +196,10 @@ const localDbSvc = { * Write all changes from the store since previous transaction. */ writeAll(storeItemMap, tx) { + if (silent) { + // Skip writing to DB in silent mode + return; + } const dbStore = tx.objectStore(dbStoreName); const incrementedTx = this.lastTx + 1; diff --git a/src/services/tempFileSvc.js b/src/services/tempFileSvc.js index 7e8a768f..6cc70733 100644 --- a/src/services/tempFileSvc.js +++ b/src/services/tempFileSvc.js @@ -9,6 +9,11 @@ const contentText = utils.queryParams.contentText; const contentProperties = utils.queryParams.contentProperties; export default { + setReady() { + if (origin && window.parent) { + window.parent.postMessage({ type: 'ready' }, origin); + } + }, closed: false, close() { if (!this.closed && origin && window.parent) { @@ -22,9 +27,10 @@ export default { } store.commit('setLight', true); + return store.dispatch('createFile', { - name: fileName, - text: contentText, + name: fileName || utils.getHostname(origin), + text: contentText || '\n', properties: contentProperties, parentId: 'temp', }) @@ -67,11 +73,11 @@ export default { const properties = utils.computeProperties(content.properties); window.parent.postMessage({ type: 'fileChange', - file: { + payload: { id: file.id, name: currentFile.name, content: { - text: content.text, + text: content.text.slice(0, -1), // Remove trailing LF properties, yamlProperties: content.properties, html: editorSvc.previewCtx.html, @@ -83,7 +89,7 @@ export default { // Watch preview refresh and file name changes editorSvc.$on('previewCtx', onChange); - store.$watch(() => store.getters['file/current'].name, onChange); + store.watch(() => store.getters['file/current'].name, onChange); }); }, };