From cc43189ceee23e1a8cc00b52d518349b353a2dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 28 Mar 2025 12:36:29 +0200 Subject: [PATCH] Add a Connector version update warning for item saving changes (7.0) --- chrome/content/zotero/xpcom/intl.js | 2 +- .../zotero/xpcom/server/server_connector.js | 188 ++++++++---------- chrome/locale/en-US/zotero/zotero.ftl | 2 + 3 files changed, 87 insertions(+), 105 deletions(-) diff --git a/chrome/content/zotero/xpcom/intl.js b/chrome/content/zotero/xpcom/intl.js index 900b57317f..51e01b5a7f 100644 --- a/chrome/content/zotero/xpcom/intl.js +++ b/chrome/content/zotero/xpcom/intl.js @@ -126,7 +126,7 @@ Zotero.Intl = new function () { try { var l10n; if (params != undefined) { - if (typeof params != 'object'){ + if (typeof params != 'object') { params = [params]; } l10n = bundle.formatStringFromName(name, params, params.length); diff --git a/chrome/content/zotero/xpcom/server/server_connector.js b/chrome/content/zotero/xpcom/server/server_connector.js index 99fe70e960..091ee9a801 100644 --- a/chrome/content/zotero/xpcom/server/server_connector.js +++ b/chrome/content/zotero/xpcom/server/server_connector.js @@ -22,7 +22,7 @@ ***** END LICENSE BLOCK ***** */ -const CONNECTOR_API_VERSION = 2; +const CONNECTOR_API_VERSION = 3; Zotero.Server.Connector = { _waitingForSelection: {}, @@ -108,6 +108,79 @@ Zotero.Server.Connector = { } return { library, collection, editable }; + }, + + /** + * Warn on outdated connector version + */ + versionWarning: function (req, force=false) { + try { + if (!force) { + if (!Zotero.Prefs.get('showConnectorVersionWarning')) return; + if (Zotero.Server.Connector.skipVersionWarning) return; + } + if (!req.headers || !req.headers['X-Zotero-Connector-API-Version']) return; + + const appName = ZOTERO_CONFIG.CLIENT_NAME; + const domain = ZOTERO_CONFIG.DOMAIN_NAME; + + const apiVersion = req.headers['X-Zotero-Connector-API-Version']; + // We are up to date + if (apiVersion >= CONNECTOR_API_VERSION) return; + + var message = Zotero.getString("connector-version-warning"); + + if (!force) { + var showNext = Zotero.Prefs.get('nextConnectorVersionWarning'); + if (showNext && new Date() < new Date(showNext * 1000)) return; + } + + // Don't show again for this browser until restart (unless forced) + Zotero.Server.Connector.skipVersionWarning = true; + setTimeout(function () { + if (this.versionWarningShowing) return; + + var remindLater = {}; + let options = { + title: Zotero.getString('general.updateAvailable'), + text: message, + button0: Zotero.getString('general.upgrade'), + button1: Zotero.getString('general.notNow'), + } + if (!force) { + const SHOW_AGAIN_DAYS = 7; + options.checkLabel = Zotero.getString( + 'general.dontShowAgainFor', + SHOW_AGAIN_DAYS, + SHOW_AGAIN_DAYS + ); + options.checkbox = remindLater; + } + this.versionWarningShowing = true; + const index = Zotero.Prompt.confirm(options) + this.versionWarningShowing = false; + + var nextShowDays; + // Remind in a week if checked remind me later + if (remindLater.value) { + nextShowDays = 7; + } + // Don't show again for at least a day, even after a restart + else { + nextShowDays = 1; + } + Zotero.Prefs.set('nextConnectorVersionWarning', Math.round(Date.now() / 1000) + 24*60*60 * nextShowDays); + + if (index == 0) { + Zotero.launchURL(ZOTERO_CONFIG.CONNECTORS_URL); + } + }.bind(this), 0); + + return [400, "application/json", JSON.stringify({ error: "CONNECTOR_VERSION_OUTDATED" })]; + } + catch (e) { + Zotero.debug(e, 2); + } } }; @@ -238,6 +311,10 @@ Zotero.Server.Connector.SaveItems.prototype = { * to the database */ init: async function (requestData) { + const response = Zotero.Server.Connector.versionWarning(requestData, true); + if (response) { + return response; + } var data = requestData.data; var { library, collection, editable } = Zotero.Server.Connector.getSaveTarget(); @@ -540,6 +617,11 @@ Zotero.Server.Connector.SaveSnapshot.prototype = { * Save snapshot */ init: async function (requestData) { + const response = Zotero.Server.Connector.versionWarning(requestData, true); + if (response) { + return response; + } + var data = requestData.data; var { library, collection } = Zotero.Server.Connector.getSaveTarget(); @@ -1029,114 +1111,12 @@ Zotero.Server.Connector.Ping.prototype = { response.prefs.reportActiveURL = true; } - this.versionWarning(req); + Zotero.Server.Connector.versionWarning(req); return [200, 'application/json', JSON.stringify(response)]; } }, - - /** - * Warn on outdated connector version - * - * We can remove this once the connector checks and warns on its own and most people are on - * a version that does that. - */ - versionWarning: function (req) { - try { - if (!Zotero.Prefs.get('showConnectorVersionWarning')) return; - if (!req.headers) return; - - var minVersion = ZOTERO_CONFIG.CONNECTOR_MIN_VERSION; - var appName = ZOTERO_CONFIG.CLIENT_NAME; - var domain = ZOTERO_CONFIG.DOMAIN_NAME; - var origin = req.headers.Origin; - - var browser; - var message; - var showDownloadButton = false; - // Legacy Safari extension - if (origin && origin.startsWith('safari-extension')) { - browser = 'safari'; - message = `An update is available for the ${appName} Connector for Safari.\n\n` - + 'You can upgrade from the Extensions pane of the Safari preferences.'; - } - else if (origin && origin.startsWith('chrome-extension')) { - browser = 'chrome'; - message = `An update is available for the ${appName} Connector for Chrome.\n\n` - + `You can upgrade to the latest version from ${domain}.`; - showDownloadButton = true; - } - else if (req.headers['User-Agent'] && req.headers['User-Agent'].includes('Firefox/')) { - browser = 'firefox'; - message = `An update is available for the ${appName} Connector for Firefox.\n\n` - + `You can upgrade to the latest version from ${domain}.`; - showDownloadButton = true; - } - // Safari App Extension is always up to date - else if (req.headers['User-Agent'] && req.headers['User-Agent'].includes('Safari/')) { - return; - } - else { - Zotero.debug("Unknown browser"); - return; - } - - if (Zotero.Server.Connector['skipVersionWarning-' + browser]) return; - - var version = req.headers['X-Zotero-Version']; - if (!version || version == '4.999.0') return; - - // If connector is up to date, bail - if (Services.vc.compare(version, minVersion) >= 0) return; - - var showNextPref = `nextConnectorVersionWarning.${browser}`; - var showNext = Zotero.Prefs.get(showNextPref); - if (showNext && new Date() < new Date(showNext * 1000)) return; - - // Don't show again for this browser until restart - Zotero.Server.Connector['skipVersionWarning-' + browser] = true; - var ps = Services.prompt; - var buttonFlags; - if (showDownloadButton) { - buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING - + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_IS_STRING; - } - else { - buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_OK; - } - setTimeout(function () { - var dontShow = {}; - var index = ps.confirmEx(null, - Zotero.getString('general.updateAvailable'), - message, - buttonFlags, - showDownloadButton ? Zotero.getString('general.upgrade') : null, - showDownloadButton ? Zotero.getString('general.notNow') : null, - null, - "Don\u0027t show again for a month", - dontShow - ); - - var nextShowDays; - if (dontShow.value) { - nextShowDays = 30; - } - // Don't show again for at least a day, even after a restart - else { - nextShowDays = 1; - } - Zotero.Prefs.set(showNextPref, Math.round(Date.now() / 1000) + 86400 * nextShowDays); - - if (showDownloadButton && index == 0) { - Zotero.launchURL(ZOTERO_CONFIG.CONNECTORS_URL); - } - }, 500); - } - catch (e) { - Zotero.debug(e, 2); - } - } } /** diff --git a/chrome/locale/en-US/zotero/zotero.ftl b/chrome/locale/en-US/zotero/zotero.ftl index c99dd16133..d8bf4fe606 100644 --- a/chrome/locale/en-US/zotero/zotero.ftl +++ b/chrome/locale/en-US/zotero/zotero.ftl @@ -768,4 +768,6 @@ mac-word-plugin-install-remind-later-button = mac-word-plugin-install-dont-ask-again-button = .label = { general-dont-ask-again } +connector-version-warning = The { -app-name } Connector must be updated to work with this version of { -app-name }. + userjs-pref-warning = Some { -app-name } settings have been overridden using an unsupported method. { -app-name } will revert them and restart.