From 58c2e38ec22e484d8a8fd9a55c1bfca214e09e99 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 20 Mar 2020 16:02:57 -0400 Subject: [PATCH] Fix invalid integration plugin installations on macOS If a Mac user first starts Zotero from the disk image, Zotero shows an error telling them to install the app in Applications, but the integration plugins will have already be registered in extensions.json with paths to the temporary AppTranslocation directory. This meant that the next time the user restarted their computer (or sooner), the AppTranslocation directory would be cleared and the integration plugins would no longer be loaded. This deletes extensions.json if it contains an AppTranslocation path for an extension when the app is started from the disk image, which should prevent this going forward. For existing users experiencing this, it also checks installed extensions at startup for AppTranslocation paths and deletes extensions.json if any appear. --- chrome/content/zotero/xpcom/prefs.js | 17 +++++++++++++++++ chrome/content/zotero/xpcom/zotero.js | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/chrome/content/zotero/xpcom/prefs.js b/chrome/content/zotero/xpcom/prefs.js index 3e9aaff3b4..4e9605f463 100644 --- a/chrome/content/zotero/xpcom/prefs.js +++ b/chrome/content/zotero/xpcom/prefs.js @@ -389,6 +389,23 @@ Zotero.Prefs = new function(){ try { let path = OS.Path.fromFileURI(addon.getResourceURI().spec); + // Hack to delete extensions.json for Mac users who first ran Zotero from the + // disk image and ended up with invalid integration plugin paths in + // extensions.json + try { + if (Zotero.isMac && path.includes('AppTranslocation')) { + await OS.File.remove( + OS.Path.join(Zotero.Profile.dir, 'extensions.json'), + { + ignoreAbsent: true + } + ); + } + } + catch (e) { + Zotero.logError(e); + } + // Directory if ((await OS.File.stat(path)).isDir) { let dir = OS.Path.join(path, 'defaults', 'preferences'); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 83f2904e35..9e66e2a825 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1816,6 +1816,21 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); Zotero.getString('general.quitApp', Zotero.clientName), null, null, null, {} ); + + // If the integration plugins were installed from the AppTranslocation path, delete + // extensions.json + try { + let file = OS.Path.join(Zotero.Profile.dir, 'extensions.json'); + let json = JSON.parse(Zotero.File.getContents(file)); + if (json.addons.some(x => x.path.includes('AppTranslocation'))) { + file = Zotero.File.pathToFile(file); + file.remove(null); + } + } + catch (e) { + Zotero.logError(e); + } + Zotero.Utilities.Internal.quit(); return false; }