Skip to content

Commit c638b55

Browse files
committed
Add new autoremember-timer-minutes setting (#316)
1 parent 6d0cfb7 commit c638b55

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

app/common/setting-definitions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ _VAL[_NAM.CFGS_FAVICON_SOURCE] = (v)=>{
180180
return (( v === FAVICON_SITE || v === FAVICON_CHROME || v === FAVICON_DDG ) ? v : undefined);
181181
};
182182

183+
// #316. How often to autoremember. Empty or <= 0 == don't autosave
184+
_NAM.CFGS_AUTOREMEMBER_MINUTES = 'autoremember-timer-minutes';
185+
_DEF[_NAM.CFGS_AUTOREMEMBER_MINUTES] = '0';
186+
_VAL[_NAM.CFGS_AUTOREMEMBER_MINUTES] = _vint;
187+
188+
183189
// }}}2
184190

185191
// The exportable format of the above objects

app/settings/manifest.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ setting_definitions.push(
216216
"type": "checkbox",
217217
"label": future_i18n('Prompt for confirmation before closing or deleting a tab that is currently playing audio (<i class="fa fa-music"></i>)'),
218218
},
219+
{
220+
"tab": future_i18n("Behaviour"),
221+
"group": future_i18n("Autoremember"),
222+
"name": S.S_AUTOREMEMBER_MINUTES,
223+
"type": "text",
224+
"label": future_i18n('If this is an integer <tt>I</tt> &gt;= 0, automatically '
225+
+ 'remember all open windows/tabs every <tt>I</tt> minutes. Refresh the '
226+
+ 'TabFern window to apply changes to this option.'),
227+
},
219228

220229
// Appearance
221230
{
@@ -507,6 +516,9 @@ could you please pass the word? Much appreciated!
507516
<ul>
508517
<li>The prompt for confirmation when closing audible tabs now applies to
509518
individual tabs ${issue(306)}.</li>
519+
<li>TabFern can now automatically mark windows as remembered on a timer.
520+
Set the timer you want in ${settings} Behaviour ${gt} Autoremember
521+
${issue(316)}.</li>
510522
<li>Bugfixes ${issue([322,335])}</li>
511523
<li>Refactoring ${issue(334)}</li>
512524
</ul>

app/win/main_tl.js

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,6 +4256,50 @@ function addEventListeners(done)
42564256
done();
42574257
} //addEventListeners
42584258

4259+
// Mark all windows as remembered
4260+
function rememberAll()
4261+
{
4262+
var modified = false;
4263+
L.log.info('Marking all windows as remembered')
4264+
try {
4265+
const root = T.treeobj.get_node($.jstree.root);
4266+
root.children.forEach( (kid_node_id, kid_idx)=>{
4267+
const val = D.windows.by_node_id(kid_node_id);
4268+
if(val && (val.keep !== K.WIN_KEEP)) {
4269+
modified = true;
4270+
M.remember(kid_node_id);
4271+
}
4272+
});
4273+
4274+
} catch(e) {
4275+
log.warn({'Failure when trying to auto-remember windows': e})
4276+
// But don't throw the error since we still want to save the tree.
4277+
}
4278+
4279+
if(modified) {
4280+
saveTree();
4281+
}
4282+
} //rememberAll
4283+
4284+
// Timer handler to call rememberAll() and set the next timer.
4285+
function autoRememberAll(minutes, only_start_timer = false)
4286+
{
4287+
if(!only_start_timer) {
4288+
rememberAll();
4289+
}
4290+
4291+
L.log.info(`Starting autoremember timer for ${minutes} minute(s)`);
4292+
window.setTimeout(()=>{autoRememberAll(minutes)}, minutes*60*1000);
4293+
} // autoRememberAll
4294+
4295+
function startAutoRememberTimerIfRequested(done) {
4296+
const minutes = S.getInt(S.S_AUTOREMEMBER_MINUTES, 0);
4297+
if(minutes > 0) {
4298+
autoRememberAll(minutes, true); // true => just start the timer
4299+
}
4300+
done();
4301+
} // startAutoRememberTimerIfRequested()
4302+
42594303
/// The last function to be called after all other initialization has
42604304
/// completed successfully.
42614305
function initTreeFinal(done)
@@ -4364,6 +4408,8 @@ function main()
43644408
if(spinner) spinner.spin($('#tabfern-container')[0]);
43654409
};
43664410

4411+
// --- Init steps ---
4412+
43674413
s.then(determine_devel_mode)
43684414
.then(basicInit)
43694415

@@ -4393,16 +4439,23 @@ function main()
43934439
})
43944440
.then(addOpenWindowsToTree)
43954441
.then(addEventListeners)
4396-
.then(initTreeFinal)
4442+
.then(initTreeFinal) // This needs to be the last real init step
4443+
4444+
.val(check_init_step_count) // This is a sanity check after initTreeFinal
43974445

4398-
.val(check_init_step_count)
4446+
// --- Post-init steps ---
43994447

44004448
// Stop the spinner, if it started
44014449
.val(()=>{
44024450
spinner.stop();
44034451
spinner = null;
44044452
})
44054453

4454+
// Start the autoremember timer now that all the state is consistent
4455+
.then(startAutoRememberTimerIfRequested)
4456+
4457+
// --- Error handling ---
4458+
44064459
.or((err)=>{
44074460
$(K.INIT_MSG_SEL).text(
44084461
$(K.INIT_MSG_SEL).text() + "\n" + err

0 commit comments

Comments
 (0)