From a2bac6b299b834de5de3d2ed9a7fc3e360d8198b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 28 Aug 2024 02:22:39 -0400 Subject: [PATCH] Use Z.Prompt.confirm() for delayed-button prompts to fix CI failures After f9faa0415f, Zotero.Prompt.confirm() ignores the delayed-button flag when running in CI. --- .../zotero/preferences/preferences_sync.jsx | 23 +++++++--------- chrome/content/zotero/xpcom/storage.js | 18 +++++-------- .../zotero/xpcom/storage/storageUtilities.js | 27 +++++++------------ chrome/content/zotero/xpcom/sync.js | 20 +++++--------- .../content/zotero/xpcom/sync/syncRunner.js | 24 ++++++----------- .../zotero/xpcom/sync/syncUtilities.js | 27 +++++++------------ 6 files changed, 50 insertions(+), 89 deletions(-) diff --git a/chrome/content/zotero/preferences/preferences_sync.jsx b/chrome/content/zotero/preferences/preferences_sync.jsx index 38d58f4895..70d2f8def5 100644 --- a/chrome/content/zotero/preferences/preferences_sync.jsx +++ b/chrome/content/zotero/preferences/preferences_sync.jsx @@ -513,19 +513,14 @@ Zotero_Preferences.Sync = { var sql = "SELECT COUNT(*) FROM settings " + "WHERE setting='storage' AND key='zfsPurge' AND value='user'"; if (!Zotero.DB.valueQueryAsync(sql)) { - let ps = Services.prompt; - var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) - + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING) - + ps.BUTTON_DELAY_ENABLE; var account = Zotero.Sync.Server.username; - var index = ps.confirmEx( - null, - Zotero.getString('zotero.preferences.sync.purgeStorage.title'), - Zotero.getString('zotero.preferences.sync.purgeStorage.desc'), - buttonFlags, - Zotero.getString('zotero.preferences.sync.purgeStorage.confirmButton'), - Zotero.getString('zotero.preferences.sync.purgeStorage.cancelButton'), null, null, {} - ); + var index = Zotero.Prompt.confirm({ + title: Zotero.getString('zotero.preferences.sync.purgeStorage.title'), + text: Zotero.getString('zotero.preferences.sync.purgeStorage.desc'), + button0: Zotero.getString('zotero.preferences.sync.purgeStorage.confirmButton'), + button1: Zotero.getString('zotero.preferences.sync.purgeStorage.cancelButton'), + buttonDelay: true, + }); if (index == 0) { var sql = "INSERT OR IGNORE INTO settings VALUES (?,?,?)"; @@ -533,7 +528,7 @@ Zotero_Preferences.Sync = { try { yield Zotero.Sync.Storage.ZFS.purgeDeletedStorageFiles(); - ps.alert( + Services.prompt.alert( null, Zotero.getString("general.success"), "Attachment files from your personal library have been removed from the Zotero servers." @@ -541,7 +536,7 @@ Zotero_Preferences.Sync = { } catch (e) { Zotero.logError(e); - ps.alert( + Services.prompt.alert( null, Zotero.getString("general.error"), "An error occurred. Please try again later." diff --git a/chrome/content/zotero/xpcom/storage.js b/chrome/content/zotero/xpcom/storage.js index c0e87bb995..cee7d04030 100644 --- a/chrome/content/zotero/xpcom/storage.js +++ b/chrome/content/zotero/xpcom/storage.js @@ -115,20 +115,14 @@ Zotero.Sync.Storage = new function () { setTimeout(function () { var group = Zotero.Groups.get(e.data.groupID); - var ps = Services.prompt; - var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) - + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL) - + ps.BUTTON_DELAY_ENABLE; - var index = ps.confirmEx( - null, - Zotero.getString('general.warning'), - Zotero.getString('sync.storage.error.fileEditingAccessLost', group.name) + "\n\n" + var index = Zotero.Prompt.confirm({ + title: Zotero.getString('general.warning'), + text: Zotero.getString('sync.storage.error.fileEditingAccessLost', group.name) + "\n\n" + Zotero.getString('sync.error.groupWillBeReset') + "\n\n" + Zotero.getString('sync.error.copyChangedItems'), - buttonFlags, - Zotero.getString('sync.resetGroupAndSync'), - null, null, null, {} - ); + button0: Zotero.getString('sync.resetGroupAndSync'), + buttonDelay: true, + }); if (index == 0) { // TODO: transaction diff --git a/chrome/content/zotero/xpcom/storage/storageUtilities.js b/chrome/content/zotero/xpcom/storage/storageUtilities.js index fd92272bab..cee21e795a 100644 --- a/chrome/content/zotero/xpcom/storage/storageUtilities.js +++ b/chrome/content/zotero/xpcom/storage/storageUtilities.js @@ -83,28 +83,21 @@ Zotero.Sync.Storage.Utilities = { [library.name, ZOTERO_CONFIG.DOMAIN_NAME]) + "\n\n" + Zotero.getString('sync.error.groupCopyChangedFiles') - var button1Text = Zotero.getString('sync.resetGroupFilesAndSync'); - var button2Text = Zotero.getString('sync.skipGroup'); + var button0Text = Zotero.getString('sync.resetGroupFilesAndSync'); + var button1Text = Zotero.getString('sync.skipGroup'); break; default: throw new Error("Unsupported library type " + libraryType); } - var ps = Services.prompt; - var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) - + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING) - + ps.BUTTON_DELAY_ENABLE; - - return ps.confirmEx( - win, - Zotero.getString('general.permissionDenied'), - msg, - buttonFlags, - button1Text, - button2Text, - null, - null, {} - ); + return Zotero.Prompt.confirm({ + window: win, + title: Zotero.getString('general.permissionDenied'), + text: msg, + button0: button0Text, + button1: button1Text, + buttonDelay: true, + }); } } diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js index e5fa06de81..ce91fb86bd 100644 --- a/chrome/content/zotero/xpcom/sync.js +++ b/chrome/content/zotero/xpcom/sync.js @@ -260,21 +260,15 @@ Zotero.Sync.Server = new function () { } } - var ps = Services.prompt; - var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) - + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL) - + ps.BUTTON_DELAY_ENABLE; - var index = ps.confirmEx( - null, - Zotero.getString('general.warning'), - Zotero.getString('sync.error.writeAccessLost', group.name) + "\n\n" + var index = Zotero.Prompt.confirm({ + title: Zotero.getString('general.warning'), + text: Zotero.getString('sync.error.writeAccessLost', group.name) + "\n\n" + Zotero.getString('sync.error.groupWillBeReset') + "\n\n" + Zotero.getString('sync.error.copyChangedItems'), - buttonFlags, - Zotero.getString('sync.resetGroupAndSync'), - null, null, null, {} - ); - + button0: Zotero.getString('sync.resetGroupAndSync'), + button1: Zotero.Prompt.BUTTON_TITLE_CANCEL, + buttonDelay: true + }); if (index == 0) { group.erase(); Zotero.Sync.Server.resetClient(); diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 10504d4ffd..905107129c 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -541,12 +541,6 @@ Zotero.Sync.Runner_Module = function (options = {}) { let removedGroups = []; let keptGroups = []; - let ps = Services.prompt; - let buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) - + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING) - + (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING) - + ps.BUTTON_DELAY_ENABLE; - // Prompt for each group // // TODO: Localize @@ -570,18 +564,16 @@ Zotero.Sync.Runner_Module = function (options = {}) { msg += "\n\n" + "Would you like to remove it from this computer or keep it " + "as a read-only library?"; - let index = ps.confirmEx( - null, - "Group Not Found", - msg, - buttonFlags, - "Remove Group", + let index = Zotero.Prompt.confirm({ + title: "Group Not Found", + text: msg, + button0: "Remove Group", // TODO: Any way to have Esc trigger extra1 instead so it doesn't // have to be in this order? - "Cancel Sync", - "Keep Group", - null, {} - ); + button1: "Cancel Sync", + button2: "Keep Group", + buttonDelay: true, + }); if (index == 0) { removedGroups.push(group); diff --git a/chrome/content/zotero/xpcom/sync/syncUtilities.js b/chrome/content/zotero/xpcom/sync/syncUtilities.js index afa1f96ee7..92496b2fa8 100644 --- a/chrome/content/zotero/xpcom/sync/syncUtilities.js +++ b/chrome/content/zotero/xpcom/sync/syncUtilities.js @@ -64,28 +64,21 @@ Zotero.Sync.Data.Utilities = { [library.name, ZOTERO_CONFIG.DOMAIN_NAME]) + "\n\n" + Zotero.getString('sync.error.groupCopyChangedItems') - var button1Text = Zotero.getString('sync.resetGroupAndSync'); - var button2Text = Zotero.getString('sync.skipGroup'); + var button0Text = Zotero.getString('sync.resetGroupAndSync'); + var button1Text = Zotero.getString('sync.skipGroup'); break; default: throw new Error("Unsupported library type " + libraryType); } - var ps = Services.prompt; - var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) - + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING) - + ps.BUTTON_DELAY_ENABLE; - - return ps.confirmEx( - win, - Zotero.getString('general.permissionDenied'), - msg, - buttonFlags, - button1Text, - button2Text, - null, - null, {} - ); + return Zotero.Prompt.confirm({ + window: win, + title: Zotero.getString('general.permissionDenied'), + text: msg, + button0: button0Text, + button1: button1Text, + buttonDelay: true, + }); } };