Skip to content

Commit

Permalink
chore: refactored api of system-theme-extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Givanyan committed Feb 7, 2024
1 parent 88072e2 commit a5fc436
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class WebEngine extends Friend implements SystemThemeExtractor {
}

/** @inheritDoc */
subscribe(cb: (value: string) => void): void {
onChange(cb: (value: string) => void): void {
if (this.darkThemeMq != null) {
return;
}
Expand All @@ -47,7 +47,7 @@ export default class WebEngine extends Friend implements SystemThemeExtractor {
}

/** @inheritDoc */
unsubscribe(): void {
destroy(): void {
if (this.darkThemeMq == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ export interface SystemThemeExtractor {
/**
* Retrieves the current system visual appearance theme
*/
getSystemTheme(): PromiseLike<string>;
getSystemTheme(): Promise<string>;

/**
* Initializes an event listener for changes in the system's visual appearance theme
*
* @param cb - A callback function to be invoked when the theme changes.
* It receives the color scheme identifier as a string parameter by which project theme can be selected.
*/
subscribe(cb: (value: string) => void): void;
onChange(cb: (value: string) => void): void;

/**
* Terminates the event listener for changes in the system's visual appearance theme
*/
unsubscribe(): void;
destroy(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ export default class ThemeManager extends Friend {
/**
* Sets the actual system theme and activates the system theme change listener
*/
useSystem(): PromiseLike<void> {
useSystem(): Promise<void> {
return this.systemThemeExtractor.getSystemTheme().then((value) => {
this.systemThemeExtractor.unsubscribe();
this.systemThemeExtractor.subscribe(
this.systemThemeExtractor.destroy();
this.systemThemeExtractor.onChange(
(value: string) => {
value = this.getThemeAlias(value);
void this.changeTheme({value, isSystem: true});
Expand Down Expand Up @@ -173,7 +173,7 @@ export default class ThemeManager extends Friend {
}

if (!isSystem) {
this.systemThemeExtractor.unsubscribe();
this.systemThemeExtractor.destroy();
}

const oldValue = this.current;
Expand Down

0 comments on commit a5fc436

Please sign in to comment.