Make Webview Zoom Changeable from Home Assistant (#52)

* Add Page Zoom Control

Adds MQTT discovery for a "Page Zoom" input to control the `WEBVIEW.viewZoom` parameter.

The MQTT value has been configured to be in % which is then converted to a scale factor when assigned or read from `WEBVIEW.viewZoom`.

* Correct Type for page_zoom publishConfig

Accidentally replaced "number" with "zoom" when changing paramters.

* Add updateZoom Functionality to webview

Add a setter function for the viewZoom property that updates the zoom factor for all views when the property is changed.
This commit is contained in:
Tom Carpenter
2025-08-25 13:31:28 +02:00
committed by GitHub
parent ea01876ea7
commit 437c4ab1c5
2 changed files with 60 additions and 1 deletions
+20 -1
View File
@@ -38,7 +38,15 @@ const init = async () => {
// Init global properties
WEBVIEW.viewUrls = urls;
WEBVIEW.viewZoom = zoom;
Object.defineProperty(WEBVIEW, "viewZoom", {
get() {
return this._viewZoom || zoom;
},
set(v) {
this._viewZoom = Math.max(0, v);
updateZoom();
},
});
WEBVIEW.viewTheme = theme;
WEBVIEW.widgetTheme = theme;
WEBVIEW.widgetEnabled = widget;
@@ -315,6 +323,17 @@ const resizeView = () => {
}
};
/**
* Updates zoom level for all webviews.
*/
const updateZoom = () => {
// And apply to all views
WEBVIEW.views.forEach((view) => {
view.webContents.setZoomFactor(WEBVIEW.viewZoom);
});
};
/**
* Register window events and handler.
*/