2025-04-22 18:37:58 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-04-22 18:57:47 -07:00
|
|
|
import { AtomOneDark } from './atom-one-dark.js';
|
|
|
|
|
import { Dracula } from './dracula.js';
|
|
|
|
|
import { GitHub } from './github.js';
|
|
|
|
|
import { GoogleCode } from './googlecode.js';
|
|
|
|
|
import { VS } from './vs.js';
|
2025-04-22 18:37:58 -07:00
|
|
|
import { VS2015 } from './vs2015.js';
|
2025-04-22 18:57:47 -07:00
|
|
|
import { XCode } from './xcode.js';
|
2025-04-22 18:37:58 -07:00
|
|
|
import { Theme } from './theme.js';
|
|
|
|
|
|
2025-04-22 18:57:47 -07:00
|
|
|
export interface ThemeDisplay {
|
|
|
|
|
name: string;
|
|
|
|
|
active: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 18:37:58 -07:00
|
|
|
class ThemeManager {
|
|
|
|
|
private static readonly DEFAULT_THEME: Theme = VS2015;
|
|
|
|
|
private readonly availableThemes: Theme[];
|
|
|
|
|
private activeTheme: Theme;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
2025-04-22 18:57:47 -07:00
|
|
|
this.availableThemes = [
|
|
|
|
|
AtomOneDark,
|
|
|
|
|
Dracula,
|
2025-04-23 17:37:09 -07:00
|
|
|
VS, // Light mode.
|
2025-04-22 18:57:47 -07:00
|
|
|
VS2015,
|
|
|
|
|
GitHub,
|
|
|
|
|
GoogleCode,
|
|
|
|
|
XCode,
|
|
|
|
|
];
|
2025-04-22 18:37:58 -07:00
|
|
|
this.activeTheme = ThemeManager.DEFAULT_THEME;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 18:57:47 -07:00
|
|
|
/**
|
|
|
|
|
* Returns a list of available theme names.
|
|
|
|
|
*/
|
|
|
|
|
getAvailableThemes(): ThemeDisplay[] {
|
|
|
|
|
return this.availableThemes.map((theme) => ({
|
|
|
|
|
name: theme.name,
|
|
|
|
|
active: theme === this.activeTheme,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the active theme.
|
|
|
|
|
* @param themeName The name of the theme to activate.
|
|
|
|
|
*/
|
|
|
|
|
setActiveTheme(themeName: string): void {
|
|
|
|
|
const foundTheme = this.availableThemes.find(
|
|
|
|
|
(theme) => theme.name === themeName,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (foundTheme) {
|
|
|
|
|
this.activeTheme = foundTheme;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`Theme "${themeName}" not found.`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 18:37:58 -07:00
|
|
|
/**
|
|
|
|
|
* Returns the currently active theme object.
|
|
|
|
|
*/
|
|
|
|
|
getActiveTheme(): Theme {
|
|
|
|
|
return this.activeTheme;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Export an instance of the ThemeManager
|
|
|
|
|
export const themeManager = new ThemeManager();
|