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:
+20
-1
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user