Keep preferences in one settings file and move tab transfer to the host
Keep the user preferences in settings.json in the app config folder. WebView storage can be lost, and the host cannot read it. The file has a schema number, a revision number, and one value for each section: general, appearance, customThemes, customThemesLegacy, and language. - settings_read gives all sections, the revision, and a one-time notice. - settings_write replaces one section, writes the file atomically, and sends settings-changed to all windows. The limit is 8 MiB. - settings_migrate writes the first file only when no file exists. - The host moves a damaged file to settings.corrupt-<seconds>.json, starts from the defaults, and reports this one time. Each window loads the sections before its first render. One store in src/lib/settings/store.ts replaces the storage listeners. When no file exists, the window normalizes the old localStorage values and migrates them. The old keys stay in place for one release. The window layout and the open tabs stay in localStorage on purpose. The browser preview keeps all preferences in localStorage. Keep tab transfer offers in host memory, not in localStorage, because an offer can hold unsaved text. A window takes an offer once. The host checks the workspace root and a 120 second expiry. When the receiver accepts the tab, the host sends tab-transfer-accepted to the source window only. A refused offer stays open, and the source tab stays open. A new window and a drop on the tab ribbon use one check. The smoke harness serves the new commands from one shared state for each browser context. Tests read saved values from the mock settings file. Rust, unit, and smoke tests cover the changes.
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
import Icon from '$lib/ui/Icon.svelte';
|
||||
import { showActionMenu } from '$lib/ui/managedActionMenu';
|
||||
import { saveBackgroundImage, removeBackgroundImage } from './backgroundImages';
|
||||
import { APPEARANCE_KEY, DEFAULT_APPEARANCE, BUILTIN_THEMES, themeModes, BACKGROUND_POSITIONS, BACKGROUND_SIZES, parseAppearance, normalizeAppearance, saveAppearance, exportAppearanceTheme, type Appearance, type ThemeName } from './appearance';
|
||||
import { onSettingsChange } from '$lib/settings/store';
|
||||
import { DEFAULT_APPEARANCE, BUILTIN_THEMES, themeModes, BACKGROUND_POSITIONS, BACKGROUND_SIZES, readAppearance, normalizeAppearance, saveAppearance, exportAppearanceTheme, type Appearance, type ThemeName } from './appearance';
|
||||
let appearance = $state<Appearance>({ ...DEFAULT_APPEARANCE });
|
||||
let error = $state('');
|
||||
let status = $state('');
|
||||
@@ -43,12 +44,16 @@
|
||||
run: () => change({ ...appearance, newTabBackground: { ...appearance.newTabBackground, [field]: value } }) })) }).close;
|
||||
}
|
||||
onMount(() => {
|
||||
const read = () => { try { installed = customThemes(); appearance = parseAppearance(localStorage.getItem(APPEARANCE_KEY)); } catch { error = $t('Could not read appearance settings.'); } };
|
||||
read(); window.addEventListener('storage', read); window.addEventListener('focus', read);
|
||||
return () => { window.removeEventListener('storage', read); window.removeEventListener('focus', read); };
|
||||
const read = () => { try { installed = customThemes(); appearance = readAppearance(); } catch { error = $t('Could not read appearance settings.'); } };
|
||||
read();
|
||||
const stops = [onSettingsChange('appearance', read), onSettingsChange('customThemes', read)];
|
||||
return () => stops.forEach(stop => stop());
|
||||
});
|
||||
function change(next: Appearance) {
|
||||
try { saveAppearance(next); appearance = normalizeAppearance(next); error = ''; return true; }
|
||||
try {
|
||||
saveAppearance(next).catch(() => { error = $t('Could not save appearance settings.'); });
|
||||
appearance = normalizeAppearance(next); error = ''; return true;
|
||||
}
|
||||
catch { error = $t('Could not save appearance settings.'); return false; }
|
||||
}
|
||||
function changeOverlay(input: HTMLInputElement) {
|
||||
@@ -68,7 +73,7 @@
|
||||
try {
|
||||
if (file.size > 65536) throw new Error($t('Choose a theme smaller than 64 KiB.'));
|
||||
const theme = parseCustomTheme(JSON.parse(await file.text()), appearance.mode);
|
||||
installTheme(theme); installed = customThemes();
|
||||
installTheme(theme).catch(reason => { error = String(reason); }); installed = customThemes();
|
||||
change({ ...appearance, theme: `custom:${theme.id}` });
|
||||
} catch (reason) { error = String(reason); }
|
||||
finally { themeInput.value = ''; }
|
||||
@@ -121,7 +126,7 @@
|
||||
<button onclick={() => themeInput.click()}>{$t("Install theme")}</button>
|
||||
<button disabled={exporting} onclick={() => void exportTemplate()}>{exporting ? $t('Exporting…') : $t('Export theme template')}</button>
|
||||
{#if appearance.theme.startsWith('custom:')}<IconButton icon="trash" label={$t("Remove custom theme")} onclick={() => {
|
||||
try { removeTheme(appearance.theme.slice(7)); installed = customThemes(); change({ ...appearance, theme: 'default' }); }
|
||||
try { removeTheme(appearance.theme.slice(7)).catch(() => { error = 'Could not remove this theme.'; }); installed = customThemes(); change({ ...appearance, theme: 'default' }); }
|
||||
catch { error = 'Could not remove this theme.'; }
|
||||
}} />{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user