File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public Settings Settings
1919 return _settings ;
2020 }
2121
22- _settings = Application . Current . GetRequiredService < IConfiguration > ( ) . Get < Settings > ( ) ?? new Settings ( ) ;
22+ _settings = LoadSettingsFromFile ( ) ;
2323
2424 return _settings ;
2525 }
@@ -46,6 +46,27 @@ public static string GetSettingsFilePath()
4646 return Path . Combine ( GetSettingsPath ( ) , "settings.json" ) ;
4747 }
4848
49+ public static Settings LoadSettingsFromFile ( )
50+ {
51+ try
52+ {
53+ var path = GetSettingsFilePath ( ) ;
54+
55+ if ( File . Exists ( path ) )
56+ {
57+ using var fs = new FileStream ( path , FileMode . Open , FileAccess . Read ) ;
58+
59+ if ( fs . CanRead )
60+ {
61+ return JsonSerializer . Deserialize < Settings > ( fs ) ;
62+ }
63+ }
64+ }
65+ catch ( Exception ) { }
66+
67+ return new Settings ( ) ;
68+ }
69+
4970 public static bool EnsureSettingDirExists ( )
5071 {
5172 try
Original file line number Diff line number Diff line change 1010using LiveChartsCore . SkiaSharpView . Painting ;
1111using LiveChartsCore . Themes ;
1212using Mapster ;
13- using Microsoft . Extensions . Configuration ;
1413using NReco . Logging . File ;
1514using OpenTelemetry . Logs ;
1615using OpenTelemetry . Metrics ;
@@ -82,14 +81,7 @@ private static ServiceProvider BuildLauncherServices()
8281 . ShallowCopyForSameType ( true )
8382 . PreserveReference ( true ) ;
8483
85- var cfg = new ConfigurationManager ( ) ;
86- if ( ! Design . IsDesignMode )
87- {
88- cfg . AddJsonFile ( SettingsService . GetSettingsFilePath ( ) , true , true ) ;
89- }
90- services . AddSingleton < IConfiguration > ( cfg ) ;
91-
92- var settings = cfg . Get < Settings > ( ) ?? new Settings ( ) ;
84+ var settings = SettingsService . LoadSettingsFromFile ( ) ;
9385
9486 services . AddServices ( ) ;
9587 services . AddLogging ( x => x . SetMinimumLevel ( LogLevel . Debug ) ) ;
Original file line number Diff line number Diff line change @@ -22,9 +22,6 @@ public override void Initialize()
2222
2323 var services = new ServiceCollection ( ) ;
2424
25- var cfg = new ConfigurationManager ( ) ;
26- services . AddSingleton < IConfiguration > ( cfg ) ;
27-
2825 // Services
2926 services . AddServices ( ) ;
3027 services . AddLogging ( ) ;
You can’t perform that action at this time.
0 commit comments