diff --git a/extension/manifest.json b/extension/manifest.json index 6738499..4cb8152 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Pywalfox", - "version": "2.0.5", + "version": "2.0.6", "description": "Dyanmic theming of the browser using your pywal colors", "browser_specific_settings": { "gecko": { diff --git a/src/background/extension.ts b/src/background/extension.ts index f4f5cab..feaa55c 100644 --- a/src/background/extension.ts +++ b/src/background/extension.ts @@ -62,6 +62,7 @@ export default class Extension { cssToggleFailed: this.cssToggleFailed.bind(this), cssFontSizeSetSuccess: this.cssFontSizeSetSuccess.bind(this), cssFontSizeSetFailed: this.cssFontSizeSetFailed.bind(this), + themeModeSet: this.themeModeSet.bind(this), }); browser.commands.onCommand.addListener(this.onCommand.bind(this)); @@ -607,6 +608,10 @@ export default class Extension { Messenger.UI.sendNotification('Font size', error, false); } + private themeModeSet(mode: ThemeModes) { + this.setThemeMode(mode); + } + public async start() { this.settingsPage = new ExtensionPage(EXTENSION_PAGES.SETTINGS); this.updatePage = new ExtensionPage(EXTENSION_PAGES.UPDATE); diff --git a/src/communication/native-messenger.ts b/src/communication/native-messenger.ts index 7f56b4a..f9e9e97 100644 --- a/src/communication/native-messenger.ts +++ b/src/communication/native-messenger.ts @@ -1,4 +1,5 @@ import { + ThemeModes, INativeAppMessage, INativeAppRequest, INativeAppMessageCallbacks, @@ -59,6 +60,9 @@ export default class NativeApp { case NATIVE_MESSAGES.CSS_FONT_SIZE: this.onCssFontSizeResponse(message); break; + case NATIVE_MESSAGES.THEME_MODE: + this.onThemeModeResponse(message); + break; case NATIVE_MESSAGES.INVALID_ACTION: this.logError(`Native app recieved unhandled message action: ${message.action}`); break; @@ -134,6 +138,25 @@ export default class NativeApp { } } + private onThemeModeResponse(message: INativeAppMessage) { + const mode: string = this.getData(message); + + if (!mode) { + this.logError('Received theme mode command, but the new mode was not specified'); + return; + } + + if (mode === ThemeModes.Dark) { + this.callbacks.themeModeSet(ThemeModes.Dark); + } else if (mode === ThemeModes.Light) { + this.callbacks.themeModeSet(ThemeModes.Light); + } else if (mode === ThemeModes.Auto) { + this.callbacks.themeModeSet(ThemeModes.Auto); + } else { + this.logError(`Received theme mode command, but the mode "${mode}" was invalid`); + } + } + private onDebuggingOutput(message: INativeAppMessage) { const output: string = this.getData(message); output && this.callbacks.output(output); diff --git a/src/config/general.ts b/src/config/general.ts index 7217b4c..7d1556c 100644 --- a/src/config/general.ts +++ b/src/config/general.ts @@ -83,6 +83,7 @@ export const NATIVE_MESSAGES = { CSS_ENABLE: 'css:enable', CSS_DISABLE: 'css:disable', CSS_FONT_SIZE: 'css:font:size', + THEME_MODE: 'theme:mode', }; export const DARKREADER_MESSAGES = { diff --git a/src/definitions.ts b/src/definitions.ts index 48ffe14..e7782a6 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -234,6 +234,7 @@ export interface INativeAppMessageCallbacks { cssToggleFailed: (target: string, error: string) => void, cssFontSizeSetSuccess: (size: number) => void, cssFontSizeSetFailed: (error: string) => void, + themeModeSet: (mode: ThemeModes) => void, } export interface INodeLookup {