forked from ekzhang/sshx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adjust font weight * Settings refactor and scrollback * Fix embarrassing typo * Text in -> with
- Loading branch information
Showing
10 changed files
with
110 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,40 @@ | ||
import { persisted } from "svelte-persisted-store"; | ||
import { type ThemeName, defaultTheme } from "./ui/themes"; | ||
import themes, { type ThemeName, defaultTheme } from "./ui/themes"; | ||
import { derived, type Readable } from "svelte/store"; | ||
|
||
export type SettingsStore = { | ||
export type Settings = { | ||
name: string; | ||
theme: ThemeName; | ||
scrollback: number; | ||
}; | ||
|
||
const storedSettings = persisted<Partial<Settings>>("sshx-settings-store", {}); | ||
|
||
/** A persisted store for settings of the current user. */ | ||
export const settings = persisted<SettingsStore>("sshx-settings-store", { | ||
name: "", | ||
theme: defaultTheme, | ||
}); | ||
export const settings: Readable<Settings> = derived( | ||
storedSettings, | ||
($storedSettings) => { | ||
// Do some validation on all of the stored settings. | ||
const name = $storedSettings.name ?? ""; | ||
|
||
let theme = $storedSettings.theme; | ||
if (!theme || !Object.hasOwn(themes, theme)) { | ||
theme = defaultTheme; | ||
} | ||
|
||
let scrollback = $storedSettings.scrollback; | ||
if (typeof scrollback !== "number" || scrollback < 0) { | ||
scrollback = 5000; | ||
} | ||
|
||
return { | ||
name, | ||
theme, | ||
scrollback, | ||
}; | ||
}, | ||
); | ||
|
||
export function updateSettings(values: Partial<Settings>) { | ||
storedSettings.update((settings) => ({ ...settings, ...values })); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters