diff --git a/tw5dropbox/appwiki/plugins/dropbox-app.js b/tw5dropbox/appwiki/plugins/dropbox-app.js index a16516c60..756370d1b 100644 --- a/tw5dropbox/appwiki/plugins/dropbox-app.js +++ b/tw5dropbox/appwiki/plugins/dropbox-app.js @@ -12,38 +12,40 @@ Startup the Dropbox wiki app /*global $tw: false */ "use strict"; -exports.startup = function() { - // Check that we've been loaded from the dropbox - var url = (window.location.protocol + "//" + window.location.host + window.location.pathname), - wikiName; - if(url.indexOf($tw.plugins.dropbox.userInfo.publicAppUrl) === 0) { - var p = url.indexOf("/",$tw.plugins.dropbox.userInfo.publicAppUrl.length + 1); - if(p !== -1 && url.substr(p) === "/index.html") { - wikiName = decodeURIComponent(url.substring($tw.plugins.dropbox.userInfo.publicAppUrl.length + 1,p)); - } +exports.startup = function(loggedIn) { + // Load any tiddlers embedded in the index file + var index = $tw.wiki.getTiddlerData($tw.plugins.dropbox.titleTiddlerIndex); + if(index) { + $tw.wiki.addTiddlers(index.tiddlers); + $tw.wiki.addTiddlers(index.shadows,true); + $tw.plugins.dropbox.fileInfo = index.fileInfo; } - if(wikiName) { - // Save the wiki name for later - $tw.plugins.dropbox.wikiName = wikiName; - $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleWikiName, text: $tw.plugins.dropbox.wikiName},true); - // Load any tiddlers embedded in the index file - var index = $tw.wiki.getTiddlerData($tw.plugins.dropbox.titleTiddlerIndex); - if(index) { - $tw.wiki.addTiddlers(index.tiddlers); - $tw.wiki.addTiddlers(index.shadows,true); - $tw.plugins.dropbox.fileInfo = index.fileInfo; - } - // Check for later versions of files on Dropbox - $tw.plugins.dropbox.loadTiddlerFiles("/" + $tw.plugins.dropbox.wikiName + "/tiddlers",function(hadChanges) { - // Save the tiddler index if we had changes - if(hadChanges) { - $tw.plugins.dropbox.saveTiddlerIndex("/" + $tw.plugins.dropbox.wikiName + "/index.html",function(error) { - console.log("Saved tiddler index"); - }); + if(loggedIn) { + // Figure out the wiki name + var url = (window.location.protocol + "//" + window.location.host + window.location.pathname), + wikiName; + if(url.indexOf($tw.plugins.dropbox.userInfo.publicAppUrl) === 0) { + var p = url.indexOf("/",$tw.plugins.dropbox.userInfo.publicAppUrl.length + 1); + if(p !== -1 && url.substr(p) === "/index.html") { + wikiName = decodeURIComponent(url.substring($tw.plugins.dropbox.userInfo.publicAppUrl.length + 1,p)); } - }); - } else { - alert("This TiddlyWiki file must be in Dropbox"); + } + if(wikiName) { + // Save the wiki name for later + $tw.plugins.dropbox.wikiName = wikiName; + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleWikiName, text: $tw.plugins.dropbox.wikiName},true); + // Check for later versions of files on Dropbox + $tw.plugins.dropbox.refreshTiddlerFiles("/" + $tw.plugins.dropbox.wikiName + "/tiddlers",function(hadChanges) { + // Save the tiddler index if we had changes + if(hadChanges) { + $tw.plugins.dropbox.saveTiddlerIndex("/" + $tw.plugins.dropbox.wikiName + "/index.html",function(error) { + console.log("Saved tiddler index"); + }); + } + }); + } else { + alert("This TiddlyWiki file must be in Dropbox"); + } } }; diff --git a/tw5dropbox/mainwiki/plugins/dropbox-main.js b/tw5dropbox/mainwiki/plugins/dropbox-main.js index 176e78eaf..dc96668f5 100644 --- a/tw5dropbox/mainwiki/plugins/dropbox-main.js +++ b/tw5dropbox/mainwiki/plugins/dropbox-main.js @@ -12,13 +12,15 @@ Startup the Dropbox main app /*global $tw: false */ "use strict"; -exports.startup = function() { - $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleLoadedWikis, text: "no"},true); - // Load tiddlers - $tw.plugins.dropbox.loadWikiFiles("/",function() { - $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleLoadedWikis, text: "yes"},true); - console.log("Loaded all wikis",$tw.wiki.tiddlers); - }); +exports.startup = function(loggedIn) { + if(loggedIn) { + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleLoadedWikis, text: "no"},true); + // Load tiddlers + $tw.plugins.dropbox.loadWikiFiles("/",function() { + $tw.wiki.addTiddler({title: $tw.plugins.dropbox.titleLoadedWikis, text: "yes"},true); + console.log("Loaded all wikis",$tw.wiki.tiddlers); + }); + } }; })(); diff --git a/tw5dropbox/plugins/dropbox.js b/tw5dropbox/plugins/dropbox.js index ffcd23686..62b74ba83 100644 --- a/tw5dropbox/plugins/dropbox.js +++ b/tw5dropbox/plugins/dropbox.js @@ -48,14 +48,19 @@ $tw.plugins.dropbox.login = function() { // Get user information $tw.plugins.dropbox.getUserInfo(function() { // Invoke any dropbox-startup modules - var mods = $tw.modules.types["dropbox-startup"]; - for(var m=0; m