diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 21cf108534..13fadfa760 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -298,6 +298,12 @@ var ZoteroPane = new function() // Focus the quicksearch on pane open setTimeout("document.getElementById('zotero-tb-search').inputField.select();", 1); + + if (Zotero.Prefs.get('sync.server.autoSync') && Zotero.Sync.Server.enabled) { + setTimeout(function () { + Zotero.Sync.Server.sync(); + }, 1000); + } } else { zoteroPane.setAttribute('collapsed', true); diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js index e9a426577b..ad2a784f1a 100644 --- a/chrome/content/zotero/xpcom/sync.js +++ b/chrome/content/zotero/xpcom/sync.js @@ -380,16 +380,26 @@ Zotero.Sync.Server = new function () { this.clearSyncTimeout = clearSyncTimeout; this.setSyncIcon = setSyncIcon; + this.__defineGetter__('enabled', function () { + return this.username && this.password; + }); + this.__defineGetter__('username', function () { return Zotero.Prefs.get('sync.server.username'); }); this.__defineGetter__('password', function () { - if (!this.username) { + var username = this.username; + + if (!username) { Zotero.debug('Username not set before setting Zotero.Sync.Server.password'); return ''; } + if (_cachedCredentials[username]) { + return _cachedCredentials[username]; + } + Zotero.debug('Getting Zotero sync password'); var loginManager = Components.classes["@mozilla.org/login-manager;1"] .getService(Components.interfaces.nsILoginManager); @@ -397,7 +407,8 @@ Zotero.Sync.Server = new function () { // Find user from returned array of nsILoginInfo objects for (var i = 0; i < logins.length; i++) { - if (logins[i].username == this.username) { + if (logins[i].username == username) { + _cachedCredentials[username] = logins[i].password; return logins[i].password; } } @@ -408,11 +419,15 @@ Zotero.Sync.Server = new function () { this.__defineSetter__('password', function (password) { _sessionID = null; - if (!this.username) { + var username = this.username; + + if (!username) { Zotero.debug('Username not set before setting Zotero.Sync.Server.password'); return; } + delete _cachedCredentials[username]; + if (!password) { Zotero.debug('Password empty setting Zotero.Sync.Server.password'); return; @@ -435,8 +450,9 @@ Zotero.Sync.Server = new function () { Zotero.debug('Setting Zotero sync password'); var loginInfo = new nsLoginInfo(_loginManagerHost, _loginManagerURL, - null, this.username, password, "", ""); + null, username, password, "", ""); loginManager.addLogin(loginInfo); + _cachedCredentials[username] = password; } }); @@ -475,6 +491,7 @@ Zotero.Sync.Server = new function () { var _apiVersionComponent = "version=" + this.apiVersion; var _maxAttempts = 3; var _attempts = _maxAttempts; + var _cachedCredentials = {}; var _syncInProgress; var _sessionID; var _sessionLock; @@ -1153,7 +1170,9 @@ Zotero.Sync.Server.EventListener = { return; } - Zotero.Sync.Server.setSyncTimeout(); + if (Zotero.Prefs.get('sync.server.autoSync') && Zotero.Sync.Server.enabled) { + Zotero.Sync.Server.setSyncTimeout(); + } } } @@ -1294,6 +1313,12 @@ Zotero.Sync.Server.Data = new function() { throw ('Reconciliation unimplemented for ' + types); } + if (obj.isAttachment()) { + var msg = "Reconciliation unimplemented for attachment items"; + alert(msg); + throw(msg); + } + // TODO: order reconcile by parent/child? toReconcile.push([ diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index 7bda721c03..80f5ac3d48 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -77,5 +77,6 @@ pref("extensions.zotero.zeroconf.server.enabled", false); pref("extensions.zotero.annotations.warnOnClose", true); // Server +pref("extensions.zotero.sync.server.autoSync", true); pref("extensions.zotero.sync.server.username", ''); pref("extensions.zotero.sync.server.compressData", true); \ No newline at end of file