diff --git a/core/modules/saver-handler.js b/core/modules/saver-handler.js index 40747b8d6..1c9b519f3 100644 --- a/core/modules/saver-handler.js +++ b/core/modules/saver-handler.js @@ -21,6 +21,7 @@ function SaverHandler(options) { var self = this; this.wiki = options.wiki; this.dirtyTracking = options.dirtyTracking; + this.preloadDirty = options.preloadDirty || []; this.pendingAutoSave = false; // Make a logger this.logger = new $tw.utils.Logger("saver-handler"); @@ -33,7 +34,13 @@ function SaverHandler(options) { // Compile the dirty tiddler filter this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter)); // Count of changes that have not yet been saved - this.numChanges = 0; + var filteredChanges = self.filterFn.call(self.wiki,function(iterator) { + $tw.utils.each(self.preloadDirty,function(title) { + var tiddler = self.wiki.getTiddler(title); + iterator(tiddler,title); + }); + }); + this.numChanges = filteredChanges.length; // Listen out for changes to tiddlers this.wiki.addEventListener("change",function(changes) { // Filter the changes so that we only count changes to tiddlers that we care about diff --git a/core/modules/startup/startup.js b/core/modules/startup/startup.js index 6dac725f3..442ba67ad 100755 --- a/core/modules/startup/startup.js +++ b/core/modules/startup/startup.js @@ -130,7 +130,11 @@ exports.startup = function() { $tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor}); } // Setup the saver handler - $tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki, dirtyTracking: !$tw.syncadaptor}); + $tw.saverHandler = new $tw.SaverHandler({ + wiki: $tw.wiki, + dirtyTracking: !$tw.syncadaptor, + preloadDirty: $tw.boot.preloadDirty || [] + }); // Host-specific startup if($tw.browser) { // Install the popup manager diff --git a/plugins/tiddlywiki/browser-storage/rawmarkup.js b/plugins/tiddlywiki/browser-storage/rawmarkup.js index 131b010b6..bebc76688 100644 --- a/plugins/tiddlywiki/browser-storage/rawmarkup.js +++ b/plugins/tiddlywiki/browser-storage/rawmarkup.js @@ -12,6 +12,8 @@ Startup code injected as raw markup // Need to initialise these because we run before bootprefix.js and boot.js $tw = window.$tw || Object.create(null); $tw.hooks = $tw.hooks || { names: {}}; +$tw.boot = $tw.boot || {}; +$tw.boot.preloadDirty = $tw.boot.preloadDirty || []; // Hook the point in the startup process when the tiddlers have been loaded but plugins not unpacked var hookName = "th-boot-tiddlers-loaded"; @@ -48,14 +50,17 @@ function hookBootTiddlersLoaded() { if(existingTiddler && existingTiddler.isEqual(incomingTiddler)) { // If the incoming tiddler is the same as the existing then we can delete the local storage version window.localStorage.removeItem(key); + } else { + $tw.wiki.addTiddler(incomingTiddler); + log.push(title); } - $tw.wiki.addTiddler(incomingTiddler); - log.push(title); } } } } } + // Make sure that all the tiddlers we've loaded are marked as dirty at startup + Array.prototype.push.apply($tw.boot.preloadDirty,log); // Save the log $tw.wiki.addTiddler({ title: "$:/temp/BrowserStorage/Log",