Skip to content

Commit

Permalink
Better init-error reporting
Browse files Browse the repository at this point in the history
In support of #123.  When init fails, report the error message (if any),
and which step it was on.
  • Loading branch information
Chris White committed May 9, 2018
1 parent 4f963c8 commit 3e8512b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions tabfern/src/view/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
INIT_TIME_ALLOWED_MS: 3000, // After this time, if init isn't done,
// display an error message.
INIT_MSG_SEL: 'div#init-incomplete', // Selector for that message
INIT_PROGRESS_SEL: 'div#init-progress', // Selector for the x/y progress indicator

ACTION_GROUP_WIN_CLASS: 'tf-action-group', // Class on action-group div
ACTION_BUTTON_WIN_CLASS: 'tf-action-button', // Class on action buttons (<i>)
Expand Down
5 changes: 5 additions & 0 deletions tabfern/src/view/tree.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
color: #f33;
}

#init-progress {
display: none; /* initially */
color: #f33;
}

li.ephemeral-recovered, .tfs-recovered {
background: darkslategray !important;
}
Expand Down
5 changes: 4 additions & 1 deletion tabfern/src/view/tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@

<div id="tabfern-container">

<!-- Error messages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<div id="init-incomplete">Initialization not complete (or not yet
complete). Changes will not be saved.
</div><!-- hidden if init does complete. -->
</div>
<div id="init-progress"></div>
<!-- the above two divs are removed if init does complete. -->

<!-- Content ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<div id="maintree"></div><!-- the window tree -->
Expand Down
43 changes: 39 additions & 4 deletions tabfern/src/view/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,10 @@ var loadSavedWindowsFromData = (function(){
/// @param {function} next_action If provided, will be called when loading
/// is complete.
function loadSavedWindowsIntoTree(next_action) {
$(K.INIT_PROGRESS_SEL).text("5/13");

chrome.storage.local.get(K.STORAGE_KEY, function(items) {
$(K.INIT_PROGRESS_SEL).text("6/13");

READIT:
if(isLastError()) {
Expand Down Expand Up @@ -3578,6 +3581,7 @@ let custom_bg_color = false;
/// Initialization that happens before the full DOM is loaded
function preLoadInit()
{
$(K.INIT_PROGRESS_SEL).text("1/13");
if(getBoolSetting(CFG_HIDE_HORIZONTAL_SCROLLBARS)) {
document.querySelector('html').classList += ' tf--feature--hide-horizontal-scrollbars';
}
Expand Down Expand Up @@ -3662,6 +3666,7 @@ function preLoadInit()
/// Beginning of the onload initialization.
function basicInit(done)
{
$(K.INIT_PROGRESS_SEL).text("2/13");
log.info('TabFern tree.js initializing view - ' + TABFERN_VERSION);

Hamburger = Modules.hamburger('#hamburger-menu', getHamburgerMenuItems
Expand Down Expand Up @@ -3694,6 +3699,7 @@ function basicInit(done)
/// Called after ASQ.try(chrome.runtime.sendMessage)
function createMainTreeIfWinIdReceived_catch(done, win_id_msg_or_error)
{
$(K.INIT_PROGRESS_SEL).text("4/13");
if(ASQH.is_asq_try_err(win_id_msg_or_error)) {
// This is fatal
return done.fail("Couldn't get win ID: " + win_id_msg_or_error.catch);
Expand Down Expand Up @@ -3737,6 +3743,7 @@ function createMainTreeIfWinIdReceived_catch(done, win_id_msg_or_error)
drivers: [Modules.dmauro_keypress]
},
function initialized(err) {
$(K.INIT_PROGRESS_SEL).text("5/13");
if ( err ) {
console.log({['Failed loading a shortcut driver! Initializing '+
'context menu with no shortcut driver']:err});
Expand All @@ -3752,6 +3759,7 @@ function createMainTreeIfWinIdReceived_catch(done, win_id_msg_or_error)

function addOpenWindowsToTree(done, cwins)
{
$(K.INIT_PROGRESS_SEL).text("8/13");
let dat = {};
let focused_win_id;

Expand Down Expand Up @@ -3796,6 +3804,7 @@ function addOpenWindowsToTree(done, cwins)

function addEventListeners(done)
{
$(K.INIT_PROGRESS_SEL).text("9/13");
// At this point, the saved and open windows have been loaded into the
// tree. Therefore, we can position the action groups. We already
// saved the position, so do not need to specify it here.
Expand Down Expand Up @@ -3870,6 +3879,7 @@ function moveWinToLastPositionIfAny_catch(done, items_or_err)
// If there was an error (e.g., nonexistent key), just
// accept the default size.

$(K.INIT_PROGRESS_SEL).text("11/13");
if(!ASQH.is_asq_try_err(items_or_err)) {
let parsed = items_or_err[K.LOCN_KEY];
if( (parsed !== null) && (typeof parsed === 'object') ) {
Expand Down Expand Up @@ -3899,12 +3909,17 @@ function moveWinToLastPositionIfAny_catch(done, items_or_err)
/// completed successfully.
function initTreeFinal(done)
{
//return; // DEBUG - don't save
$(K.INIT_PROGRESS_SEL).text("12/13");

// Tests of different ways of failing init - for debugging only
//throw new Error("oops"); // DEBUG
//return; // DEBUG - don't save

if(!was_loading_error) {
did_init_complete = true;
// Assume the document is loaded by this point.
$(K.INIT_MSG_SEL).css('display','none');
$(K.INIT_MSG_SEL).remove();
$(K.INIT_PROGRESS_SEL).remove();
// just in case initialization took a long time, and the message
// already appeared.

Expand Down Expand Up @@ -3944,7 +3959,17 @@ function initIncompleteWarning()
{
if(!did_init_complete) {
// Assume the document is loaded by this point.
$(K.INIT_MSG_SEL).css('display','block');
if(K && K.INIT_MSG_SEL) {
$(K.INIT_MSG_SEL).css('display','block');
} else {
window.setTimeout(initIncompleteWarning, 500);
}

if(K && K.INIT_PROGRESS_SEL) {
$(K.INIT_PROGRESS_SEL).css('display','block');
} else {
window.setTimeout(initIncompleteWarning, 500);
}
}
} //initIncompleteWarning()

Expand All @@ -3965,6 +3990,8 @@ function main(...args)

local_init();

$(K.INIT_PROGRESS_SEL).text("0/13");

// Timer to display the warning message if initialization doesn't complete
// quickly enough.
window.setTimeout(initIncompleteWarning, K.INIT_TIME_ALLOWED_MS);
Expand All @@ -3980,28 +4007,36 @@ function main(...args)
// Run the main init steps once the page has loaded
let s = ASQ();
callbackOnLoad(s.errfcb());
$(K.INIT_PROGRESS_SEL).text("waiting for browser");

s.then(basicInit)
.try((done)=>{
// Get our Chrome-extensions-API window ID from the background page.
// I don't know a way to get this directly from the JS window object.
// TODO maybe getCurrent? Not sure if that's reliable.
$(K.INIT_PROGRESS_SEL).text("3/13");
chrome.runtime.sendMessage({msg:MSG_GET_VIEW_WIN_ID}, ASQH.CC(done));
})
.then(createMainTreeIfWinIdReceived_catch)
.then(loadSavedWindowsIntoTree)
.then((done)=>{
$(K.INIT_PROGRESS_SEL).text("7/13");
chrome.windows.getAll({'populate': true}, ASQH.CC(done));
})
.then(addOpenWindowsToTree)
.then(addEventListeners)
.try((done)=>{
$(K.INIT_PROGRESS_SEL).text("10/13");
// Find out where the view was before, if anywhere
chrome.storage.local.get(K.LOCN_KEY, ASQH.CC(done));
})
.then(moveWinToLastPositionIfAny_catch)
.then(initTreeFinal)
//.or(TODO show "couldn't load" in the popup)
.or((err)=>{
$(K.INIT_MSG_SEL).text(
$(K.INIT_MSG_SEL).text() + "\n" + err
)
});
;

} // main()
Expand Down

0 comments on commit 3e8512b

Please sign in to comment.