- if (this.auth.isLoggedIn()) {
- const theme = this.auth.getUser().theme
- if (theme !== 'instance-default') return theme
+ const theme = this.auth.isLoggedIn()
+ ? this.auth.getUser().theme
+ : this.userService.getAnonymousUser().theme
+
+ if (theme !== 'instance-default') return theme
+
+ const instanceTheme = this.serverConfig.theme.default
+ if (instanceTheme !== 'default') return instanceTheme
+
+ // Default to dark theme if available and wanted by the user
+ if (
+ this.themes.find(t => t.name === 'dark') &&
+ window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
+ ) {
+ return 'dark'