Skip to content

Commit

Permalink
Very basic Firefox support (#100)
Browse files Browse the repository at this point in the history
None of the icons are visible, but you can save windows and restore them
from the TabFern window.
  • Loading branch information
Chris White committed Aug 6, 2018
1 parent f7daf7a commit 1768ec0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
4 changes: 4 additions & 0 deletions tabfern/src/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ const CFG_DEFAULTS = {
// Chrome code. Hopefully in the future I can test for null/undefined
// in either browser, and get rid of this block.

BROWSER_TYPE=null; // unknown

(function(win){
let isLastError_chrome =
()=>{return (typeof(chrome.runtime.lastError) !== 'undefined');};
Expand All @@ -104,6 +106,7 @@ const CFG_DEFAULTS = {
(info)=>{ // fullfillment
if(info.name === 'Firefox') {
win.isLastError = isLastError_firefox;
BROWSER_TYPE = 'ff';
} else {
win.isLastError = isLastError_chrome;
}
Expand All @@ -114,6 +117,7 @@ const CFG_DEFAULTS = {
}
);
} else { // Chrome
BROWSER_TYPE = 'chrome';
win.isLastError = isLastError_chrome;
}
})(window);
Expand Down
49 changes: 37 additions & 12 deletions tabfern/src/view/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,10 +1479,22 @@ function treeOnSelect(_evt_unused, evt_data)
}

if(is_tab && node_val.isOpen) { // An open tab
chrome.tabs.highlight({
windowId: node_val.win_id,
tabs: [node_val.index] // Jump to the clicked-on tab
}, ignore_chrome_error);

if(BROWSER_TYPE === 'ff') {
ASQ().promise(
browser.tabs.update(node_val.tab_id,{active:true})
)
.or((err)=>{
log.warn({"Could not highlight tab":node_val,err});
});

} else { //Chrome
chrome.tabs.highlight({
windowId: node_val.win_id,
tabs: [node_val.index] // Jump to the clicked-on tab
}, ignore_chrome_error);
}

//log.info('flagging treeonselect' + node.id);
T.treeobj.flag_node(node);
win_id = node_val.win_id;
Expand Down Expand Up @@ -1522,20 +1534,31 @@ function treeOnSelect(_evt_unused, evt_data)
for(let child_id of win_node.children) {
let child_val = D.tabs.by_node_id(child_id);
urls.push(child_val.raw_url);
// TODO: in Firefox, you can't call window.create with a URL of
// about:addons or about:debugging.
}

// Open the window
window_is_being_restored = true;
let create_data = {
url: urls
, left: newWinSize.left
, top: newWinSize.top
, width: newWinSize.width
, height: newWinSize.height
}
if(BROWSER_TYPE !== 'ff') {
create_data.focused = true;
}
log.info({'Creating window': create_data});

chrome.windows.create(
{
url: urls
, focused: true
, left: newWinSize.left
, top: newWinSize.top
, width: newWinSize.width
, height: newWinSize.height
},
create_data,
function(cwin) {
// TODO: in Firefox, I'm not sure if this gets called after
// an error. Try to open a saved window with a tab
// for about:addons or about:debugging to trigger an error.

// Note: In testing, this happens after the winOnCreated,
// tabOnCreated, and tabOnActivated events. I don't know
// if that's guaranteed, though.
Expand Down Expand Up @@ -3864,6 +3887,8 @@ function main(...args)
let s = ASQ();
callbackOnLoad(s.errfcb());
$(K.INIT_PROGRESS_SEL).text("waiting for browser");
// Note: on one test on Firefox, the rest of the chain never fired.
// Not sure why.

s.then(basicInit)
.try((done)=>{
Expand Down

0 comments on commit 1768ec0

Please sign in to comment.