From a0bdeab401b67ea1cf4becc2d08f3f67b389e460 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 6 Dec 2024 02:49:43 -0500 Subject: [PATCH] fx128: Fix login manager Use async methods (since the sync ones seem to already be broken from JS despite https://bugzilla.mozilla.org/show_bug.cgi?id=1832756 still being open) and avoid loading Firefox Accounts module --- app/scripts/fetch_xulrunner | 3 +++ chrome/content/zotero/xpcom/sync/syncLocal.js | 11 ++++------- chrome/content/zotero/xpcom/sync/syncRunner.js | 4 ++-- test/tests/syncLocalTest.js | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/scripts/fetch_xulrunner b/app/scripts/fetch_xulrunner index 5b5cf145c7..f82ff72462 100755 --- a/app/scripts/fetch_xulrunner +++ b/app/scripts/fetch_xulrunner @@ -291,6 +291,9 @@ function modify_omni { replace_line 'let uninstall = \(\) => \{' 'let uninstall = async () => {' modules/addons/XPIInstall.sys.mjs replace_line 'cancelUninstallAddon\(aAddon\)' 'async cancelUninstallAddon(aAddon)' modules/addons/XPIInstall.sys.mjs + # Prevent login manager from trying to load FxAccountsCommon.sys.mjs + replace_line 'return login.hostname == lazy.FXA_PWDMGR_HOST;' 'return false;' modules/storage-json.sys.mjs + # No idea why this is necessary, but without it initialization fails with "TypeError: "constructor" is read-only" replace_line 'LoginStore.prototype.constructor = LoginStore;' '\/\/LoginStore.prototype.constructor = LoginStore;' modules/LoginStore.sys.mjs # diff --git a/chrome/content/zotero/xpcom/sync/syncLocal.js b/chrome/content/zotero/xpcom/sync/syncLocal.js index 25a1cc4566..21057c8f2e 100644 --- a/chrome/content/zotero/xpcom/sync/syncLocal.js +++ b/chrome/content/zotero/xpcom/sync/syncLocal.js @@ -68,17 +68,14 @@ Zotero.Sync.Data.Local = { }, - setAPIKey: function (apiKey) { - var loginManager = Components.classes["@mozilla.org/login-manager;1"] - .getService(Components.interfaces.nsILoginManager); - + setAPIKey: async function (apiKey) { var oldLoginInfo = this._getAPIKeyLoginInfo(); // Clear old login if ((!apiKey || apiKey === "")) { if (oldLoginInfo) { Zotero.debug("Clearing old API key"); - loginManager.removeLogin(oldLoginInfo); + Services.logins.removeLogin(oldLoginInfo); } Zotero.Notifier.trigger('delete', 'api-key', []); return; @@ -97,11 +94,11 @@ Zotero.Sync.Data.Local = { ); if (!oldLoginInfo) { Zotero.debug("Setting API key"); - loginManager.addLogin(loginInfo); + await Services.logins.addLoginAsync(loginInfo); } else { Zotero.debug("Replacing API key"); - loginManager.modifyLogin(oldLoginInfo, loginInfo); + await Services.logins.modifyLoginAsync(oldLoginInfo, loginInfo); } Zotero.Notifier.trigger('modify', 'api-key', []); }, diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index e605a231af..655de84b77 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -1664,7 +1664,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { if (!json.username) throw new Error("username not found in key response"); if (!json.access) throw new Error("'access' not found in key response"); - Zotero.Sync.Data.Local.setAPIKey(json.key); + yield Zotero.Sync.Data.Local.setAPIKey(json.key); return json; }) @@ -1674,7 +1674,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { this.resetStorageController('zfs'); var apiKey = yield Zotero.Sync.Data.Local.getAPIKey(); var client = this.getAPIClient({apiKey}); - Zotero.Sync.Data.Local.setAPIKey(); + yield Zotero.Sync.Data.Local.setAPIKey(); yield client.deleteAPIKey(); }) diff --git a/test/tests/syncLocalTest.js b/test/tests/syncLocalTest.js index aa033d7d91..2c32155b6d 100644 --- a/test/tests/syncLocalTest.js +++ b/test/tests/syncLocalTest.js @@ -5,17 +5,17 @@ describe("Zotero.Sync.Data.Local", function() { it("should get and set an API key", function* () { var apiKey1 = Zotero.Utilities.randomString(24); var apiKey2 = Zotero.Utilities.randomString(24); - Zotero.Sync.Data.Local.setAPIKey(apiKey1); + yield Zotero.Sync.Data.Local.setAPIKey(apiKey1); yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(apiKey1), apiKey1); - Zotero.Sync.Data.Local.setAPIKey(apiKey2); + yield Zotero.Sync.Data.Local.setAPIKey(apiKey2); yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(apiKey2), apiKey2); }) it("should clear an API key by setting an empty string", function* () { var apiKey = Zotero.Utilities.randomString(24); - Zotero.Sync.Data.Local.setAPIKey(apiKey); - Zotero.Sync.Data.Local.setAPIKey(""); + yield Zotero.Sync.Data.Local.setAPIKey(apiKey); + yield Zotero.Sync.Data.Local.setAPIKey(""); yield assert.eventually.strictEqual(Zotero.Sync.Data.Local.getAPIKey(apiKey), ""); }) })