forked from 4gray/iptvnator
-
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.
feat(settings): refactor settings management and add store service
Refactor the settings management in the SettingsComponent to utilize a new SettingsStore service for better state management. Remove direct local storage access and replace it with a method to retrieve settings from the store. Update the backToHome method to handle dialog navigation. Add error logging for file reading issues and introduce an input property to determine dialog context.
- Loading branch information
Showing
3 changed files
with
110 additions
and
64 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Injectable, computed, signal } from '@angular/core'; | ||
import { StorageMap } from '@ngx-pwa/local-storage'; | ||
import { Language } from '../settings/language.enum'; | ||
import { Settings, VideoPlayer } from '../settings/settings.interface'; | ||
import { Theme } from '../settings/theme.enum'; | ||
import { STORE_KEY } from '../shared/enums/store-keys.enum'; | ||
|
||
const DEFAULT_SETTINGS: Settings = { | ||
player: VideoPlayer.VideoJs, | ||
language: Language.ENGLISH, | ||
showCaptions: false, | ||
theme: Theme.LightTheme, | ||
mpvPlayerPath: '', | ||
vlcPlayerPath: '', | ||
remoteControl: false, | ||
remoteControlPort: 3000, | ||
epgUrl: [], | ||
}; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class SettingsStore { | ||
private settings = signal<Settings>(DEFAULT_SETTINGS); | ||
|
||
// Computed values for commonly used settings | ||
readonly player = computed(() => this.settings().player); | ||
readonly showCaptions = computed(() => this.settings().showCaptions); | ||
readonly theme = computed(() => this.settings().theme); | ||
|
||
constructor(private storage: StorageMap) { | ||
this.loadSettings(); | ||
} | ||
|
||
async loadSettings() { | ||
const stored = await this.storage.get(STORE_KEY.Settings).toPromise(); | ||
if (stored) { | ||
this.settings.set({ ...DEFAULT_SETTINGS, ...(stored as Settings) }); | ||
} | ||
} | ||
|
||
async updateSettings(settings: Partial<Settings>) { | ||
const newSettings = { ...this.settings(), ...settings }; | ||
this.settings.set(newSettings); | ||
await this.storage.set(STORE_KEY.Settings, newSettings).toPromise(); | ||
} | ||
|
||
getSettings() { | ||
return this.settings; | ||
} | ||
} |
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