diff --git a/app/common/setting-definitions.js b/app/common/setting-definitions.js index 8638960..1d0cfe6 100644 --- a/app/common/setting-definitions.js +++ b/app/common/setting-definitions.js @@ -25,6 +25,15 @@ let _VAL = { __proto__: null }; /// The default validator for bool values let _vbool = (v)=>{ return ((typeof v === 'boolean')?v:undefined)}; +/// The default validator for integer values +let _vint = (v)=>{ + const num = Number(v); + if(isNaN(num) || (Math.trunc(num) != num)) { + return undefined; + } + return num; +}; + // Booleans {{{2 _NAM.CFG_POPUP_ON_STARTUP = 'open-popup-on-chrome-startup'; _DEF[_NAM.CFG_POPUP_ON_STARTUP] = true; @@ -165,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. @@ -238,6 +253,33 @@ function getBoolSetting(setting_name, default_value = undefined) } } //getBoolSetting +/// Get an integer setting from the settings page. +/// @param setting_name A value in CFG_NAMES +/// @param default_value Optional default. If unspecified or +/// undefined, the default from CFG_DEFAULTS +/// is used. +function getIntSetting(setting_name, default_value = undefined) +{ + if(typeof default_value === 'undefined' && setting_name in CFG_DEFAULTS) { + default_value = CFG_DEFAULTS[setting_name]; + } + + let locStorageValue = localStorage.getItem(SETTING_PREFIX + setting_name); + + if ( locStorageValue === null ) { // nonexistent key + return default_value; + } else { + const str = String(locStorageValue); + let val = JSON.parse(locStorageValue); // stored with double-quotes + val = _vint(val); + if (typeof val === 'undefined') { + return default_value; + } else { + return val; + } + } +} //getIntSetting + /// Find out whether the given setting from the settings page exists. /// @param setting_name A value in CFG_NAMES function haveSetting(setting_name) @@ -302,6 +344,7 @@ let me = { getRaw: getRawSetting, getString: getStringSetting, getBool: getBoolSetting, + getInt: getIntSetting, have: haveSetting, set: setSetting, setIfNonexistent: setSettingIfNonexistent, diff --git a/app/settings/manifest.js b/app/settings/manifest.js index 7c8e478..04fbe2b 100644 --- a/app/settings/manifest.js +++ b/app/settings/manifest.js @@ -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 ()'), }, + { + "tab": future_i18n("Behaviour"), + "group": future_i18n("Autoremember"), + "name": S.S_AUTOREMEMBER_MINUTES, + "type": "text", + "label": future_i18n('If this is an integer I >= 0, automatically ' + + 'remember all open windows/tabs every I minutes. Refresh the ' + + 'TabFern window to apply changes to this option.'), + }, // Appearance { @@ -489,7 +498,16 @@ setting_definitions.push( 'group_html':true, "type": "description", "text": ( -`
As you've noticed, my time to work on TabFern is limited 😅 . +If you are a JavaScript developer, could you contribute some code? I'm happy +to help you get started! If you aren't a JS dev, but know someone who is, +could you please pass the word? Much appreciated! +
+