Skip to content

Commit

Permalink
Handle undefined theme in the site template widget (#4454)
Browse files Browse the repository at this point in the history
* Handle undefined theme

* Fix comment
  • Loading branch information
jeremy-rifkin authored and mattgodbolt committed Jan 24, 2023
1 parent 6a3c1e4 commit ffc1a30
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion static/settings.ts
Expand Up @@ -64,7 +64,7 @@ export interface SiteSettings {
showMinimap: boolean;
showQuickSuggestions: boolean;
tabWidth: number;
theme: Themes;
theme: Themes | undefined;
useCustomContextMenu: boolean;
useSpaces: boolean;
useVim: boolean;
Expand Down
2 changes: 1 addition & 1 deletion static/themes.ts
Expand Up @@ -155,7 +155,7 @@ export class Themer {
}

private onSettingsChange(newSettings: SiteSettings) {
const newTheme = newSettings.theme in themes ? themes[newSettings.theme] : themes.default;
const newTheme = newSettings.theme && newSettings.theme in themes ? themes[newSettings.theme] : themes.default;
if (!newTheme.monaco) newTheme.monaco = 'vs';
this.setTheme(newTheme);
}
Expand Down
5 changes: 4 additions & 1 deletion static/widgets/site-templates-widget.ts
Expand Up @@ -47,7 +47,10 @@ class SiteTemplatesWidget {
}
getCurrentTheme() {
const theme = Settings.getStoredSettings()['theme'];
if (theme === 'system') {
if (!theme) {
// apparently this can happen
return 'default';
} else if (theme === 'system') {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
return 'dark';
} else {
Expand Down

0 comments on commit ffc1a30

Please sign in to comment.