Index: ext/background.js |
=================================================================== |
--- a/ext/background.js |
+++ b/ext/background.js |
@@ -312,16 +312,26 @@ |
chrome.tabs.onActivated.addListener(details => |
{ |
ext.pages.onActivated._dispatch(new Page({id: details.tabId})); |
}); |
/* Browser actions */ |
+ // On Firefox for Android, open the options page directly when the browser |
+ // action is clicked. |
+ if (!("getPopup" in chrome.browserAction)) |
Manish Jethani
2017/08/16 00:44:45
We're checking for browserAction.getPopup, i.e. wh
|
+ { |
+ chrome.browserAction.onClicked.addListener(() => |
+ { |
+ ext.showOptions(); |
+ }); |
+ } |
+ |
let BrowserAction = function(tabId) |
{ |
this._tabId = tabId; |
this._changes = null; |
}; |
BrowserAction.prototype = { |
_applyChanges() |
{ |
@@ -660,19 +670,25 @@ |
{ |
chrome.storage.local.remove(key, callback); |
}, |
onChanged: chrome.storage.onChanged |
}; |
/* Options */ |
- if ("openOptionsPage" in chrome.runtime) |
+ ext.showOptions = callback => |
Manish Jethani
2017/08/16 00:44:44
Note that now it's one function with the if...else
|
{ |
- ext.showOptions = callback => |
+ let {application} = require("info"); |
+ |
+ if ("openOptionsPage" in chrome.runtime && |
+ // Firefox for Android does have a runtime.openOptionsPage but it |
+ // doesn't do anything. |
+ application && application != "unknown" && |
+ application != "fennec") |
Wladimir Palant
2017/08/17 12:21:21
This value comes from browser's internal data, not
Manish Jethani
2017/08/17 13:21:26
This information is fetched asynchronously, it may
Sebastian Noack
2017/08/18 10:13:47
The functionality here is triggered by user intera
Manish Jethani
2017/08/18 14:20:30
This can be mitigated by adding an additional chec
|
{ |
if (!callback) |
{ |
chrome.runtime.openOptionsPage(); |
} |
else |
{ |
chrome.runtime.openOptionsPage(() => |
@@ -687,58 +703,56 @@ |
if (tabs[0].status == "complete") |
callback(new Page(tabs[0])); |
else |
afterTabLoaded(callback)(tabs[0]); |
} |
}); |
}); |
} |
- }; |
- } |
- else |
- { |
- // Edge does not yet support runtime.openOptionsPage (tested version 38) |
- // and so this workaround needs to stay for now. |
- // We are not using extension.getURL to get the absolute path here |
- // because of the Edge issue: |
- // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10276332/ |
- ext.showOptions = callback => |
+ } |
+ else |
{ |
+ // Edge does not yet support runtime.openOptionsPage (tested version 38) |
+ // nor does Firefox for Android, |
+ // and so this workaround needs to stay for now. |
+ // We are not using extension.getURL to get the absolute path here |
+ // because of the Edge issue: |
+ // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10276332/ |
chrome.windows.getLastFocused(win => |
{ |
let optionsUrl = "options.html"; |
let queryInfo = {url: optionsUrl}; |
// extension pages can't be accessed in incognito windows. In order to |
// correctly mimic the way in which Chrome opens extension options, |
// we have to focus the options page in any other window. |
if (!win.incognito) |
queryInfo.windowId = win.id; |
chrome.tabs.query(queryInfo, tabs => |
{ |
- if (tabs.length > 0) |
+ if (tabs && tabs.length > 0) |
Manish Jethani
2017/08/16 00:44:44
Firefox returns null instead of an empty array.
|
{ |
let tab = tabs[0]; |
chrome.windows.update(tab.windowId, {focused: true}); |
chrome.tabs.update(tab.id, {active: true}); |
if (callback) |
callback(new Page(tab)); |
} |
else |
{ |
ext.pages.open(optionsUrl, callback); |
} |
}); |
}); |
- }; |
- } |
+ } |
+ }; |
/* Windows */ |
ext.windows = { |
create(createData, callback) |
{ |
chrome.windows.create(createData, createdWindow => |
{ |
afterTabLoaded(callback)(createdWindow.tabs[0]); |