From 400f0f498ee8d54028621ae5b24493425ac3ef21 Mon Sep 17 00:00:00 2001 From: Lewis Liu Date: Thu, 28 Apr 2016 00:47:58 -0700 Subject: [PATCH 1/5] Fixed chrome version failing after restart --- chrome/just-save.js | 62 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/chrome/just-save.js b/chrome/just-save.js index 6cd3c83..c9d6e83 100644 --- a/chrome/just-save.js +++ b/chrome/just-save.js @@ -20,46 +20,44 @@ browser.runtime.onInstalled.addListener(event => { browser.contextMenus.removeAll(result => { logResult(result); - const handleMenuClick = clickContext => { - if (clickContext.menuItemId !== 'just-save') { - return; - } - - const url = clickContext.srcUrl || clickContext.linkUrl || clickContext.pageUrl; - - if (!url) { - return console.error(`No url found for current click context`); - } - - const filename = undefined; - - const downloadOptions = { - url, - filename - // filename, - // conflictAction: 'prompt', //not implemented yet in firefox, defaults to uniquify - // saveAs: false //not implemented yet in firefox, defaults to false - }; - - browser.downloads.download( - downloadOptions, - logResult - ); - }; - const menuProperties = { id: 'just-save', title: 'Just Save', contexts: ['all'] }; - + browser.contextMenus.create( menuProperties, logResult ); - - // FIXME: appears to stop working after restarting chrome - // might need to add another listener for a different event - browser.contextMenus.onClicked.addListener(handleMenuClick); }); }); + +const handleMenuClick = clickContext => { + if (clickContext.menuItemId !== 'just-save') { + return; + } + + const url = clickContext.srcUrl || clickContext.linkUrl || clickContext.pageUrl; + + if (!url) { + return console.error(`No url found for current click context`); + } + + const filename = undefined; + + const downloadOptions = { + url, + filename + // filename, + // conflictAction: 'prompt', //not implemented yet in firefox, defaults to uniquify + // saveAs: false //not implemented yet in firefox, defaults to false + }; + + browser.downloads.download( + downloadOptions, + logResult + ); +}; + +browser.contextMenus.onClicked.addListener(handleMenuClick); \ No newline at end of file From 0394f3fae135de63393761a3f6fbec8fe7deed06 Mon Sep 17 00:00:00 2001 From: Lewis Liu Date: Thu, 28 Apr 2016 00:51:49 -0700 Subject: [PATCH 2/5] Tentatively reverting to addListener for firefox --- firefox/just-save.js | 72 +++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/firefox/just-save.js b/firefox/just-save.js index 515e262..55fee80 100644 --- a/firefox/just-save.js +++ b/firefox/just-save.js @@ -12,52 +12,50 @@ const logResult = result => { browser.contextMenus.removeAll(result => { logResult(result); - const handleMenuClick = clickContext => { - if (clickContext.menuItemId !== 'just-save') { - return; - } - - const url = clickContext.srcUrl || clickContext.linkUrl || clickContext.pageUrl; - - if (!url) { - return console.error(`No url found for current click context`); - } - - // need to specify filename for non-image contexts to workaround firefox name bug - // TODO: document this bug and report on https://discourse.mozilla-community.org/c/add-ons/development - const filename = clickContext.srcUrl ? - undefined : - clickContext.linkUrl ? 'link.htm' : 'page.htm'; - - const downloadOptions = { - url, - filename - // filename, - // conflictAction: 'prompt', //not implemented yet in firefox, defaults to uniquify - // saveAs: false //not implemented yet in firefox, defaults to false - }; - - browser.downloads.download( - downloadOptions, - logResult - ); - }; - const menuProperties = { id: 'just-save', title: 'Just Save', // contexts: ['all'] contexts: ['all'], - // workaround for onClick.addListener bug below - onclick: handleMenuClick + // // workaround for onClick.addListener bug below + // onclick: handleMenuClick }; browser.contextMenus.create( menuProperties, logResult ); - - // doesn't seem to work? - // TODO: report as a bug - // browser.contextMenus.onClicked.addListener(handleMenuClick); }); + +const handleMenuClick = clickContext => { + if (clickContext.menuItemId !== 'just-save') { + return; + } + + const url = clickContext.srcUrl || clickContext.linkUrl || clickContext.pageUrl; + + if (!url) { + return console.error(`No url found for current click context`); + } + + // need to specify filename for non-image contexts to workaround firefox name bug + // TODO: document this bug and report on https://discourse.mozilla-community.org/c/add-ons/development + const filename = clickContext.srcUrl ? + undefined : + clickContext.linkUrl ? 'link.htm' : 'page.htm'; + + const downloadOptions = { + url, + filename + // filename, + // conflictAction: 'prompt', //not implemented yet in firefox, defaults to uniquify + // saveAs: false //not implemented yet in firefox, defaults to false + }; + + browser.downloads.download( + downloadOptions, + logResult + ); +}; + +browser.contextMenus.onClicked.addListener(handleMenuClick); From 6b2b19a3068346a590b3a5a8aa52dc0112888d8a Mon Sep 17 00:00:00 2001 From: Lewis Liu Date: Thu, 28 Apr 2016 00:51:59 -0700 Subject: [PATCH 3/5] Revert "Tentatively reverting to addListener for firefox" This reverts commit 0394f3fae135de63393761a3f6fbec8fe7deed06. --- firefox/just-save.js | 72 +++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/firefox/just-save.js b/firefox/just-save.js index 55fee80..515e262 100644 --- a/firefox/just-save.js +++ b/firefox/just-save.js @@ -12,50 +12,52 @@ const logResult = result => { browser.contextMenus.removeAll(result => { logResult(result); + const handleMenuClick = clickContext => { + if (clickContext.menuItemId !== 'just-save') { + return; + } + + const url = clickContext.srcUrl || clickContext.linkUrl || clickContext.pageUrl; + + if (!url) { + return console.error(`No url found for current click context`); + } + + // need to specify filename for non-image contexts to workaround firefox name bug + // TODO: document this bug and report on https://discourse.mozilla-community.org/c/add-ons/development + const filename = clickContext.srcUrl ? + undefined : + clickContext.linkUrl ? 'link.htm' : 'page.htm'; + + const downloadOptions = { + url, + filename + // filename, + // conflictAction: 'prompt', //not implemented yet in firefox, defaults to uniquify + // saveAs: false //not implemented yet in firefox, defaults to false + }; + + browser.downloads.download( + downloadOptions, + logResult + ); + }; + const menuProperties = { id: 'just-save', title: 'Just Save', // contexts: ['all'] contexts: ['all'], - // // workaround for onClick.addListener bug below - // onclick: handleMenuClick + // workaround for onClick.addListener bug below + onclick: handleMenuClick }; browser.contextMenus.create( menuProperties, logResult ); -}); - -const handleMenuClick = clickContext => { - if (clickContext.menuItemId !== 'just-save') { - return; - } - - const url = clickContext.srcUrl || clickContext.linkUrl || clickContext.pageUrl; - if (!url) { - return console.error(`No url found for current click context`); - } - - // need to specify filename for non-image contexts to workaround firefox name bug - // TODO: document this bug and report on https://discourse.mozilla-community.org/c/add-ons/development - const filename = clickContext.srcUrl ? - undefined : - clickContext.linkUrl ? 'link.htm' : 'page.htm'; - - const downloadOptions = { - url, - filename - // filename, - // conflictAction: 'prompt', //not implemented yet in firefox, defaults to uniquify - // saveAs: false //not implemented yet in firefox, defaults to false - }; - - browser.downloads.download( - downloadOptions, - logResult - ); -}; - -browser.contextMenus.onClicked.addListener(handleMenuClick); + // doesn't seem to work? + // TODO: report as a bug + // browser.contextMenus.onClicked.addListener(handleMenuClick); +}); From 564f9c9e3227b7b7eb8aab7d4f78f1e03d99f3f4 Mon Sep 17 00:00:00 2001 From: Lewis Liu Date: Thu, 28 Apr 2016 00:52:48 -0700 Subject: [PATCH 4/5] Bumping version --- chrome/manifest.json | 2 +- firefox/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome/manifest.json b/chrome/manifest.json index 6ef2c9a..a7d6c6b 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Just Save", - "version": "0.0.1", + "version": "0.0.2", "description": "A simple WebExtension for skipping the \"Save As\" dialog when saving images, pages and links.", "icons": { diff --git a/firefox/manifest.json b/firefox/manifest.json index 5c6a1fc..5d74bcc 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Just Save", - "version": "0.0.1", + "version": "0.0.2", "description": "A simple WebExtension for skipping the \"Save As\" dialog when saving images, pages and links.", "icons": { From 782c2c3384d00dec4670862955994e4933792c0e Mon Sep 17 00:00:00 2001 From: Lewis Liu Date: Thu, 28 Apr 2016 00:53:13 -0700 Subject: [PATCH 5/5] Documenting more issues --- chrome/just-save.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chrome/just-save.js b/chrome/just-save.js index c9d6e83..57af295 100644 --- a/chrome/just-save.js +++ b/chrome/just-save.js @@ -1,4 +1,10 @@ 'use strict'; +// FIXME: need to keep this on a separate codebase due to +// need for separate manifest file because persistent attribute is rejected +// https://bugzilla.mozilla.org/show_bug.cgi?id=1253565 +// should be able to revert to single codebase when Firefox 48 is released + +// FIXME: figure out how to prevent toolbar icon from being added in chrome // adding browser shim for chrome support window.browser = chrome;