From 1768ec08de8386e537cad7c3813ff22baceddb4e Mon Sep 17 00:00:00 2001 From: Chris White Date: Mon, 6 Aug 2018 15:32:04 -0400 Subject: [PATCH] Very basic Firefox support (#100) None of the icons are visible, but you can save windows and restore them from the TabFern window. --- tabfern/src/common/common.js | 4 +++ tabfern/src/view/tree.js | 49 +++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/tabfern/src/common/common.js b/tabfern/src/common/common.js index 0ff099e9..c2058e61 100755 --- a/tabfern/src/common/common.js +++ b/tabfern/src/common/common.js @@ -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');}; @@ -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; } @@ -114,6 +117,7 @@ const CFG_DEFAULTS = { } ); } else { // Chrome + BROWSER_TYPE = 'chrome'; win.isLastError = isLastError_chrome; } })(window); diff --git a/tabfern/src/view/tree.js b/tabfern/src/view/tree.js index d4f744e2..57a0fe62 100755 --- a/tabfern/src/view/tree.js +++ b/tabfern/src/view/tree.js @@ -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; @@ -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. @@ -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)=>{