1- using Nickvision . Application . Shared . Helpers ;
1+ using Microsoft . Data . Sqlite ;
2+ using Nickvision . Application . Shared . Helpers ;
23using Nickvision . Application . Shared . Models ;
34using Nickvision . Desktop . Application ;
45using Nickvision . Desktop . Globalization ;
6+ using System ;
57using System . Collections ;
68using System . Collections . Generic ;
79using System . Linq ;
810using System . Threading . Tasks ;
911
1012namespace Nickvision . Application . Shared . Controllers ;
1113
12- public class PreferencesViewController
14+ public class PreferencesViewController : IDisposable
1315{
1416 private readonly IConfigurationService _configurationService ;
1517 private readonly ITranslationService _translationService ;
18+ private readonly SqliteTransaction _transaction ;
1619
1720 public IReadOnlyList < SelectionItem < string > > AvailableTranslationLanguages { get ; }
1821 public IReadOnlyList < SelectionItem < Theme > > Themes { get ; }
@@ -21,6 +24,7 @@ public PreferencesViewController(IConfigurationService configurationService, ITr
2124 {
2225 _configurationService = configurationService ;
2326 _translationService = translationService ;
27+ _transaction = _configurationService . CreateTransaction ( ) ;
2428 AvailableTranslationLanguages = new List < SelectionItem < string > > ( )
2529 {
2630 new SelectionItem < string > ( string . Empty , _translationService . _ ( "System" ) , string . IsNullOrEmpty ( _configurationService . TranslationLanguage ) ) ,
@@ -39,6 +43,12 @@ public PreferencesViewController(IConfigurationService configurationService, ITr
3943 new SelectionItem < Theme > ( Models . Theme . System , _translationService . _p ( "Theme" , "System" ) , _configurationService . Theme == Models . Theme . System ) ,
4044 } ;
4145 }
46+
47+ ~ PreferencesViewController ( )
48+ {
49+ Dispose ( false ) ;
50+ }
51+
4252 public SelectionItem < Theme > Theme
4353 {
4454 set => _configurationService . Theme = value . Value ;
@@ -56,5 +66,20 @@ public bool AllowPreviewUpdates
5666 set => _configurationService . AllowPreviewUpdates = value ;
5767 }
5868
59- public Task SaveConfigurationAsync ( ) => _configurationService . SaveAsync ( ) ;
69+ public void Dispose ( )
70+ {
71+ Dispose ( true ) ;
72+ GC . SuppressFinalize ( this ) ;
73+ }
74+
75+ public Task SaveConfigurationAsync ( ) => _transaction . CommitAsync ( ) ;
76+
77+ private void Dispose ( bool disposing )
78+ {
79+ if ( ! disposing )
80+ {
81+ return ;
82+ }
83+ _transaction . Dispose ( ) ;
84+ }
6085}
0 commit comments