Skip to content

Commit

Permalink
Add new autoremember-timer-minutes setting (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxw42 committed Nov 3, 2024
1 parent 59293d4 commit c8741b0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/common/setting-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ _VAL[_NAM.CFGS_FAVICON_SOURCE] = (v)=>{
return (( v === FAVICON_SITE || v === FAVICON_CHROME || v === FAVICON_DDG ) ? v : undefined);
};

// #316. How often to autoremember. Empty or <= 0 == don't autosave
_NAM.CFGS_AUTOREMEMBER_MINUTES = 'autoremember-timer-minutes';
_DEF[_NAM.CFGS_AUTOREMEMBER_MINUTES] = '';
_VAL[_NAM.CFGS_AUTOREMEMBER_MINUTES] = _vint;


// }}}2

/// The default values for the configuration settings.
Expand Down
9 changes: 9 additions & 0 deletions app/settings/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ setting_definitions.push(
"type": "checkbox",
"label": future_i18n('Prompt for confirmation before closing or deleting a tab that is currently playing audio (<i class="fa fa-music"></i>)'),
},
{
"tab": future_i18n("Behaviour"),
"group": future_i18n("Autoremember"),
"name": S.S_AUTOREMEMBER_MINUTES,
"type": "text",
"label": future_i18n('If this is an integer <tt>I</tt> &gt;= 0, automatically '
+ 'remember all open windows/tabs every <tt>I</tt> minutes. Refresh the '
+ 'TabFern window to apply changes to this option.'),
},

// Appearance
{
Expand Down
63 changes: 61 additions & 2 deletions app/win/main_tl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4301,6 +4301,56 @@ function addEventListeners(done)
done();
} //addEventListeners

// Mark all windows as remembered
function rememberAll()
{
var modified = false;
L.log.info('Marking all windows as remembered')
try {
const root = T.treeobj.get_node($.jstree.root);
root.children.forEach( (kid_node_id, kid_idx)=>{
const val = D.windows.by_node_id(kid_node_id);
if(val && (val.keep !== K.WIN_KEEP)) {
modified = true;
M.remember(kid_node_id);
}
});

} catch(e) {
log.warn({'Failure when trying to auto-remember windows': e})
// But don't throw the error since we still want to save the tree.
}

if(modified) {
saveTree();
}
} //rememberAll

// Timer handler to rememberAll() and set the next timer.
function autoRememberAll(first = false)
{
// Timer handling. Check the setting each time so that if the
// user turns off autoremember we'll stop the timer.
const minutes = S.getInt(S.S_AUTOREMEMBER_MINUTES, 0);
if(minutes <= 0) {
return;
}

L.log.info(`Starting autoremember timer for ${minutes} minutes`);
window.setTimeout(autoRememberAll, minutes*60*1000);

if(first) {
return;
}

rememberAll();
} // autoRememberAll

function startAutoRememberTimerIfRequested(done) {
autoRememberAll(true); // true => just start the timer
done();
} // startAutoRememberTimerIfRequested()

/// The last function to be called after all other initialization has
/// completed successfully.
function initTreeFinal(done)
Expand Down Expand Up @@ -4410,6 +4460,8 @@ function main()
};
//let spin_timer = window.setTimeout(spin_starter, 1000);

// --- Init steps ---

s.then(determine_devel_mode)
.then(basicInit)

Expand Down Expand Up @@ -4439,9 +4491,11 @@ function main()
})
.then(addOpenWindowsToTree)
.then(addEventListeners)
.then(initTreeFinal)
.then(initTreeFinal) // This needs to be the last real init step

.val(check_init_step_count)
.val(check_init_step_count) // This is a sanity check after initTreeFinal

// --- Post-init steps ---

// Stop the spinner, if it started
.val(()=>{
Expand All @@ -4450,6 +4504,11 @@ function main()
//clearTimeout(spin_timer);
})

// Start the autoremember timer now that all the state is consistent
.then(startAutoRememberTimerIfRequested)

// --- Error handling ---

.or((err)=>{
$(K.INIT_MSG_SEL).text(
$(K.INIT_MSG_SEL).text() + "\n" + err
Expand Down

0 comments on commit c8741b0

Please sign in to comment.