@@ -58,6 +58,7 @@ async function createInitialDatabase() {
58
58
59
59
const schema = fs . readFileSync ( `${ resourceDir . DB_INIT_DIR } /schema.sql` , "utf-8" ) ;
60
60
const demoFile = fs . readFileSync ( `${ resourceDir . DB_INIT_DIR } /demo.zip` ) ;
61
+ const defaultTheme = await getDefaultTheme ( ) ;
61
62
62
63
let rootNote ! : BNote ;
63
64
@@ -87,7 +88,7 @@ async function createInitialDatabase() {
87
88
} ) . save ( ) ;
88
89
89
90
optionsInitService . initDocumentOptions ( ) ;
90
- optionsInitService . initNotSyncedOptions ( true , { } ) ;
91
+ optionsInitService . initNotSyncedOptions ( true , defaultTheme , { } ) ;
91
92
optionsInitService . initStartupOptions ( ) ;
92
93
password . resetPassword ( ) ;
93
94
} ) ;
@@ -118,19 +119,20 @@ async function createInitialDatabase() {
118
119
initDbConnection ( ) ;
119
120
}
120
121
121
- function createDatabaseForSync ( options : OptionRow [ ] , syncServerHost = '' , syncProxy = '' ) {
122
+ async function createDatabaseForSync ( options : OptionRow [ ] , syncServerHost = '' , syncProxy = '' ) {
122
123
log . info ( "Creating database for sync" ) ;
123
124
124
125
if ( isDbInitialized ( ) ) {
125
126
throw new Error ( "DB is already initialized" ) ;
126
127
}
127
128
129
+ const defaultTheme = await getDefaultTheme ( ) ;
128
130
const schema = fs . readFileSync ( `${ resourceDir . DB_INIT_DIR } /schema.sql` , "utf8" ) ;
129
131
130
132
sql . transactional ( ( ) => {
131
133
sql . executeScript ( schema ) ;
132
134
133
- optionsInitService . initNotSyncedOptions ( false , { syncServerHost, syncProxy } ) ;
135
+ optionsInitService . initNotSyncedOptions ( false , defaultTheme , { syncServerHost, syncProxy } ) ;
134
136
135
137
// document options required for sync to kick off
136
138
for ( const opt of options ) {
@@ -141,6 +143,16 @@ function createDatabaseForSync(options: OptionRow[], syncServerHost = '', syncPr
141
143
log . info ( "Schema and not synced options generated." ) ;
142
144
}
143
145
146
+ async function getDefaultTheme ( ) {
147
+ if ( utils . isElectron ( ) ) {
148
+ const { nativeTheme} = await import ( "electron" ) ;
149
+ return nativeTheme . shouldUseDarkColors ? 'dark' : 'light' ;
150
+ } else {
151
+ // default based on the poll in https://github.com/zadam/trilium/issues/2516
152
+ return "dark" ;
153
+ }
154
+ }
155
+
144
156
function setDbAsInitialized ( ) {
145
157
if ( ! isDbInitialized ( ) ) {
146
158
optionService . setOption ( 'initialized' , 'true' ) ;
0 commit comments