Settings storage and preferences
Settings storage gives Screenbox one shared way to save user choices and expose them as live application state. Settings contexts group those choices by user concern, while the settings page lets users change them and starts the related side effects.
Settings storage
The settings storage service is a small key-value boundary between application preferences and the Windows local settings store. A missing value or a value with the wrong type returns the caller's default, so each setting defines its own safe first-run behavior. The boundary can also use another key-value store, which keeps settings contexts independent from the platform store and supports isolated tests. (Screenbox.Core/…/ISettingsStorage.cs• L3-23, Screenbox.Core/…/SettingsStorage.cs• L6-35)
Settings contexts
Settings contexts are long-lived observable state holders for related preferences. Each context maps a typed property to a stable storage key and a default value. The shared base keeps a memory cache after the first read, writes changed values to storage, and reports changes to both data binding and interested application services. (Screenbox.Core/…/SettingsContextBase.cs• L12-23, Screenbox.Core/…/SettingsContextBase.cs• L25-141)
The application creates one shared instance of each context and one settings storage service. This lets the settings page and other application flows read the same current values instead of keeping separate copies. (Screenbox.Core/…/ServiceHelpers.cs• L58-79)
Preference domains
The contexts divide preferences by the behavior they control:
| Context | User-configurable behavior |
|---|---|
GeneralSettingsContext | Theme, language, recent-item visibility, folder enqueue behavior, and multiple application instances |
LibrarySettingsContext | Library indexing, removable-storage search, and song and album sort order |
PlaybackSettingsContext | Volume limits, repeat mode, subtitle language, and playback-position save and restore |
PlayerSettingsContext | Player sizing, controls, seek steps, gestures, frame-capture location, visualizer choice, video scaling, and advanced player arguments |
These domains also give change listeners a narrow contract. A setting change message names the owning context, property, old value, and new value, so a receiver can respond only to the behavior it owns. (Screenbox.Core/…/GeneralSettingsContext.cs• L6-51, Screenbox.Core/…/LibrarySettingsContext.cs• L6-43, Screenbox.Core/…/PlaybackSettingsContext.cs• L6-57, Screenbox.Core/…/PlayerSettingsContext.cs• L8-161, Screenbox.Core/…/SettingChangedMessage.cs• L5-20)
Setting change flow
The diagram shows how a preference moves from a settings control to persistent state and then to application behavior.
flowchart LR
Control[Settings control] --> ViewModel[SettingsPageViewModel]
ViewModel --> Context[Typed settings context]
Context --> Cache[In-memory current value]
Context --> Store[Local settings storage]
Context --> Notify[Binding and setting-change messages]
Notify --> Behavior[Application behavior]
The base context does not write again when a value is equal to its current value. A real change updates the cache and storage before it notifies listeners. Enum choices use their stored numeric value while the context exposes the typed enum to the rest of the app. (Screenbox.Core/…/SettingsContextBase.cs• L59-101, Screenbox.Core/…/SettingsContextBase.cs• L104-139)
Settings-facing views
The settings view presents the preference domains as grouped controls rather than as a raw storage list. The page view model supplies the shared contexts, option lists, folder collections, and commands that connect those controls to library, history, playback, and file services. (Screenbox.Core/…/SettingsPageViewModel.cs• L24-66, Screenbox/Pages/SettingsPage.xaml#L148-L271)
Preference controls
The page groups settings into libraries, personalization, general behavior, player behavior, advanced behavior, privacy, and about information. Direct two-way bindings update context properties as the user changes a control. Some controls are device-specific, such as desktop player gestures or Xbox removable storage. (Screenbox/Pages/SettingsPage.xaml#L273-L400, Screenbox/Pages/SettingsPage.xaml#L402-L720)
The view model also owns settings that need work beyond a value write. It refreshes library content after folder or removable-storage changes, clears recent items when recent visibility is disabled, and manages the saved access token for the frame-capture folder. (Screenbox.Core/…/SettingsPageViewModel.cs• L128-175, Screenbox.Core/…/SettingsPageViewModel.cs• L177-243, Screenbox.Core/…/SettingsPageViewModel.cs• L259-285)
Immediate and deferred effects
Most preferences affect the app as soon as their bound property changes. Theme and language are applied by the page, while selected player changes can show a pending relaunch notice when the new value needs application startup to take effect. (Screenbox/…/SettingsPage.xaml.cs• L26-38, Screenbox/…/SettingsPage.xaml.cs• L71-83, Screenbox/Pages/SettingsPage.xaml#L759-L770)
The settings page loads external state when it opens and stops device monitoring when it closes. This keeps library locations, removable folders, frame-capture access, and visualizer choices aligned with the current platform state. (Screenbox/…/SettingsPage.xaml.cs• L52-64, Screenbox.Core/…/SettingsPageViewModel.cs• L288-339)
Application behavior links
Settings influence flows outside the settings page through the shared contexts. For example, the launch path reads the multiple-instance preference before it chooses instance routing, and file activation reads the folder-enqueue preference before it builds the playback queue. (Screenbox/Program.cs• L16-37, Screenbox/App.xaml.cs• L207-235)
This separation keeps the page focused on user interaction. Other parts of the application consume the same context values or their change messages, so a preference remains useful even when the user changes it outside the flow that first displays it.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep each public setting property, its storage key, and its default value aligned. A key change can make existing user preferences appear lost.
- Keep enum values stable when they are stored as integers. Reordering an enum can change the meaning of saved choices.
- When a setting needs a live effect, connect its context change message or view-model change handler to the owning behavior.
- When a setting needs a relaunch, update both the change check and the pending-change notice so the user sees the required action.
- When a setting stores a file or folder reference, preserve the access-token lifecycle with the platform permission list.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A stored value has a type that does not match the requested setting type | The setting falls back to its default | Keep storage keys and value types stable. |
| A setting is changed to the same value | No write or change notification occurs | Treat the context property as the source of truth for current state. |
| A saved frame-capture token no longer resolves | The folder cannot open or display | Reload the folder through the file service and handle the failure. |
| Library access is denied during a settings refresh | The requested library does not update | Surface the access error through the settings notification path. |
| A startup-only preference changes during the session | The current process still uses the old startup state | Show the relaunch-required notice. |
Key files
| File | Why to read it |
|---|---|
| Screenbox.Core/…/ISettingsStorage.cs | Defines the storage boundary and default-value contract. |
| Screenbox.Core/…/SettingsStorage.cs | Shows how preferences reach Windows local settings. |
| Screenbox.Core/…/SettingsContextBase.cs | Defines shared caching, persistence, and change notification behavior. |
| Screenbox.Core/…/GeneralSettingsContext.cs | Shows general application and shell preferences. |
| Screenbox.Core/…/LibrarySettingsContext.cs | Shows library behavior preferences. |
| Screenbox.Core/…/PlaybackSettingsContext.cs | Shows playback and position-history preferences. |
| Screenbox.Core/…/PlayerSettingsContext.cs | Shows player and advanced behavior preferences. |
| Screenbox.Core/…/SettingsPageViewModel.cs | Connects settings controls to platform, library, history, and file actions. |
Screenbox/Pages/SettingsPage.xaml | Shows how the product presents settings to users. |
| Screenbox/…/SettingsPage.xaml.cs | Applies page-level theme and language effects and manages page lifecycle. |
| Screenbox.Core/…/SettingChangedMessage.cs | Defines the typed change signal for other application behaviors. |