Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering of the openHAB ui in a Webview on an iPad was way to small.… #806

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openHAB/OpenHABWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class OpenHABWebViewController: OpenHABViewController {
// adds: window.webkit.messageHandlers.xxxx.postMessage to JS env
config.userContentController.add(self, name: "Native")
config.userContentController.addUserScript(WKUserScript(source: js, injectionTime: .atDocumentStart, forMainFrameOnly: false))

let webView = WKWebView(frame: view.bounds, configuration: config)
// Alow rotation of webview
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
Expand All @@ -233,6 +234,10 @@ class OpenHABWebViewController: OpenHABViewController {
// support dark mode and avoid white flashing when loading
webView.isOpaque = false
webView.backgroundColor = UIColor.clear
if UIDevice.current.userInterfaceIdiom == .pad {
// since ios 13 Safari sets the user agent to desktop mode on iPads so the view renders correctly with larger screens
webView.customUserAgent = "Mozilla/5.0 (iPad; CPU OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1"
}
if #available(iOS 16.4, *) {
webView.isInspectable = true
}
Expand Down
Loading