Auto-sync on first open of Zotero pane after starting Firefox

This commit is contained in:
Dan Stillman 2008-07-01 20:39:20 +00:00
parent d48adde7ed
commit 20d649ee42
3 changed files with 37 additions and 5 deletions

View file

@ -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);

View file

@ -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([

View file

@ -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);