Modes: a mode that no longer matches the features reads "Custom (based on <mode>)" and offers "Re-apply <mode>"
A mode is a starting point, never a lock and never applied again on its own. modeStatus() (runtime) compares the flags with the mode's preset: custom, what re-applying turns on and off, and which of those the preset gained in an update since it was applied. mode_set keeps the preset of that moment (modes.json "preset", flag names only, bounded; forgotten when the mode changes). Settings, the first-run screen and the app menu's Mode row show Custom; Re-apply lists what it turns on and off before it writes anything; a preset that grew is mentioned once on the mode row (Review), never applied. Tests: exact match, changed by the owner, preset grew, choice made before the preset was kept.
This commit is contained in:
parent
57524ae2ff
commit
7d30df6aaa
9 changed files with 288 additions and 27 deletions
|
|
@ -794,12 +794,14 @@ async fn mode_get(webview: Webview, app: AppHandle) -> Result<ModeState, String>
|
||||||
Ok(page(&app)?.modes.clone())
|
Ok(page(&app)?.modes.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remembers the chosen mode (or none) and that the first-run screen was answered. The preset's
|
/// Remembers the chosen mode (or none), that the first-run screen was answered, and what the
|
||||||
/// flags are the shell's to apply (`features_set`); this only records the choice.
|
/// mode's preset was when it was applied (`preset`, flag names to on/off: data for the shell's
|
||||||
|
/// "custom" and "this mode has new features" notes). The preset's flags are the shell's to apply
|
||||||
|
/// (`features_set`); this only records the choice.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn mode_set(webview: Webview, app: AppHandle, mode: Option<String>, onboarded: bool) -> Result<ModeState, String> {
|
async fn mode_set(webview: Webview, app: AppHandle, mode: Option<String>, onboarded: bool, preset: Option<std::collections::BTreeMap<String, bool>>) -> Result<ModeState, String> {
|
||||||
shell_only(&webview)?;
|
shell_only(&webview)?;
|
||||||
let next = page(&app)?.modes.chosen(mode, onboarded)?;
|
let next = page(&app)?.modes.chosen(mode, onboarded, preset)?;
|
||||||
write_json(&app, MODES_FILE, &next)?;
|
write_json(&app, MODES_FILE, &next)?;
|
||||||
page(&app)?.modes = next.clone();
|
page(&app)?.modes = next.clone();
|
||||||
Ok(next)
|
Ok(next)
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,22 @@
|
||||||
//! owner started from, and whether the first-run screen was answered. A mode is a starting point:
|
//! owner started from, and whether the first-run screen was answered. A mode is a starting point:
|
||||||
//! the presets themselves are the app's (its feature table) and are applied by the shell through
|
//! the presets themselves are the app's (its feature table) and are applied by the shell through
|
||||||
//! `features_set`; native code only remembers the choice (`modes.json`), so the screen shows once.
|
//! `features_set`; native code only remembers the choice (`modes.json`), so the screen shows once.
|
||||||
|
//! With the choice it keeps what the preset was at that moment (`preset`: flag names and on/off,
|
||||||
|
//! data the shell hands over), so the shell can tell "the owner changed features" from "an update
|
||||||
|
//! made the preset larger" later. Native code never reads it and never applies anything.
|
||||||
//!
|
//!
|
||||||
//! `existing` is decided natively, once, on the first start of a version that has modes: an app
|
//! `existing` is decided natively, once, on the first start of a version that has modes: an app
|
||||||
//! data folder that already held settings belongs to someone who set the app up before. They keep
|
//! data folder that already held settings belongs to someone who set the app up before. They keep
|
||||||
//! exactly what they have, and the screen they see can be dismissed without choosing.
|
//! exactly what they have, and the screen they see can be dismissed without choosing.
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub const MODES_FILE: &str = "modes.json";
|
pub const MODES_FILE: &str = "modes.json";
|
||||||
const MAX_MODE_ID: usize = 32;
|
const MAX_MODE_ID: usize = 32;
|
||||||
|
const MAX_PRESET_FLAGS: usize = 512;
|
||||||
|
const MAX_FLAG_NAME: usize = 64;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase", default)]
|
#[serde(rename_all = "camelCase", default)]
|
||||||
|
|
@ -21,6 +28,15 @@ pub struct ModeState {
|
||||||
pub onboarded: bool,
|
pub onboarded: bool,
|
||||||
/// The app was set up before modes existed.
|
/// The app was set up before modes existed.
|
||||||
pub existing: bool,
|
pub existing: bool,
|
||||||
|
/// The chosen mode's preset as it was when it was applied (flag name to on/off). `None`: not
|
||||||
|
/// known (no mode, or a choice made by a version that did not keep it).
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub preset: Option<BTreeMap<String, bool>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A flag name: letters, digits, `.`, `-` and `_`, at most 64 characters.
|
||||||
|
fn valid_flag(name: &str) -> bool {
|
||||||
|
!name.is_empty() && name.len() <= MAX_FLAG_NAME && name.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'.' | b'-' | b'_'))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A mode id: lowercase letters, digits and `-`, starting with a letter, at most 32 characters.
|
/// A mode id: lowercase letters, digits and `-`, starting with a letter, at most 32 characters.
|
||||||
|
|
@ -34,20 +50,31 @@ pub fn valid_mode(id: &str) -> bool {
|
||||||
impl ModeState {
|
impl ModeState {
|
||||||
/// The state on the first start: nothing chosen, the screen still to be shown.
|
/// The state on the first start: nothing chosen, the screen still to be shown.
|
||||||
pub fn first_run(existing: bool) -> Self {
|
pub fn first_run(existing: bool) -> Self {
|
||||||
Self { mode: None, onboarded: false, existing }
|
Self { mode: None, onboarded: false, existing, preset: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validated(self) -> Result<Self, String> {
|
pub fn validated(self) -> Result<Self, String> {
|
||||||
if self.mode.as_deref().is_some_and(|mode| !valid_mode(mode)) {
|
if self.mode.as_deref().is_some_and(|mode| !valid_mode(mode)) {
|
||||||
return Err("VALIDATION: invalid mode".into());
|
return Err("VALIDATION: invalid mode".into());
|
||||||
}
|
}
|
||||||
|
if let Some(preset) = &self.preset {
|
||||||
|
if self.mode.is_none() || preset.len() > MAX_PRESET_FLAGS || !preset.keys().all(|name| valid_flag(name)) {
|
||||||
|
return Err("VALIDATION: invalid mode preset".into());
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What the shell may change: the chosen mode and that the screen was answered. `existing`
|
/// What the shell may change: the chosen mode, that the screen was answered, and the preset
|
||||||
/// stays what native code decided.
|
/// the mode had when it was applied. Without `preset` the stored one stays while the mode
|
||||||
pub fn chosen(&self, mode: Option<String>, onboarded: bool) -> Result<Self, String> {
|
/// stays, and is forgotten when the mode changes. `existing` stays what native code decided.
|
||||||
Self { mode, onboarded, existing: self.existing }.validated()
|
pub fn chosen(&self, mode: Option<String>, onboarded: bool, preset: Option<BTreeMap<String, bool>>) -> Result<Self, String> {
|
||||||
|
let preset = match preset {
|
||||||
|
Some(preset) => Some(preset),
|
||||||
|
None if mode == self.mode => self.preset.clone(),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
Self { mode, onboarded, existing: self.existing, preset }.validated()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,18 +95,38 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn the_shell_chooses_a_mode_but_never_what_kind_of_install_this_is() {
|
fn the_shell_chooses_a_mode_but_never_what_kind_of_install_this_is() {
|
||||||
let fresh = ModeState::first_run(false);
|
let fresh = ModeState::first_run(false);
|
||||||
assert_eq!(fresh, ModeState { mode: None, onboarded: false, existing: false });
|
assert_eq!(fresh, ModeState { mode: None, onboarded: false, existing: false, preset: None });
|
||||||
let existing = ModeState::first_run(true);
|
let existing = ModeState::first_run(true);
|
||||||
let dismissed = existing.chosen(None, true).unwrap();
|
let dismissed = existing.chosen(None, true, None).unwrap();
|
||||||
assert_eq!(dismissed, ModeState { mode: None, onboarded: true, existing: true }, "dismissed without choosing: nothing else changes");
|
assert_eq!(dismissed, ModeState { mode: None, onboarded: true, existing: true, preset: None }, "dismissed without choosing: nothing else changes");
|
||||||
let chosen = dismissed.chosen(Some("power".into()), true).unwrap();
|
let chosen = dismissed.chosen(Some("power".into()), true, None).unwrap();
|
||||||
assert_eq!(chosen.mode.as_deref(), Some("power"));
|
assert_eq!(chosen.mode.as_deref(), Some("power"));
|
||||||
assert!(chosen.existing);
|
assert!(chosen.existing);
|
||||||
assert!(existing.chosen(Some("<script>".into()), true).is_err());
|
assert!(existing.chosen(Some("<script>".into()), true, None).is_err());
|
||||||
// The file reads back; missing fields take the defaults; unknown input never panics.
|
// The file reads back; missing fields take the defaults; unknown input never panics.
|
||||||
let json = serde_json::to_string(&chosen).unwrap();
|
let json = serde_json::to_string(&chosen).unwrap();
|
||||||
assert_eq!(json, r#"{"mode":"power","onboarded":true,"existing":true}"#);
|
assert_eq!(json, r#"{"mode":"power","onboarded":true,"existing":true}"#);
|
||||||
assert_eq!(serde_json::from_str::<ModeState>("{}").unwrap(), ModeState::default());
|
assert_eq!(serde_json::from_str::<ModeState>("{}").unwrap(), ModeState::default());
|
||||||
assert!(serde_json::from_str::<ModeState>(r#"{"mode":"BAD MODE"}"#).unwrap().validated().is_err());
|
assert!(serde_json::from_str::<ModeState>(r#"{"mode":"BAD MODE"}"#).unwrap().validated().is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_preset_of_the_moment_is_kept_with_the_choice() {
|
||||||
|
let preset = |pairs: &[(&str, bool)]| pairs.iter().map(|(name, on)| (name.to_string(), *on)).collect::<BTreeMap<_, _>>();
|
||||||
|
let start = ModeState::first_run(false);
|
||||||
|
let chosen = start.chosen(Some("advanced".into()), true, Some(preset(&[("reader.readMarker", true), ("area.chat", false)]))).unwrap();
|
||||||
|
assert_eq!(serde_json::to_string(&chosen).unwrap(), r#"{"mode":"advanced","onboarded":true,"existing":false,"preset":{"area.chat":false,"reader.readMarker":true}}"#);
|
||||||
|
// The same mode again without a preset: what is stored stays. Another mode without one: forgotten.
|
||||||
|
assert_eq!(chosen.chosen(Some("advanced".into()), true, None).unwrap().preset, chosen.preset);
|
||||||
|
assert_eq!(chosen.chosen(Some("basic".into()), true, None).unwrap().preset, None);
|
||||||
|
assert_eq!(chosen.chosen(Some("advanced".into()), true, Some(preset(&[]))).unwrap().preset, Some(preset(&[])));
|
||||||
|
// Flag names only, a bounded number of them, and never without a mode.
|
||||||
|
assert!(start.chosen(Some("advanced".into()), true, Some(preset(&[("<b>", true)]))).is_err());
|
||||||
|
assert!(start.chosen(Some("advanced".into()), true, Some(preset(&[(&"a".repeat(65), true)]))).is_err());
|
||||||
|
assert!(start.chosen(None, true, Some(preset(&[("hideAds", true)]))).is_err());
|
||||||
|
let many = (0..=MAX_PRESET_FLAGS).map(|index| (format!("flag{index}"), true)).collect::<BTreeMap<_, _>>();
|
||||||
|
assert!(start.chosen(Some("advanced".into()), true, Some(many)).is_err());
|
||||||
|
// A file written before the preset was kept reads as "not known".
|
||||||
|
assert_eq!(serde_json::from_str::<ModeState>(r#"{"mode":"advanced","onboarded":true,"existing":true}"#).unwrap().preset, None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,40 @@ export function switchMode(table: FeatureTable, flags: Readonly<Flags>, from: st
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ModeStatus = {
|
||||||
|
/** The flags differ from what the mode starts from: "Custom (based on <mode>)". */
|
||||||
|
custom: boolean;
|
||||||
|
/** What applying the mode again would turn on and off (flag ids, in table order). */
|
||||||
|
on: string[];
|
||||||
|
off: string[];
|
||||||
|
/**
|
||||||
|
* Of those, the ones the mode gained since it was applied (an update made its preset larger).
|
||||||
|
* Empty when nothing is known about the preset of that time.
|
||||||
|
*/
|
||||||
|
added: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How the stored flags relate to mode `mode` (null or unknown: no mode, nothing to say). A mode is
|
||||||
|
* a starting point: nothing here applies anything. `applied` is the mode's `flags` as they were
|
||||||
|
* when it was applied (the shell stores it with the choice); without it a difference is simply the
|
||||||
|
* owner's own change.
|
||||||
|
*/
|
||||||
|
export function modeStatus(table: FeatureTable, flags: Readonly<Flags>, mode: string | null | undefined, applied?: Readonly<Record<string, boolean>> | null): ModeStatus {
|
||||||
|
const spec = modeById(table, mode);
|
||||||
|
if (!spec) return { custom: false, on: [], off: [], added: [] };
|
||||||
|
const preset = modeFlags(table, spec.id);
|
||||||
|
const defaults = tableDefaults(table);
|
||||||
|
const differs = Object.keys(preset).filter(key => typeof flags[key] === 'boolean' && flags[key] !== preset[key]);
|
||||||
|
const was = (key: string) => typeof applied?.[key] === 'boolean' ? applied[key] : defaults[key];
|
||||||
|
return {
|
||||||
|
custom: differs.length > 0,
|
||||||
|
on: differs.filter(key => preset[key]),
|
||||||
|
off: differs.filter(key => !preset[key]),
|
||||||
|
added: applied ? differs.filter(key => was(key) !== preset[key]) : [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Feature health, as the panel learns it. A feature that paused itself (featureModules.ts: its
|
* Feature health, as the panel learns it. A feature that paused itself (featureModules.ts: its
|
||||||
* selector probes failed) is named by its area's `health` palette command in the page: the entry
|
* selector probes failed) is named by its area's `health` palette command in the page: the entry
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import test from 'node:test';
|
||||||
import { observeSelector, type DomWindow } from '../src/domHub.ts';
|
import { observeSelector, type DomWindow } from '../src/domHub.ts';
|
||||||
import { AREA_COMMAND_BUDGET, PROBE_STRIKES, createFeatureRegistry, type FeatureModule, type HotfixData } from '../src/featureModules.ts';
|
import { AREA_COMMAND_BUDGET, PROBE_STRIKES, createFeatureRegistry, type FeatureModule, type HotfixData } from '../src/featureModules.ts';
|
||||||
import {
|
import {
|
||||||
areaFlag, effectiveFlags, manualChanges, modeFlags, normalizeFlags, pausedFeatures, sparseFlags, supersededFiles, switchMode, tableDefaults, validateTable,
|
areaFlag, effectiveFlags, manualChanges, modeFlags, modeStatus, normalizeFlags, pausedFeatures, sparseFlags, supersededFiles, switchMode, tableDefaults, validateTable,
|
||||||
type FeatureTable,
|
type FeatureTable,
|
||||||
} from '../src/featureTable.ts';
|
} from '../src/featureTable.ts';
|
||||||
import { createCorePluginApi, type CorePluginApi, type PluginApiSite } from '../src/pluginApi.ts';
|
import { createCorePluginApi, type CorePluginApi, type PluginApiSite } from '../src/pluginApi.ts';
|
||||||
|
|
@ -66,6 +66,36 @@ test('feature table: a mode is a starting point; changing it keeps or drops the
|
||||||
assert.deepEqual(switchMode(TABLE, basic, 'basic', 'advanced', true), defaults);
|
assert.deepEqual(switchMode(TABLE, basic, 'basic', 'advanced', true), defaults);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a mode is a starting point: exact, changed by the owner, and a preset that grew', () => {
|
||||||
|
const power = TABLE.modes.find(mode => mode.id === 'power')!;
|
||||||
|
const applied = modeFlags(TABLE, 'power');
|
||||||
|
// Exact match: the flags are what the mode starts from.
|
||||||
|
assert.deepEqual(modeStatus(TABLE, applied, 'power', power.flags), { custom: false, on: [], off: [], added: [] });
|
||||||
|
// No mode chosen, or one this table does not know: nothing to say, whatever the flags are.
|
||||||
|
assert.deepEqual(modeStatus(TABLE, { ...applied, hideTrends: true }, null), { custom: false, on: [], off: [], added: [] });
|
||||||
|
assert.equal(modeStatus(TABLE, applied, 'gone').custom, false);
|
||||||
|
|
||||||
|
// The owner changed features: custom, and re-applying says what it turns on and off. None of it is "new".
|
||||||
|
const mine = { ...applied, hideTrends: true, 'navigation.keys': false, 'area.reader': false };
|
||||||
|
assert.deepEqual(modeStatus(TABLE, mine, 'power', power.flags), { custom: true, on: ['navigation.keys', 'area.reader'], off: ['hideTrends'], added: [] });
|
||||||
|
// Applying again is exactly that list: afterwards the match is exact.
|
||||||
|
assert.equal(modeStatus(TABLE, switchMode(TABLE, mine, 'power', 'power', false), 'power', power.flags).custom, false);
|
||||||
|
|
||||||
|
// An update made the preset larger: the flags are as the old preset left them. Custom, nothing
|
||||||
|
// applied, and the additions are named so they can be mentioned.
|
||||||
|
const grown: FeatureTable = { ...TABLE, modes: TABLE.modes.map(mode => mode.id === 'power' ? { ...mode, flags: { ...mode.flags, hideTrends: true, hideAds: false } } : mode) };
|
||||||
|
assert.deepEqual(modeStatus(grown, applied, 'power', power.flags), { custom: true, on: ['hideTrends'], off: ['hideAds'], added: ['hideTrends', 'hideAds'] });
|
||||||
|
// Both at once: the owner's own change is a difference but not an addition.
|
||||||
|
assert.deepEqual(modeStatus(grown, { ...applied, 'navigation.keys': false }, 'power', power.flags), { custom: true, on: ['hideTrends', 'navigation.keys'], off: ['hideAds'], added: ['hideTrends', 'hideAds'] });
|
||||||
|
// An addition the owner already has is no difference at all.
|
||||||
|
assert.deepEqual(modeStatus(grown, { ...applied, hideTrends: true }, 'power', power.flags).added, ['hideAds']);
|
||||||
|
// Once the grown preset is the one remembered (the note was looked at), it is not "new" again; the mode stays custom.
|
||||||
|
assert.deepEqual(modeStatus(grown, applied, 'power', grown.modes.find(mode => mode.id === 'power')!.flags), { custom: true, on: ['hideTrends'], off: ['hideAds'], added: [] });
|
||||||
|
// A choice made before the preset was remembered: a difference, never a guess about what is new.
|
||||||
|
assert.deepEqual(modeStatus(grown, applied, 'power'), { custom: true, on: ['hideTrends'], off: ['hideAds'], added: [] });
|
||||||
|
assert.deepEqual(modeStatus(grown, applied, 'power', null).added, []);
|
||||||
|
});
|
||||||
|
|
||||||
test('feature table: problems are reported', () => {
|
test('feature table: problems are reported', () => {
|
||||||
const bad: FeatureTable = {
|
const bad: FeatureTable = {
|
||||||
areas: [{ id: 'Nav', name: 'Nav', description: 'd', owner: 'nav.js', namespace: 'nav' }, ...TABLE.areas],
|
areas: [{ id: 'Nav', name: 'Nav', description: 'd', owner: 'nav.js', namespace: 'nav' }, ...TABLE.areas],
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import { formatNumber } from './i18n.ts';
|
||||||
import { Icon, type IconName } from './icons.tsx';
|
import { Icon, type IconName } from './icons.tsx';
|
||||||
import {
|
import {
|
||||||
DEFAULT_MENU, ZOOM_MAX, ZOOM_MIN, findSpec, joinGroups, languageChoice, languageRows, menuText, moveStop, planMenu, shortcutText, specRows, submenuKeys, submenuLeft, typeahead, updateRow,
|
DEFAULT_MENU, ZOOM_MAX, ZOOM_MIN, findSpec, joinGroups, languageChoice, languageRows, menuText, moveStop, planMenu, shortcutText, specRows, submenuKeys, submenuLeft, typeahead, updateRow,
|
||||||
type BuiltinMenuItem, type MenuEnv, type MenuItemRow, type MenuRow,
|
type BuiltinMenuItem, type MenuEnv, type MenuItemRow, type MenuModeStatus, type MenuRow,
|
||||||
} from './menuModel.ts';
|
} from './menuModel.ts';
|
||||||
import { ReportDialog } from './ReportDialog.tsx';
|
import { ReportDialog } from './ReportDialog.tsx';
|
||||||
import { safe, setSafeMode } from './safeStore.ts';
|
import { safe, setSafeMode } from './safeStore.ts';
|
||||||
|
|
@ -78,7 +78,8 @@ export function AppMenu() {
|
||||||
const [path, setPath] = useState<string[]>([]);
|
const [path, setPath] = useState<string[]>([]);
|
||||||
const [anchor, setAnchor] = useState<Anchor>({ at: 'button', top: 50, right: 8 });
|
const [anchor, setAnchor] = useState<Anchor>({ at: 'button', top: 50, right: 8 });
|
||||||
const [mode, setMode] = useState<string | null>(null);
|
const [mode, setMode] = useState<string | null>(null);
|
||||||
const [asking, setAsking] = useState<{ to: string; changes: number } | null>(null);
|
const [modeStatus, setModeStatus] = useState<MenuModeStatus | null>(null);
|
||||||
|
const [asking, setAsking] = useState<{ to: string; changes: number; reapply?: boolean } | null>(null);
|
||||||
const [version, setVersion] = useState('');
|
const [version, setVersion] = useState('');
|
||||||
const [update, setUpdate] = useState<UpdateStatus>({ state: 'idle' });
|
const [update, setUpdate] = useState<UpdateStatus>({ state: 'idle' });
|
||||||
const [askedUpdate, setAskedUpdate] = useState(false);
|
const [askedUpdate, setAskedUpdate] = useState(false);
|
||||||
|
|
@ -126,6 +127,7 @@ export function AppMenu() {
|
||||||
if (hasFeature('workspaces') && !workspaces.loaded) void loadWorkspaces().catch(() => {});
|
if (hasFeature('workspaces') && !workspaces.loaded) void loadWorkspaces().catch(() => {});
|
||||||
void config.themes?.loadThemes();
|
void config.themes?.loadThemes();
|
||||||
menu.modes?.current().then(setMode, () => {});
|
menu.modes?.current().then(setMode, () => {});
|
||||||
|
menu.modes?.status?.().then(setModeStatus, () => {});
|
||||||
if (!version) menu.version?.().then(setVersion, () => {});
|
if (!version) menu.version?.().then(setVersion, () => {});
|
||||||
setAskedUpdate(false);
|
setAskedUpdate(false);
|
||||||
if (hasFeature('updates')) invoke('update_status').then(value => setUpdate(parseUpdateStatus(value)), () => {});
|
if (hasFeature('updates')) invoke('update_status').then(value => setUpdate(parseUpdateStatus(value)), () => {});
|
||||||
|
|
@ -283,7 +285,10 @@ export function AppMenu() {
|
||||||
});
|
});
|
||||||
case 'language': return item(id, t('wb.settings.language.title'), 'globe', { submenu: true, hint: languageName(menu.languages?.state().locale) });
|
case 'language': return item(id, t('wb.settings.language.title'), 'globe', { submenu: true, hint: languageName(menu.languages?.state().locale) });
|
||||||
case 'theme': return item(id, menuText('theme'), 'palette', { submenu: true, hint: themeId ? config.themes!.themeName(themeId) : undefined });
|
case 'theme': return item(id, menuText('theme'), 'palette', { submenu: true, hint: themeId ? config.themes!.themeName(themeId) : undefined });
|
||||||
case 'mode': return item(id, t('wb.modes.section'), 'layers', { submenu: true, hint: modeList.find(entry => entry.id === mode)?.label });
|
case 'mode': {
|
||||||
|
const label = modeList.find(entry => entry.id === mode)?.label;
|
||||||
|
return item(id, t('wb.modes.section'), 'layers', { submenu: true, hint: label && modeStatus?.custom ? t('wb.modes.custom', { mode: label }) : label });
|
||||||
|
}
|
||||||
case 'zoom': return { kind: 'zoom', id: 'zoom' };
|
case 'zoom': return { kind: 'zoom', id: 'zoom' };
|
||||||
case 'plugins': return item(id, section(t('wb.panel.section.plugins')), 'plug', { run: () => shell.openPanelSection('plugins') });
|
case 'plugins': return item(id, section(t('wb.panel.section.plugins')), 'plug', { run: () => shell.openPanelSection('plugins') });
|
||||||
case 'store': return item(id, section(t('wb.panel.section.store')), 'bag', { run: () => shell.openPanelSection('store') });
|
case 'store': return item(id, section(t('wb.panel.section.store')), 'bag', { run: () => shell.openPanelSection('store') });
|
||||||
|
|
@ -350,6 +355,16 @@ export function AppMenu() {
|
||||||
const name = (modeId: string) => modeList.find(entry => entry.id === modeId)?.label ?? modeId;
|
const name = (modeId: string) => modeList.find(entry => entry.id === modeId)?.label ?? modeId;
|
||||||
const apply = async (to: string, keep: boolean) => { await modes.apply(to, keep); setMode(to); close('action'); };
|
const apply = async (to: string, keep: boolean) => { await modes.apply(to, keep); setMode(to); close('action'); };
|
||||||
const at = path.indexOf('mode') + 1;
|
const at = path.indexOf('mode') + 1;
|
||||||
|
if (asking?.reapply && modeStatus) {
|
||||||
|
// What applying the mode again turns on and off, said before it happens.
|
||||||
|
return [
|
||||||
|
{ kind: 'note', id: 'mode:reapply-hint', title: t('wb.modes.reapply', { mode: name(asking.to) }), text: t('wb.modes.reapplyHint', { mode: name(asking.to) }) },
|
||||||
|
...(modeStatus.on.length ? [{ kind: 'note' as const, id: 'mode:reapply-on', title: '', text: t('wb.modes.turnsOn', { list: modeStatus.on.join(', ') }) }] : []),
|
||||||
|
...(modeStatus.off.length ? [{ kind: 'note' as const, id: 'mode:reapply-off', title: '', text: t('wb.modes.turnsOff', { list: modeStatus.off.join(', ') }) }] : []),
|
||||||
|
item('mode:reapply-yes', t('wb.modes.reapply', { mode: name(asking.to) }), 'reload', { keepOpen: true, run: async () => { await modes.reapply?.(); close('action'); } }),
|
||||||
|
item('mode:cancel', t('wb.common.cancel'), 'close', { keepOpen: true, run: () => { focusNext.current = { level: at, id: 'mode:reapply' }; setAsking(null); } }),
|
||||||
|
];
|
||||||
|
}
|
||||||
if (asking) {
|
if (asking) {
|
||||||
// The question Settings asks: what was changed by hand stays, or the mode is taken as it is.
|
// The question Settings asks: what was changed by hand stays, or the mode is taken as it is.
|
||||||
return [
|
return [
|
||||||
|
|
@ -359,7 +374,7 @@ export function AppMenu() {
|
||||||
item('mode:cancel', t('wb.common.cancel'), 'close', { keepOpen: true, run: () => { focusNext.current = { level: at, id: `mode:${asking.to}` }; setAsking(null); } }),
|
item('mode:cancel', t('wb.common.cancel'), 'close', { keepOpen: true, run: () => { focusNext.current = { level: at, id: `mode:${asking.to}` }; setAsking(null); } }),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return modeList.map(entry => item(`mode:${entry.id}`, entry.label, undefined, {
|
const list = modeList.map(entry => item(`mode:${entry.id}`, entry.label, undefined, {
|
||||||
check: 'radio', checked: entry.id === mode, keepOpen: true,
|
check: 'radio', checked: entry.id === mode, keepOpen: true,
|
||||||
run: async () => {
|
run: async () => {
|
||||||
if (entry.id === mode) { close('action'); return; }
|
if (entry.id === mode) { close('action'); return; }
|
||||||
|
|
@ -367,6 +382,21 @@ export function AppMenu() {
|
||||||
if (changes > 0) { focusNext.current = { level: at, edge: 'first' }; setAsking({ to: entry.id, changes }); } else await apply(entry.id, false);
|
if (changes > 0) { focusNext.current = { level: at, edge: 'first' }; setAsking({ to: entry.id, changes }); } else await apply(entry.id, false);
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
if (!mode || !modeStatus?.custom || !modes.reapply) return list;
|
||||||
|
// The mode is a starting point: the features moved on, and nothing applies it again unasked.
|
||||||
|
const grew: MenuRow[] = modeStatus.added > 0 ? [{ kind: 'note', id: 'mode:grew', title: '', text: t('wb.modes.grew', { mode: name(mode), count: modeStatus.added }) }] : [];
|
||||||
|
return joinGroups([list, [
|
||||||
|
{ kind: 'note', id: 'mode:custom', title: t('wb.modes.custom', { mode: name(mode) }) },
|
||||||
|
...grew,
|
||||||
|
item('mode:reapply', t('wb.modes.reapply', { mode: name(mode) }), 'reload', {
|
||||||
|
keepOpen: true,
|
||||||
|
run: () => {
|
||||||
|
focusNext.current = { level: at, edge: 'first' };
|
||||||
|
setAsking({ to: mode, changes: 0, reapply: true });
|
||||||
|
if (modeStatus.added > 0) void modes.seen?.().then(() => setModeStatus({ ...modeStatus, added: 0 }), () => {});
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]]);
|
||||||
}
|
}
|
||||||
case 'workspaces': {
|
case 'workspaces': {
|
||||||
const list = workspaceList();
|
const list = workspaceList();
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,21 @@ export type MenuModes = {
|
||||||
changes(to: string): Promise<number>;
|
changes(to: string): Promise<number>;
|
||||||
/** Applies `to`, keeping the owner's own changes or not. */
|
/** Applies `to`, keeping the owner's own changes or not. */
|
||||||
apply(to: string, keep: boolean): Promise<void>;
|
apply(to: string, keep: boolean): Promise<void>;
|
||||||
|
/** How the features relate to the mode in use (omit: the menu never says "custom"). */
|
||||||
|
status?(): Promise<MenuModeStatus>;
|
||||||
|
/** Applies the mode in use again as it is now: exactly what `status()` listed. */
|
||||||
|
reapply?(): Promise<void>;
|
||||||
|
/** The "new features" note was looked at; it is not shown again. */
|
||||||
|
seen?(): Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A mode is a starting point. `custom`: the features are no longer what the mode starts from;
|
||||||
|
* `on` / `off`: the names of what applying it again would turn on and off; `added`: how many of
|
||||||
|
* those the mode gained in an update since it was applied.
|
||||||
|
*/
|
||||||
|
export type MenuModeStatus = { custom: boolean; on: string[]; off: string[]; added: number };
|
||||||
|
|
||||||
/** Lines an app adds to the "Report a problem" summary (reportModel.ts): ids only, never anything about the person. */
|
/** Lines an app adds to the "Report a problem" summary (reportModel.ts): ids only, never anything about the person. */
|
||||||
export type ReportDetails = ReadonlyArray<{ label: string; values: readonly string[] }>;
|
export type ReportDetails = ReadonlyArray<{ label: string; values: readonly string[] }>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,18 @@
|
||||||
// preselected; someone who set the app up before modes existed may dismiss it and keep exactly
|
// preselected; someone who set the app up before modes existed may dismiss it and keep exactly
|
||||||
// what they have. `ModeSettings` is the same choice later, in Settings, with the question whether
|
// what they have. `ModeSettings` is the same choice later, in Settings, with the question whether
|
||||||
// the owner's own changes stay. A mode is a starting point: choosing one writes flag values
|
// the owner's own changes stay. A mode is a starting point: choosing one writes flag values
|
||||||
// (`features_set`) and remembers the choice (`mode_get/set`); it never takes a switch away.
|
// (`features_set`) and remembers the choice (`mode_get/set`); it never takes a switch away, and it
|
||||||
|
// is never applied again on its own. When the flags are no longer what the mode starts from (the
|
||||||
|
// owner changed features, or an update made the mode larger) the mode reads "Custom (based on
|
||||||
|
// <mode>)" and one action, "Re-apply <mode>", lists what it turns on and off before it does.
|
||||||
import { useEffect, useState, type ComponentType } from 'react';
|
import { useEffect, useState, type ComponentType } from 'react';
|
||||||
import { modeById, normalizeFlags, sparseFlags as sparse, type FeatureTable, type Flags } from '../../../runtime/src/featureTable.ts';
|
import {
|
||||||
|
areaFlag, featureWords, modeById, modeFlags, modeStatus, normalizeFlags, sparseFlags as sparse, type FeatureTable, type Flags, type ModeStatus,
|
||||||
|
} from '../../../runtime/src/featureTable.ts';
|
||||||
import { invoke } from '../frame/bridge.ts';
|
import { invoke } from '../frame/bridge.ts';
|
||||||
import { useT } from '../frame/hooks.ts';
|
import { useT } from '../frame/hooks.ts';
|
||||||
import { tx } from '../frame/i18n.ts';
|
import { tx } from '../frame/i18n.ts';
|
||||||
import type { MenuModes } from '../frame/menuModel.ts';
|
import type { MenuModeStatus, MenuModes } from '../frame/menuModel.ts';
|
||||||
import { shell } from '../frame/state.ts';
|
import { shell } from '../frame/state.ts';
|
||||||
import { Badge, Button, Row, Section } from './controls.tsx';
|
import { Badge, Button, Row, Section } from './controls.tsx';
|
||||||
import { modePlan, type PluginFileState } from './featureModel.ts';
|
import { modePlan, type PluginFileState } from './featureModel.ts';
|
||||||
|
|
@ -17,12 +22,16 @@ import { featureTable, flagsChanged, useFlags } from './PluginFeatures.tsx';
|
||||||
import { panelSite, type Notify } from './site.ts';
|
import { panelSite, type Notify } from './site.ts';
|
||||||
import './plugins.css';
|
import './plugins.css';
|
||||||
|
|
||||||
/** The onboarding state native code keeps (waybetter-host `modes::ModeState`). */
|
/**
|
||||||
export type ModeState = { mode: string | null; onboarded: boolean; existing: boolean };
|
* The onboarding state native code keeps (waybetter-host `modes::ModeState`). `preset`: the mode's
|
||||||
|
* flags as they were when it was applied (absent: not known).
|
||||||
|
*/
|
||||||
|
export type ModeState = { mode: string | null; onboarded: boolean; existing: boolean; preset?: Record<string, boolean> | null };
|
||||||
|
|
||||||
const getError = (error: unknown) => error instanceof Error ? error.message : String(error);
|
const getError = (error: unknown) => error instanceof Error ? error.message : String(error);
|
||||||
const listeners = new Set<(state: ModeState) => void>();
|
const listeners = new Set<(state: ModeState) => void>();
|
||||||
let cached: ModeState | null = null;
|
let cached: ModeState | null = null;
|
||||||
|
const share = (next: ModeState) => { cached = next; for (const listener of listeners) listener(next); };
|
||||||
|
|
||||||
/** The mode state, loaded once and shared by the first-run screen and Settings. Null until loaded (or without modes). */
|
/** The mode state, loaded once and shared by the first-run screen and Settings. Null until loaded (or without modes). */
|
||||||
export function useModeState(): [ModeState | null, (next: ModeState) => void] {
|
export function useModeState(): [ModeState | null, (next: ModeState) => void] {
|
||||||
|
|
@ -46,12 +55,42 @@ async function applyMode(table: FeatureTable, flags: Flags, from: string | null,
|
||||||
if (!await save(plan.flags)) return null;
|
if (!await save(plan.flags)) return null;
|
||||||
for (const file of plan.disable) await invoke('plugin_set_enabled', { file, enabled: false }).catch(() => {});
|
for (const file of plan.disable) await invoke('plugin_set_enabled', { file, enabled: false }).catch(() => {});
|
||||||
if (plan.disable.length) window.dispatchEvent(new CustomEvent('bt-plugins-changed'));
|
if (plan.disable.length) window.dispatchEvent(new CustomEvent('bt-plugins-changed'));
|
||||||
const state = await invoke<ModeState>('mode_set', { mode: to, onboarded: true });
|
const state = await invoke<ModeState>('mode_set', { mode: to, onboarded: true, preset: modeById(table, to)?.flags ?? {} });
|
||||||
flagsChanged();
|
flagsChanged();
|
||||||
await panelSite().features?.onMode?.(to);
|
await panelSite().features?.onMode?.(to);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** "Re-apply <mode>": every flag back to what the mode starts from now. Plugin files are not touched. */
|
||||||
|
async function reapplyMode(table: FeatureTable, mode: string, save: (flags: Flags) => Promise<boolean>): Promise<ModeState | null> {
|
||||||
|
if (!modeById(table, mode) || !await save(modeFlags(table, mode))) return null;
|
||||||
|
const state = await invoke<ModeState>('mode_set', { mode, onboarded: true, preset: modeById(table, mode)!.flags });
|
||||||
|
flagsChanged();
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The "new features" note was looked at: the mode's preset of today is the one remembered, so it is said once. */
|
||||||
|
const presetSeen = (table: FeatureTable, state: ModeState) =>
|
||||||
|
invoke<ModeState>('mode_set', { mode: state.mode, onboarded: state.onboarded, preset: modeById(table, state.mode)?.flags ?? {} });
|
||||||
|
|
||||||
|
/** A flag as the owner knows it: the feature's label, or the area's name for its switch. */
|
||||||
|
function flagName(table: FeatureTable, id: string): string {
|
||||||
|
const area = table.areas.find(entry => areaFlag(entry.id) === id);
|
||||||
|
if (area) return area.name;
|
||||||
|
const feature = table.features.find(entry => entry.id === id);
|
||||||
|
return feature ? tx(featureWords(feature).label, undefined, id) : id;
|
||||||
|
}
|
||||||
|
const flagNames = (table: FeatureTable, ids: readonly string[]) => ids.map(id => flagName(table, id)).join(', ');
|
||||||
|
|
||||||
|
/** What "Re-apply" would do, in words: one line for what turns on, one for what turns off. */
|
||||||
|
function ReapplyList({ table, status }: { table: FeatureTable; status: ModeStatus }) {
|
||||||
|
const t = useT();
|
||||||
|
return <>
|
||||||
|
{status.on.length > 0 && <small>{t('wb.modes.turnsOn', { list: flagNames(table, status.on) })}</small>}
|
||||||
|
{status.off.length > 0 && <small>{t('wb.modes.turnsOff', { list: flagNames(table, status.off) })}</small>}
|
||||||
|
</>;
|
||||||
|
}
|
||||||
|
|
||||||
function ModeCards({ table, selected, onSelect, Art }: { table: FeatureTable; selected: string | null; onSelect(id: string): void; Art?: ComponentType<{ mode: string }> }) {
|
function ModeCards({ table, selected, onSelect, Art }: { table: FeatureTable; selected: string | null; onSelect(id: string): void; Art?: ComponentType<{ mode: string }> }) {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
return <div className="wbm-cards" role="radiogroup" aria-label={t('wb.modes.section')}>
|
return <div className="wbm-cards" role="radiogroup" aria-label={t('wb.modes.section')}>
|
||||||
|
|
@ -82,6 +121,8 @@ export function Onboarding({ state, done, notify }: { state: ModeState; done(nex
|
||||||
const [selected, setSelected] = useState<string | null>(state.existing ? null : recommended);
|
const [selected, setSelected] = useState<string | null>(state.existing ? null : recommended);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
const mode = modeById(table, selected);
|
const mode = modeById(table, selected);
|
||||||
|
const stored = modeById(table, state.mode);
|
||||||
|
const custom = !!stored && !!flags && modeStatus(table, flags, stored.id, state.preset).custom;
|
||||||
|
|
||||||
async function finish(next: () => Promise<ModeState | null>) {
|
async function finish(next: () => Promise<ModeState | null>) {
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
|
|
@ -99,6 +140,7 @@ export function Onboarding({ state, done, notify }: { state: ModeState; done(nex
|
||||||
<p>{t('wb.modes.lede')}</p>
|
<p>{t('wb.modes.lede')}</p>
|
||||||
<ModeCards table={table} selected={selected} onSelect={setSelected} Art={panel.features?.ModeArt}/>
|
<ModeCards table={table} selected={selected} onSelect={setSelected} Art={panel.features?.ModeArt}/>
|
||||||
{state.existing && <p className="wbm-note">{t('wb.modes.existing', { app: panel.brand.name })}</p>}
|
{state.existing && <p className="wbm-note">{t('wb.modes.existing', { app: panel.brand.name })}</p>}
|
||||||
|
{custom && <p className="wbm-note">{t('wb.modes.custom', { mode: tx(stored!.name, undefined, stored!.id) })}</p>}
|
||||||
<div className="wbm-actions">
|
<div className="wbm-actions">
|
||||||
{state.existing && <Button tone={selected ? 'ghost' : 'primary'} disabled={busy} onClick={dismiss}>{t('wb.modes.keepSetup')}</Button>}
|
{state.existing && <Button tone={selected ? 'ghost' : 'primary'} disabled={busy} onClick={dismiss}>{t('wb.modes.keepSetup')}</Button>}
|
||||||
{mode && state.existing && <Button disabled={busy || !flags} onClick={() => start(true)}>{t('wb.modes.keep')}</Button>}
|
{mode && state.existing && <Button disabled={busy || !flags} onClick={() => start(true)}>{t('wb.modes.keep')}</Button>}
|
||||||
|
|
@ -118,9 +160,25 @@ function ModeSettingsOf({ table, notify }: { table: FeatureTable; notify: Notify
|
||||||
const [state, setState] = useModeState();
|
const [state, setState] = useModeState();
|
||||||
const [flags, , reload] = useFlags(table, notify);
|
const [flags, , reload] = useFlags(table, notify);
|
||||||
const [asking, setAsking] = useState<{ to: string; changes: number } | null>(null);
|
const [asking, setAsking] = useState<{ to: string; changes: number } | null>(null);
|
||||||
|
const [reviewing, setReviewing] = useState(false);
|
||||||
if (!state || !flags) return null;
|
if (!state || !flags) return null;
|
||||||
const name = (id: string) => tx(modeById(table, id)?.name ?? id, undefined, id);
|
const name = (id: string) => tx(modeById(table, id)?.name ?? id, undefined, id);
|
||||||
const save = async (next: Flags) => { await invoke('features_set', { features: sparse(table, next) }); return true; };
|
const save = async (next: Flags) => { await invoke('features_set', { features: sparse(table, next) }); return true; };
|
||||||
|
const status = modeStatus(table, flags, state.mode, state.preset);
|
||||||
|
|
||||||
|
/** Opens the list of what re-applying does. Looking at it is what ends the "new features" note. */
|
||||||
|
function review() {
|
||||||
|
setAsking(null);
|
||||||
|
setReviewing(true);
|
||||||
|
if (status.added.length) presetSeen(table, state!).then(setState, () => {});
|
||||||
|
}
|
||||||
|
async function reapply() {
|
||||||
|
setReviewing(false);
|
||||||
|
try {
|
||||||
|
const next = await reapplyMode(table, state!.mode!, save);
|
||||||
|
if (next) { setState(next); await reload(); notify(t('wb.modes.applied', { mode: name(next.mode!) })); }
|
||||||
|
} catch (err) { notify(getError(err), true); }
|
||||||
|
}
|
||||||
|
|
||||||
async function apply(to: string, keep: boolean) {
|
async function apply(to: string, keep: boolean) {
|
||||||
setAsking(null);
|
setAsking(null);
|
||||||
|
|
@ -138,6 +196,19 @@ function ModeSettingsOf({ table, notify }: { table: FeatureTable; notify: Notify
|
||||||
return <Section title={t('wb.modes.section')} hint={t('wb.modes.sectionHint')} id="modes">
|
return <Section title={t('wb.modes.section')} hint={t('wb.modes.sectionHint')} id="modes">
|
||||||
{table.modes.map(mode => {
|
{table.modes.map(mode => {
|
||||||
const current = state.mode === mode.id;
|
const current = state.mode === mode.id;
|
||||||
|
const custom = current && status.custom;
|
||||||
|
if (custom) return <Row key={mode.id} label={name(mode.id)} hint={tx(mode.description, undefined, '')} keywords={`mode preset custom ${mode.id}`} wide={reviewing}
|
||||||
|
badge={<><Badge tone="accent">{t('wb.modes.custom', { mode: name(mode.id) })}</Badge>{mode.recommended && <Badge>{t('wb.modes.recommended')}</Badge>}</>}>
|
||||||
|
{reviewing
|
||||||
|
? <span className="wbf-ask" role="alertdialog">{t('wb.modes.reapplyHint', { mode: name(mode.id) })} <ReapplyList table={table} status={status}/>
|
||||||
|
<Button size="sm" tone="primary" onClick={() => void reapply()}>{t('wb.modes.reapply', { mode: name(mode.id) })}</Button>
|
||||||
|
<Button size="sm" tone="ghost" onClick={() => setReviewing(false)}>{t('wb.common.cancel')}</Button>
|
||||||
|
</span>
|
||||||
|
: <span className="wbf-ask">
|
||||||
|
{status.added.length > 0 && <small>{t('wb.modes.grew', { mode: name(mode.id), count: status.added.length })}</small>}
|
||||||
|
<Button size="sm" onClick={review}>{status.added.length > 0 ? t('wb.modes.review') : t('wb.modes.reapply', { mode: name(mode.id) })}</Button>
|
||||||
|
</span>}
|
||||||
|
</Row>;
|
||||||
return <Row key={mode.id} label={name(mode.id)} hint={tx(mode.description, undefined, '')} keywords={`mode preset ${mode.id}`} wide={asking?.to === mode.id}
|
return <Row key={mode.id} label={name(mode.id)} hint={tx(mode.description, undefined, '')} keywords={`mode preset ${mode.id}`} wide={asking?.to === mode.id}
|
||||||
badge={<>{current && <Badge tone="accent">{t('wb.modes.current')}</Badge>}{mode.recommended && <Badge>{t('wb.modes.recommended')}</Badge>}</>}>
|
badge={<>{current && <Badge tone="accent">{t('wb.modes.current')}</Badge>}{mode.recommended && <Badge>{t('wb.modes.recommended')}</Badge>}</>}>
|
||||||
{asking?.to === mode.id
|
{asking?.to === mode.id
|
||||||
|
|
@ -146,7 +217,7 @@ function ModeSettingsOf({ table, notify }: { table: FeatureTable; notify: Notify
|
||||||
<Button size="sm" onClick={() => void apply(mode.id, false)}>{t('wb.modes.reset', { mode: name(mode.id) })}</Button>
|
<Button size="sm" onClick={() => void apply(mode.id, false)}>{t('wb.modes.reset', { mode: name(mode.id) })}</Button>
|
||||||
<Button size="sm" tone="ghost" onClick={() => setAsking(null)}>{t('wb.common.cancel')}</Button>
|
<Button size="sm" tone="ghost" onClick={() => setAsking(null)}>{t('wb.common.cancel')}</Button>
|
||||||
</span>
|
</span>
|
||||||
: <Button size="sm" onClick={() => void choose(mode.id)}>{t('wb.modes.use')}</Button>}
|
: <Button size="sm" onClick={() => { setReviewing(false); void choose(mode.id); }}>{t('wb.modes.use')}</Button>}
|
||||||
</Row>;
|
</Row>;
|
||||||
})}
|
})}
|
||||||
</Section>;
|
</Section>;
|
||||||
|
|
@ -191,7 +262,27 @@ export function menuModes(): MenuModes {
|
||||||
if (!table) return;
|
if (!table) return;
|
||||||
const save = async (next: Flags) => { await invoke('features_set', { features: sparse(table, next) }); return true; };
|
const save = async (next: Flags) => { await invoke('features_set', { features: sparse(table, next) }); return true; };
|
||||||
const next = await applyMode(table, await flagsNow(table), (await state()).mode, to, keep, save);
|
const next = await applyMode(table, await flagsNow(table), (await state()).mode, to, keep, save);
|
||||||
if (next) { cached = next; for (const listener of listeners) listener(next); }
|
if (next) share(next);
|
||||||
|
},
|
||||||
|
async status(): Promise<MenuModeStatus> {
|
||||||
|
const table = featureTable();
|
||||||
|
const now = table?.modes.length ? await state() : null;
|
||||||
|
if (!table || !now) return { custom: false, on: [], off: [], added: 0 };
|
||||||
|
const status = modeStatus(table, await flagsNow(table), now.mode, now.preset);
|
||||||
|
return { custom: status.custom, on: status.on.map(id => flagName(table, id)), off: status.off.map(id => flagName(table, id)), added: status.added.length };
|
||||||
|
},
|
||||||
|
async reapply() {
|
||||||
|
const table = featureTable();
|
||||||
|
const mode = (await state()).mode;
|
||||||
|
if (!table || !mode) return;
|
||||||
|
const save = async (next: Flags) => { await invoke('features_set', { features: sparse(table, next) }); return true; };
|
||||||
|
const next = await reapplyMode(table, mode, save);
|
||||||
|
if (next) share(next);
|
||||||
|
},
|
||||||
|
async seen() {
|
||||||
|
const table = featureTable();
|
||||||
|
const now = await state();
|
||||||
|
if (table && now.mode) share(await presetSeen(table, now));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -469,18 +469,25 @@ export const PANEL_MESSAGES = {
|
||||||
'wb.make.warn.tag': 'The header has no {tag}.',
|
'wb.make.warn.tag': 'The header has no {tag}.',
|
||||||
'wb.modes.applied': '{mode} is on.',
|
'wb.modes.applied': '{mode} is on.',
|
||||||
'wb.modes.current': 'in use',
|
'wb.modes.current': 'in use',
|
||||||
|
'wb.modes.custom': 'Custom (based on {mode})',
|
||||||
'wb.modes.existing': 'You already set {app} up. Nothing changes unless you pick a mode.',
|
'wb.modes.existing': 'You already set {app} up. Nothing changes unless you pick a mode.',
|
||||||
|
'wb.modes.grew': '{mode} has new features: {count}.',
|
||||||
'wb.modes.keep': 'Keep my changes',
|
'wb.modes.keep': 'Keep my changes',
|
||||||
'wb.modes.keepHint': 'Changed by hand: {count}. Those would be replaced.',
|
'wb.modes.keepHint': 'Changed by hand: {count}. Those would be replaced.',
|
||||||
'wb.modes.keepQuestion': 'Keep your manual changes?',
|
'wb.modes.keepQuestion': 'Keep your manual changes?',
|
||||||
'wb.modes.keepSetup': 'Keep my current setup',
|
'wb.modes.keepSetup': 'Keep my current setup',
|
||||||
'wb.modes.lede': 'Pick a starting point. Every plugin and feature stays individually switchable, and you can change the mode later in Settings.',
|
'wb.modes.lede': 'Pick a starting point. Every plugin and feature stays individually switchable, and you can change the mode later in Settings.',
|
||||||
|
'wb.modes.reapply': 'Re-apply {mode}',
|
||||||
|
'wb.modes.reapplyHint': 'Every feature goes back to what {mode} starts with.',
|
||||||
'wb.modes.recommended': 'Recommended',
|
'wb.modes.recommended': 'Recommended',
|
||||||
'wb.modes.reset': 'Use {mode} as it is',
|
'wb.modes.reset': 'Use {mode} as it is',
|
||||||
|
'wb.modes.review': 'Review',
|
||||||
'wb.modes.section': 'Mode',
|
'wb.modes.section': 'Mode',
|
||||||
'wb.modes.sectionHint': 'A starting point, not a lock. Changing it never takes a switch away.',
|
'wb.modes.sectionHint': 'A starting point, not a lock. Changing it never takes a switch away.',
|
||||||
'wb.modes.start': 'Start with {mode}',
|
'wb.modes.start': 'Start with {mode}',
|
||||||
'wb.modes.title': 'How much should {app} change {site}?',
|
'wb.modes.title': 'How much should {app} change {site}?',
|
||||||
|
'wb.modes.turnsOff': 'Turns off: {list}',
|
||||||
|
'wb.modes.turnsOn': 'Turns on: {list}',
|
||||||
'wb.modes.use': 'Use this mode',
|
'wb.modes.use': 'Use this mode',
|
||||||
'wb.panel.accounts.add': '+ Add account',
|
'wb.panel.accounts.add': '+ Add account',
|
||||||
'wb.panel.accounts.hint': 'Each account is its own {site} sign-in on this computer and stays signed in across restarts. Click one to open its feed beside this pane.',
|
'wb.panel.accounts.hint': 'Each account is its own {site} sign-in on this computer and stays signed in across restarts. Click one to open its feed beside this pane.',
|
||||||
|
|
|
||||||
|
|
@ -1113,18 +1113,25 @@
|
||||||
"wb.features.useBuiltIn": "Use the built-in one",
|
"wb.features.useBuiltIn": "Use the built-in one",
|
||||||
"wb.modes.applied": "{mode} is on.",
|
"wb.modes.applied": "{mode} is on.",
|
||||||
"wb.modes.current": "in use",
|
"wb.modes.current": "in use",
|
||||||
|
"wb.modes.custom": "Custom (based on {mode})",
|
||||||
"wb.modes.existing": "You already set {app} up. Nothing changes unless you pick a mode.",
|
"wb.modes.existing": "You already set {app} up. Nothing changes unless you pick a mode.",
|
||||||
|
"wb.modes.grew": "{mode} has new features: {count}.",
|
||||||
"wb.modes.keep": "Keep my changes",
|
"wb.modes.keep": "Keep my changes",
|
||||||
"wb.modes.keepHint": "Changed by hand: {count}. Those would be replaced.",
|
"wb.modes.keepHint": "Changed by hand: {count}. Those would be replaced.",
|
||||||
"wb.modes.keepQuestion": "Keep your manual changes?",
|
"wb.modes.keepQuestion": "Keep your manual changes?",
|
||||||
"wb.modes.keepSetup": "Keep my current setup",
|
"wb.modes.keepSetup": "Keep my current setup",
|
||||||
"wb.modes.lede": "Pick a starting point. Every plugin and feature stays individually switchable, and you can change the mode later in Settings.",
|
"wb.modes.lede": "Pick a starting point. Every plugin and feature stays individually switchable, and you can change the mode later in Settings.",
|
||||||
|
"wb.modes.reapply": "Re-apply {mode}",
|
||||||
|
"wb.modes.reapplyHint": "Every feature goes back to what {mode} starts with.",
|
||||||
"wb.modes.recommended": "Recommended",
|
"wb.modes.recommended": "Recommended",
|
||||||
"wb.modes.reset": "Use {mode} as it is",
|
"wb.modes.reset": "Use {mode} as it is",
|
||||||
|
"wb.modes.review": "Review",
|
||||||
"wb.modes.section": "Mode",
|
"wb.modes.section": "Mode",
|
||||||
"wb.modes.sectionHint": "A starting point, not a lock. Changing it never takes a switch away.",
|
"wb.modes.sectionHint": "A starting point, not a lock. Changing it never takes a switch away.",
|
||||||
"wb.modes.start": "Start with {mode}",
|
"wb.modes.start": "Start with {mode}",
|
||||||
"wb.modes.title": "How much should {app} change {site}?",
|
"wb.modes.title": "How much should {app} change {site}?",
|
||||||
|
"wb.modes.turnsOff": "Turns off: {list}",
|
||||||
|
"wb.modes.turnsOn": "Turns on: {list}",
|
||||||
"wb.modes.use": "Use this mode",
|
"wb.modes.use": "Use this mode",
|
||||||
"wb.features.soon": "Its features arrive in a later update."
|
"wb.features.soon": "Its features arrive in a later update."
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue