@@ -15,11 +15,11 @@ public class JsonRPCPluginSettings
1515
1616 public required string SettingPath { get ; init ; }
1717 public Dictionary < string , FrameworkElement > SettingControls { get ; } = new ( ) ;
18-
18+
1919 public IReadOnlyDictionary < string , object > Inner => Settings ;
2020 protected ConcurrentDictionary < string , object > Settings { get ; set ; }
2121 public required IPublicAPI API { get ; init ; }
22-
22+
2323 private JsonStorage < ConcurrentDictionary < string , object > > _storage ;
2424
2525 // maybe move to resource?
@@ -37,26 +37,26 @@ public async Task InitializeAsync()
3737 _storage = new JsonStorage < ConcurrentDictionary < string , object > > ( SettingPath ) ;
3838 Settings = await _storage . LoadAsync ( ) ;
3939
40- if ( Settings != null )
40+ if ( Settings != null || Configuration == null )
4141 {
4242 return ;
4343 }
4444
45- foreach ( var ( type , attributes ) in Configuration . Body )
45+ foreach ( var ( type , attributes ) in Configuration . Body )
4646 {
4747 if ( attributes . Name == null )
4848 {
4949 continue ;
5050 }
51-
51+
5252 if ( ! Settings . ContainsKey ( attributes . Name ) )
5353 {
5454 Settings [ attributes . Name ] = attributes . DefaultValue ;
5555 }
5656 }
5757 }
5858
59-
59+
6060 public void UpdateSettings ( IReadOnlyDictionary < string , object > settings )
6161 {
6262 if ( settings == null || settings . Count == 0 )
@@ -80,34 +80,35 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
8080 comboBox . Dispatcher . Invoke ( ( ) => comboBox . SelectedItem = value ) ;
8181 break ;
8282 case CheckBox checkBox :
83- checkBox . Dispatcher . Invoke ( ( ) => checkBox . IsChecked = value is bool isChecked ? isChecked : bool . Parse ( value as string ?? string . Empty ) ) ;
83+ checkBox . Dispatcher . Invoke ( ( ) =>
84+ checkBox . IsChecked = value is bool isChecked
85+ ? isChecked
86+ : bool . Parse ( value as string ?? string . Empty ) ) ;
8487 break ;
8588 }
8689 }
8790 }
91+
8892 Save ( ) ;
8993 }
90-
94+
9195 public async Task SaveAsync ( )
9296 {
9397 await _storage . SaveAsync ( ) ;
9498 }
95-
99+
96100 public void Save ( )
97101 {
98102 _storage . Save ( ) ;
99103 }
100-
104+
101105 public Control CreateSettingPanel ( )
102106 {
103- if ( Settings == null )
107+ if ( Settings == null || Settings . Count == 0 )
104108 return new ( ) ;
105109
106110 var settingWindow = new UserControl ( ) ;
107- var mainPanel = new Grid
108- {
109- Margin = settingPanelMargin , VerticalAlignment = VerticalAlignment . Center
110- } ;
111+ var mainPanel = new Grid { Margin = settingPanelMargin , VerticalAlignment = VerticalAlignment . Center } ;
111112
112113 ColumnDefinition gridCol1 = new ColumnDefinition ( ) ;
113114 ColumnDefinition gridCol2 = new ColumnDefinition ( ) ;
@@ -242,10 +243,7 @@ public Control CreateSettingPanel()
242243 Margin = new Thickness ( 10 , 0 , 0 , 0 ) , Content = "Browse"
243244 } ;
244245
245- var dockPanel = new DockPanel ( )
246- {
247- Margin = settingControlMargin
248- } ;
246+ var dockPanel = new DockPanel ( ) { Margin = settingControlMargin } ;
249247
250248 DockPanel . SetDock ( Btn , Dock . Right ) ;
251249 dockPanel . Children . Add ( Btn ) ;
@@ -352,7 +350,10 @@ public Control CreateSettingPanel()
352350 case "checkbox" :
353351 var checkBox = new CheckBox
354352 {
355- IsChecked = Settings [ attribute . Name ] is bool isChecked ? isChecked : bool . Parse ( attribute . DefaultValue ) ,
353+ IsChecked =
354+ Settings [ attribute . Name ] is bool isChecked
355+ ? isChecked
356+ : bool . Parse ( attribute . DefaultValue ) ,
356357 Margin = settingCheckboxMargin ,
357358 HorizontalAlignment = System . Windows . HorizontalAlignment . Right ,
358359 ToolTip = attribute . Description
@@ -375,14 +376,12 @@ public Control CreateSettingPanel()
375376
376377 break ;
377378 case "hyperlink" :
378- var hyperlink = new Hyperlink
379- {
380- ToolTip = attribute . Description , NavigateUri = attribute . url
381- } ;
379+ var hyperlink = new Hyperlink { ToolTip = attribute . Description , NavigateUri = attribute . url } ;
382380
383381 var linkbtn = new System . Windows . Controls . Button
384382 {
385- HorizontalAlignment = System . Windows . HorizontalAlignment . Right , Margin = settingControlMargin
383+ HorizontalAlignment = System . Windows . HorizontalAlignment . Right ,
384+ Margin = settingControlMargin
386385 } ;
387386
388387 linkbtn . Content = attribute . urlLabel ;
@@ -408,12 +407,9 @@ public Control CreateSettingPanel()
408407 mainPanel . Children . Add ( panel ) ;
409408 mainPanel . Children . Add ( contentControl ) ;
410409 rowCount ++ ;
411-
412410 }
413411
414412 return settingWindow ;
415413 }
416-
417-
418414 }
419415}
0 commit comments