diff --git a/tabfern/js/asq-helpers.js b/tabfern/js/asq-helpers.js index 89f39d30..b585d116 100755 --- a/tabfern/js/asq-helpers.js +++ b/tabfern/js/asq-helpers.js @@ -72,7 +72,38 @@ let chrcbk = module.CCgo(seq); do_right_now(chrcbk); return seq; - } //ASQ.NOW() + } //ASQ.NowCC() + + /// Take action on this tick, and kick off a sequence based on a Chrome + /// callback, as if called with ASQ.try. + /// @param do_right_now {function} Called as do_right_now(chrome_cbk). + /// Should cause chrome_cbk to be invoked + /// when the sequence should proceed. + /// @return A sequence to chain off. + module.NowCCTry = function(do_right_now) { + // Inner sequence that provides the Chrome callback and the + // try/catch functionality + let inner_seq = ASQ(); + let inner_chrcbk = module.CCgo(inner_seq); + + // Outer sequence that we will return + let outer_seq = ASQ().duplicate(); //paused + + // When inner_seq finishes, run outer_seq. There must be a + // better way to do this, but I don't know what it is. You can't + // put a .then() after a .or(), as far as I know. + inner_seq.val((...args)=>{ + outer_seq.unpause(...args); + }) + .or((failure)=>{ // like ASQ().try() + outer_seq.unpause( { 'catch': failure } ); + }); + + // Kick it off + do_right_now(inner_chrcbk); + + return outer_seq; + } //ASQ.NowCCTry() /// Check for an asynquence-contrib try() error return module.is_asq_try_err = function(o) diff --git a/tabfern/src/view/tree.js b/tabfern/src/view/tree.js index 813c9ed6..5bb30c10 100755 --- a/tabfern/src/view/tree.js +++ b/tabfern/src/view/tree.js @@ -645,6 +645,33 @@ function actionEditBullet(node_id, node, unused_action_id, unused_action_el) saveTree(); } //actionEditBullet +/// Delete a tab's entry in the tree. +/// @param node_id {string} the ID of the node to delete +/// @param node the node to delete +/// @param evt {Event} (optional) If truthy, the event that triggered the action +/// @param is_internal {Boolean} (optional) If truthy, this is an internal +/// action, so don't prompt for confirmation. +function actionDeleteTab(node_id, node, unused_action_id, unused_action_el, + evt, is_internal) +{ + let tab_val = D.tabs.by_node_id(node_id); + if(!tab_val || !tab_val.tab_id) return; + + // TODO RESUME HERE +// ASQH.NowCCTry((cc)=>{ +// chrome.tabs.remove(tab_val.tab_id, cc) +// }) +// .then((done_or_err)=>{ +// // Check if the tab still exists. If it had a beforeunload and +// // the user hit "Stay", it will still be there. +// // Even if there is a beforeunload popup, it appears that +// // chrome.runtime.lastError does not show any error. Therefore, +// // we cannot rely on the error state to tell us whether the tab +// // is actually closed. +// }); + +} //actionDeleteTab + ////////////////////////////////////////////////////////////////////////// }}}1 // Tree-node creation // {{{1