Skip to content

AppSettings

0x5BFA edited this page Jan 18, 2025 · 14 revisions

Overview

Current settings manager is separated into multiple services that share the same json context object is configured in DI container. We rather should have a static class that can be initialized whenever we want and get/set settings values from/to a centralized static manager

Definition

public sealed partial class AppSettings {}

Usage

Initialization & Disposal

// Sets up the watcher to the json file and gets a handle of it with shareable access, etc.
AppSettings.Initialize("The full path to the json");

// Free the watcher and the handle for the json file at the main process termination, etc.
AppSettings.Dispose();

Get or set a setting

if (AppSettings.SaveLastOpenedSessions)
    AppSettings.SaveLastOpenedSessions = false;

Create a setting

// AppSettings.Layout.cs
public sealed partial class AppSettings
{
    [GeneratedAppSettingsProperty(DefaultValue = false)]
    public partial bool SyncFolderPreferencesAcrossDirectories { get; set; }

    [GeneratedAppSettingsProperty(DefaultValue = FolderLayoutModes.Adaptive)]
    public partial FolderLayoutModes DefaultLayoutMode { get; set; }
}

// AppSettings.Appearance.cs
public sealed partial class AppSettings
{
    [GeneratedAppSettingsProperty(DefaultValue = Math.Min(Math.Max(Get(255d), Constants.UI.MinimumSidebarWidth), 500d))]
    public partial double SidebarWidth { get; set; }

    [GeneratedAppSettingsProperty(DefaultValue = true)]
    public partial bool IsSidebarOpen { get; set; }
}

Source generator

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class GeneratedAppSettingsPropertyAttribute : Attribute {}
// AppSettings.General.g.cs
public partial bool SaveLastOpenedSessions
{
    get => Get(true);
    set => Set(value);
}

JSON validation

We would use this event when we try to get a setting for the first time after the cold launch and it'd possibly be before the UI is fully initialized; therefore, we have to wait until the all UI elements in MainPage then display an error dialog that tells user that the settings json file has been reset.

public event EventHandler<JsonSerializationException> JsonDeserializationFailed;
Controls
  • FolderBrowser
  • DetailsFolderView
  • GridFolderView
  • ListFolderView
  • TilesFolderView
  • ContentFolderView
  • ColumnsFolderView
  • TreeFolderView
  • GalleryFolderView
  • HomeFolderView
  • RectanglurSelectionVisual
  • DataGrid
  • SidebarView
  • Omnibar
  • Toolbar
  • FilePreviewPresenter
  • ColorTags
  • RichTokens
  • TerminalView
API
  • WindowsStorable
  • ArchiveStorable
  • HomeStorable
  • FtpStorable
  • SftpStorable
  • WebDAVStorable
Infrastructure
  • CommandManager
  • MultitaskingManager
  • DialogManager
  • AppSettings
  • OperationServer

Copyright © 2025 0x5BFA. All rights reserved. Do not copy or redistribute modified versions.

Clone this wiki locally