Skip to content

Commit 4f1ffd6

Browse files
committed
Add new autoremember-timer-minutes setting (#316)
1 parent 0798d37 commit 4f1ffd6

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

app/common/setting-definitions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ _VAL[_NAM.CFGS_FAVICON_SOURCE] = (v) => {
188188
: undefined;
189189
};
190190

191+
// #316. How often to autoremember. Empty or <= 0 == don't autosave
192+
_NAM.CFGS_AUTOREMEMBER_MINUTES = "autoremember-timer-minutes";
193+
_DEF[_NAM.CFGS_AUTOREMEMBER_MINUTES] = "0";
194+
_VAL[_NAM.CFGS_AUTOREMEMBER_MINUTES] = _vint;
195+
191196
// }}}2
192197

193198
// 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
@@ -226,6 +226,15 @@ setting_definitions.push(
226226
"type": "checkbox",
227227
"label": future_i18n('Prompt for confirmation before closing or deleting a tab that is currently playing audio (<i class="fa fa-music"></i>)'),
228228
},
229+
{
230+
"tab": future_i18n("Behaviour"),
231+
"group": future_i18n("Autoremember"),
232+
"name": S.S_AUTOREMEMBER_MINUTES,
233+
"type": "text",
234+
"label": future_i18n('If this is an integer <tt>I</tt> &gt;= 0, automatically '
235+
+ 'remember all open windows/tabs every <tt>I</tt> minutes. Refresh the '
236+
+ 'TabFern window to apply changes to this option.'),
237+
},
229238

230239
// Appearance
231240
{
@@ -501,6 +510,9 @@ setting_definitions.push(
501510
"text":
502511
`
503512
<ul>
513+
<li>TabFern can now automatically mark windows as remembered on a timer.
514+
Set the timer you want in ${settings} Behaviour ${gt} Autoremember
515+
${issue(316)}.</li>
504516
</ul>
505517
`
506518
},

app/win/main_tl.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4510,6 +4510,49 @@ function addEventListeners(done) {
45104510
done();
45114511
} //addEventListeners
45124512

4513+
// Mark all windows as remembered
4514+
function rememberAll() {
4515+
var modified = false;
4516+
L.log.info("Marking all windows as remembered");
4517+
try {
4518+
const root = T.treeobj.get_node($.jstree.root);
4519+
root.children.forEach((kid_node_id, kid_idx) => {
4520+
const val = D.windows.by_node_id(kid_node_id);
4521+
if (val && val.keep !== K.WIN_KEEP) {
4522+
modified = true;
4523+
M.remember(kid_node_id);
4524+
}
4525+
});
4526+
} catch (e) {
4527+
log.warn({ "Failure when trying to auto-remember windows": e });
4528+
// But don't throw the error since we still want to save the tree.
4529+
}
4530+
4531+
if (modified) {
4532+
saveTree();
4533+
}
4534+
} //rememberAll
4535+
4536+
// Timer handler to call rememberAll() and set the next timer.
4537+
function autoRememberAll(minutes, only_start_timer = false) {
4538+
if (!only_start_timer) {
4539+
rememberAll();
4540+
}
4541+
4542+
L.log.info(`Starting autoremember timer for ${minutes} minute(s)`);
4543+
window.setTimeout(() => {
4544+
autoRememberAll(minutes);
4545+
}, minutes * 60 * 1000);
4546+
} // autoRememberAll
4547+
4548+
function startAutoRememberTimerIfRequested(done) {
4549+
const minutes = S.getInt(S.S_AUTOREMEMBER_MINUTES, 0);
4550+
if (minutes > 0) {
4551+
autoRememberAll(minutes, true); // true => just start the timer
4552+
}
4553+
done();
4554+
} // startAutoRememberTimerIfRequested()
4555+
45134556
/// The last function to be called after all other initialization has
45144557
/// completed successfully.
45154558
function initTreeFinal(done) {
@@ -4620,6 +4663,8 @@ function main() {
46204663
if (spinner) spinner.spin($("#tabfern-container")[0]);
46214664
};
46224665

4666+
// --- Init steps ---
4667+
46234668
s.then(determine_devel_mode)
46244669
.then(basicInit)
46254670

@@ -4646,16 +4691,23 @@ function main() {
46464691
})
46474692
.then(addOpenWindowsToTree)
46484693
.then(addEventListeners)
4649-
.then(initTreeFinal)
4694+
.then(initTreeFinal) // This needs to be the last real init step
4695+
4696+
.val(check_init_step_count) // This is a sanity check after initTreeFinal
46504697

4651-
.val(check_init_step_count)
4698+
// --- Post-init steps ---
46524699

46534700
// Stop the spinner, if it started
46544701
.val(() => {
46554702
spinner.stop();
46564703
spinner = null;
46574704
})
46584705

4706+
// Start the autoremember timer now that all the state is consistent
4707+
.then(startAutoRememberTimerIfRequested)
4708+
4709+
// --- Error handling ---
4710+
46594711
.or((err) => {
46604712
$(K.INIT_MSG_SEL).text($(K.INIT_MSG_SEL).text() + "\n" + err);
46614713

0 commit comments

Comments
 (0)