1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/themes/default-theme.injectable.ts
Sebastian Malton 963651ef4b Make LensTheme fully injectable and runnable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-12-06 09:19:00 -05:00

27 lines
809 B
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { lensThemeDeclarationInjectionToken } from "./declaration";
const defaultLensThemeInjectable = getInjectable({
id: "default-lens-theme",
instantiate: (di) => {
const themes = di.injectMany(lensThemeDeclarationInjectionToken);
const [defaultTheme, ...rest] = themes.filter(theme => theme.isDefault);
if (rest.length > 0) {
throw new Error("Multiple LensTheme's are declared as the default");
}
if (!defaultTheme) {
throw new Error("No LensTheme is declared as the default");
}
return defaultTheme;
},
});
export default defaultLensThemeInjectable;