Skip to content

Commit

Permalink
Merge pull request #2 from lewisl9029/bugfix-chrome-fails-to-respond-…
Browse files Browse the repository at this point in the history
…after-restart

Bugfix chrome fails to respond after restart
  • Loading branch information
lewisl9029 committed Apr 28, 2016
2 parents 8850b6b + 782c2c3 commit fb87d25
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
68 changes: 36 additions & 32 deletions chrome/just-save.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,46 +26,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);
2 changes: 1 addition & 1 deletion chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit fb87d25

Please # to comment.