import { Injectable } from "@angular/core" ; import { remote } from "electron" ; import * as settings from "electron-settings" ; export enum Themes { Dark = "ultra-dark" , Light = "light" } @ Injectable ( { providedIn : "root" , } ) export class ThemeService { remote : typeof remote ; settings : typeof settings ; constructor ( ) { if ( this . isElectron ( ) ) { this . remote = window . require ( "electron" ) . remote ; this . settings = window . require ( "electron" ) . remote . require ( "electron-settings" ) ; } } public switchTheme ( theme ) { document . documentElement . setAttribute ( "data-theme" , theme ) ; const window = this . remote . getCurrentWindow ( ) ; window . setVibrancy ( theme ) ; } public initTheme ( ) { if ( this . isElectron ( ) ) { const theme = this . settings . getSync ( "appearance.theme" ) ; this . switchTheme ( theme as Themes ) ; } } private isElectron ( ) { return window && window . process && window . process . type ; } }