clean, add backend capability to change theme setting

This commit is contained in:
marlon-erler
2026-04-09 17:32:17 +00:00
parent 16f9c5ee81
commit ed29696375
4 changed files with 46 additions and 35 deletions
+42 -28
View File
@@ -1,6 +1,5 @@
// this file is responsible for all settings. // this file is responsible for all settings.
import { Languages } from "../../View/translations";
import StorageModel, { StorageModelSubPaths, filePaths } from "./storageModel"; import StorageModel, { StorageModelSubPaths, filePaths } from "./storageModel";
export default class SettingsModel { export default class SettingsModel {
@@ -10,63 +9,66 @@ export default class SettingsModel {
username: string; username: string;
firstDayOfWeek: string; firstDayOfWeek: string;
language: string; language: string;
theme: string;
// storage // storage
setName(newValue: string): void { private storeSetting(pathName: keyof typeof filePaths.settingsModel, value: string): void {
this.username = newValue;
const path = StorageModel.getPath( const path = StorageModel.getPath(
StorageModelSubPaths.SettingsModel, StorageModelSubPaths.SettingsModel,
filePaths.settingsModel.username, filePaths.settingsModel[pathName],
); );
this.storageModel.write(path, newValue); this.storageModel.write(path, value);
}
setName(newValue: string): void {
this.username = newValue;
this.storeSetting("username", newValue);
} }
setFirstDayOfWeek(newValue: string): void { setFirstDayOfWeek(newValue: string): void {
this.firstDayOfWeek = newValue; this.firstDayOfWeek = newValue;
const path = StorageModel.getPath( this.storeSetting("firstDayOfWeek", newValue);
StorageModelSubPaths.SettingsModel,
filePaths.settingsModel.firstDayOfWeek,
);
this.storageModel.write(path, newValue);
} }
setLanguage(newValue: string): void { setLanguage(newValue: string): void {
this.language = newValue; this.language = newValue;
const path = StorageModel.getPath( this.storeSetting("language", newValue);
StorageModelSubPaths.SettingsModel, }
filePaths.settingsModel.language,
); setTheme(newValue: string): void {
this.storageModel.write(path, newValue); this.theme = newValue;
this.storeSetting("theme", newValue);
} }
// load // load
loadUsername(): void { private readSetting(pathName: keyof typeof filePaths.settingsModel): string {
const path = StorageModel.getPath( const path = StorageModel.getPath(
StorageModelSubPaths.SettingsModel, StorageModelSubPaths.SettingsModel,
filePaths.settingsModel.username, filePaths.settingsModel[pathName],
); );
const content = this.storageModel.read(path); return this.storageModel.read(path);
}
loadUsername(): void {
const content = this.readSetting("username");
this.username = content ?? ""; this.username = content ?? "";
} }
loadFirstDayofWeek(): void { loadFirstDayofWeek(): void {
const path = StorageModel.getPath( const content = this.readSetting("firstDayOfWeek");
StorageModelSubPaths.SettingsModel,
filePaths.settingsModel.firstDayOfWeek,
);
const content = this.storageModel.read(path);
this.firstDayOfWeek = content ?? "0"; this.firstDayOfWeek = content ?? "0";
} }
loadLanguage(): void { loadLanguage(): void {
const path = StorageModel.getPath( const content = this.readSetting("language");
StorageModelSubPaths.SettingsModel,
filePaths.settingsModel.language,
);
const content = this.storageModel.read(path);
this.language = content ?? SettingsModel.getSystemLanguage(); this.language = content ?? SettingsModel.getSystemLanguage();
} }
loadTheme(): void {
const content = this.readSetting("theme");
this.theme = content ?? ThemeSettings.System;
}
// init // init
constructor(storageModel: StorageModel) { constructor(storageModel: StorageModel) {
this.storageModel = storageModel; this.storageModel = storageModel;
@@ -87,3 +89,15 @@ export default class SettingsModel {
} }
} }
} }
export enum Languages {
English = "en",
German = "de",
Spanish = "es",
}
export enum ThemeSettings {
Dark = "dark",
Light = "light",
System = "system",
}
+1
View File
@@ -266,5 +266,6 @@ export const filePaths = {
username: ["user-name"], username: ["user-name"],
firstDayOfWeek: ["first-day-of-week"], firstDayOfWeek: ["first-day-of-week"],
language: ["language"], language: ["language"],
theme: ["theme"],
}, },
}; };
+2 -1
View File
@@ -1,6 +1,6 @@
import * as React from "bloatless-react"; import * as React from "bloatless-react";
import { languageNames, Languages } from "../translations"; import { languageNames } from "../translations";
import SettingsViewModel, { import SettingsViewModel, {
SettingsModalPages, SettingsModalPages,
} from "../../ViewModel/Global/settingsViewModel"; } from "../../ViewModel/Global/settingsViewModel";
@@ -8,6 +8,7 @@ import { SplitModal } from "../Components/splitModal";
import { InfoTile } from "../Components/infoTile"; import { InfoTile } from "../Components/infoTile";
import { Option } from "../Components/option"; import { Option } from "../Components/option";
import CoreViewModel from "../../ViewModel/Global/coreViewModel"; import CoreViewModel from "../../ViewModel/Global/coreViewModel";
import { Languages } from "../../Model/Global/settingsModel";
export function SettingsModal( export function SettingsModal(
coreViewModel: CoreViewModel, coreViewModel: CoreViewModel,
-5
View File
@@ -835,8 +835,3 @@ export const languageNames = {
} }
export type Translations = typeof englishTranslations; export type Translations = typeof englishTranslations;
export enum Languages {
English = "en",
German = "de",
Spanish = "es",
}