Skip to content

Commit

Permalink
Began adding support code for close-tab (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris White committed Dec 18, 2017
1 parent 055e8e1 commit 1f1f7c4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tabfern/js/asq-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions tabfern/src/view/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1f1f7c4

Please sign in to comment.