1- using System ;
21using Coder . Desktop . App . Services ;
32using CommunityToolkit . Mvvm . ComponentModel ;
43using CommunityToolkit . Mvvm . Input ;
4+ using Microsoft . Extensions . Logging ;
55using Microsoft . UI . Dispatching ;
66using Microsoft . UI . Xaml ;
77using Microsoft . UI . Xaml . Controls ;
8+ using System ;
89
910namespace Coder . Desktop . App . ViewModels ;
1011
@@ -13,11 +14,48 @@ public partial class SettingsViewModel : ObservableObject
1314 private Window ? _window ;
1415 private DispatcherQueue ? _dispatcherQueue ;
1516
17+ private readonly ILogger < SettingsViewModel > _logger ;
18+
19+ [ ObservableProperty ]
20+ public partial bool ConnectOnLaunch { get ; set ; } = false ;
21+
22+ [ ObservableProperty ]
23+ public partial bool StartOnLogin { get ; set ; } = false ;
24+
1625 private ISettingsManager _settingsManager ;
1726
18- public SettingsViewModel ( ISettingsManager settingsManager )
27+ public SettingsViewModel ( ILogger < SettingsViewModel > logger , ISettingsManager settingsManager )
1928 {
2029 _settingsManager = settingsManager ;
30+ _logger = logger ;
31+ ConnectOnLaunch = _settingsManager . Read ( SettingsManager . ConnectOnLaunchKey , false ) ;
32+ StartOnLogin = _settingsManager . Read ( SettingsManager . StartOnLoginKey , false ) ;
33+
34+ this . PropertyChanged += ( _ , args ) =>
35+ {
36+ if ( args . PropertyName == nameof ( ConnectOnLaunch ) )
37+ {
38+ try
39+ {
40+ _settingsManager . Save ( SettingsManager . ConnectOnLaunchKey , ConnectOnLaunch ) ;
41+ }
42+ catch ( Exception ex )
43+ {
44+ Console . WriteLine ( $ "Error saving { SettingsManager . ConnectOnLaunchKey } setting: { ex . Message } ") ;
45+ }
46+ }
47+ else if ( args . PropertyName == nameof ( StartOnLogin ) )
48+ {
49+ try
50+ {
51+ _settingsManager . Save ( SettingsManager . StartOnLoginKey , StartOnLogin ) ;
52+ }
53+ catch ( Exception ex )
54+ {
55+ Console . WriteLine ( $ "Error saving { SettingsManager . StartOnLoginKey } setting: { ex . Message } ") ;
56+ }
57+ }
58+ } ;
2159 }
2260
2361 public void Initialize ( Window window , DispatcherQueue dispatcherQueue )
@@ -27,28 +65,4 @@ public void Initialize(Window window, DispatcherQueue dispatcherQueue)
2765 if ( ! _dispatcherQueue . HasThreadAccess )
2866 throw new InvalidOperationException ( "Initialize must be called from the UI thread" ) ;
2967 }
30-
31- [ RelayCommand ]
32- private void SaveSetting ( )
33- {
34- //_settingsManager.Save();
35- }
36-
37- [ RelayCommand ]
38- private void ShowSettingsDialog ( )
39- {
40- if ( _window is null || _dispatcherQueue is null )
41- throw new InvalidOperationException ( "Initialize must be called before showing the settings dialog." ) ;
42- // Here you would typically open a settings dialog or page.
43- // For example, you could navigate to a SettingsPage in your app.
44- // This is just a placeholder for demonstration purposes.
45- // Display MessageBox and show a message
46- var message = $ "Settings dialog opened. Current setting: { _settingsManager . Read ( "SomeSetting" , false ) } \n " +
47- "You can implement your settings dialog here." ;
48- var dialog = new ContentDialog ( ) ;
49- dialog . Title = "Settings" ;
50- dialog . Content = message ;
51- dialog . XamlRoot = _window . Content . XamlRoot ;
52- _ = dialog . ShowAsync ( ) ;
53- }
5468}
0 commit comments