@@ -47,9 +47,11 @@ export default class Main extends BaseController {
47
47
48
48
public onInit ( ) {
49
49
this . db = new Database ( ) ;
50
+ this . setDefaultSettings ( ) ;
50
51
void this . handleInit ( ) ;
51
52
this . showWelcomeDialog ( ) ;
52
53
this . setModel ( new JSONModel ( this . local , true ) , "local" ) ;
54
+ this . handleTheme ( ) ;
53
55
}
54
56
55
57
private async handleInit ( ) {
@@ -78,6 +80,33 @@ export default class Main extends BaseController {
78
80
this . focusSearch ( ) ;
79
81
}
80
82
83
+ private setDefaultSettings ( ) {
84
+ if ( localStorage . getItem ( "copyWithPrefix" ) === null ) {
85
+ localStorage . setItem ( "copyWithPrefix" , "true" ) ;
86
+ }
87
+ if ( localStorage . getItem ( "resetSearchAfterCopy" ) === null ) {
88
+ localStorage . setItem ( "resetSearchAfterCopy" , "true" ) ;
89
+ }
90
+ if ( localStorage . getItem ( "theme" ) === null ) {
91
+ localStorage . setItem ( "theme" , "System" ) ;
92
+ }
93
+ }
94
+
95
+ private handleTheme ( ) {
96
+ const theme = localStorage . getItem ( "theme" ) || "System" ;
97
+ this . applyTheme ( theme ) ;
98
+
99
+ const mediaQuery = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
100
+ mediaQuery . addEventListener ( "change" , ( e ) => {
101
+ const darkMode = e . matches ;
102
+ if ( darkMode ) {
103
+ this . applyTheme ( "Dark" ) ;
104
+ } else {
105
+ this . applyTheme ( "Light" ) ;
106
+ }
107
+ } ) ;
108
+ }
109
+
81
110
private async refresh ( ) : Promise < void > {
82
111
const customTransactions = await this . db . getTransactions ( ) ;
83
112
const transactions = [ ...this . standardTransactions , ...customTransactions ] ;
0 commit comments