Temporary folder (part 3)

This commit is contained in:
Benoit Schweblin 2018-03-15 13:51:39 +00:00
parent c5e0f3e2e4
commit 7c0bf68ad3
4 changed files with 25 additions and 7 deletions

View File

@ -18,6 +18,7 @@ import SplashScreen from './SplashScreen';
import syncSvc from '../services/syncSvc'; import syncSvc from '../services/syncSvc';
import networkSvc from '../services/networkSvc'; import networkSvc from '../services/networkSvc';
import sponsorSvc from '../services/sponsorSvc'; import sponsorSvc from '../services/sponsorSvc';
import tempFileSvc from '../services/tempFileSvc';
import timeSvc from '../services/timeSvc'; import timeSvc from '../services/timeSvc';
import store from '../store'; import store from '../store';
@ -94,6 +95,7 @@ export default {
networkSvc.init(); networkSvc.init();
sponsorSvc.init(); sponsorSvc.init();
this.ready = true; this.ready = true;
tempFileSvc.setReady();
}) })
.catch((err) => { .catch((err) => {
if (err && err.message !== 'reload') { if (err && err.message !== 'reload') {

View File

@ -119,8 +119,13 @@ export default {
editorSvc.init(editorElt, previewElt, tocElt); editorSvc.init(editorElt, previewElt, tocElt);
// Focus on the editor every time reader mode is disabled // Focus on the editor every time reader mode is disabled
this.$watch(() => this.styles.showEditor, const focus = () => {
showEditor => showEditor && editorSvc.clEditor.focus()); if (this.styles.showEditor) {
editorSvc.clEditor.focus();
}
};
setTimeout(focus, 100);
this.$watch(() => this.styles.showEditor, focus);
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.updateStyle); window.removeEventListener('resize', this.updateStyle);

View File

@ -6,6 +6,7 @@ import welcomeFile from '../data/welcomeFile.md';
const dbVersion = 1; const dbVersion = 1;
const dbStoreName = 'objects'; const dbStoreName = 'objects';
const exportWorkspace = utils.queryParams.exportWorkspace; const exportWorkspace = utils.queryParams.exportWorkspace;
const silent = utils.queryParams.silent;
const resetApp = utils.queryParams.reset; const resetApp = utils.queryParams.reset;
const deleteMarkerMaxAge = 1000; const deleteMarkerMaxAge = 1000;
const checkSponsorshipAfter = (5 * 60 * 1000) + (30 * 1000); // tokenExpirationMargin + 30 sec 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. * Write all changes from the store since previous transaction.
*/ */
writeAll(storeItemMap, tx) { writeAll(storeItemMap, tx) {
if (silent) {
// Skip writing to DB in silent mode
return;
}
const dbStore = tx.objectStore(dbStoreName); const dbStore = tx.objectStore(dbStoreName);
const incrementedTx = this.lastTx + 1; const incrementedTx = this.lastTx + 1;

View File

@ -9,6 +9,11 @@ const contentText = utils.queryParams.contentText;
const contentProperties = utils.queryParams.contentProperties; const contentProperties = utils.queryParams.contentProperties;
export default { export default {
setReady() {
if (origin && window.parent) {
window.parent.postMessage({ type: 'ready' }, origin);
}
},
closed: false, closed: false,
close() { close() {
if (!this.closed && origin && window.parent) { if (!this.closed && origin && window.parent) {
@ -22,9 +27,10 @@ export default {
} }
store.commit('setLight', true); store.commit('setLight', true);
return store.dispatch('createFile', { return store.dispatch('createFile', {
name: fileName, name: fileName || utils.getHostname(origin),
text: contentText, text: contentText || '\n',
properties: contentProperties, properties: contentProperties,
parentId: 'temp', parentId: 'temp',
}) })
@ -67,11 +73,11 @@ export default {
const properties = utils.computeProperties(content.properties); const properties = utils.computeProperties(content.properties);
window.parent.postMessage({ window.parent.postMessage({
type: 'fileChange', type: 'fileChange',
file: { payload: {
id: file.id, id: file.id,
name: currentFile.name, name: currentFile.name,
content: { content: {
text: content.text, text: content.text.slice(0, -1), // Remove trailing LF
properties, properties,
yamlProperties: content.properties, yamlProperties: content.properties,
html: editorSvc.previewCtx.html, html: editorSvc.previewCtx.html,
@ -83,7 +89,7 @@ export default {
// Watch preview refresh and file name changes // Watch preview refresh and file name changes
editorSvc.$on('previewCtx', onChange); editorSvc.$on('previewCtx', onChange);
store.$watch(() => store.getters['file/current'].name, onChange); store.watch(() => store.getters['file/current'].name, onChange);
}); });
}, },
}; };