@@ -15,28 +15,23 @@ struct UpdaterWebView: UIViewRepresentable {
1515 Coordinator ( parent: self )
1616 }
1717
18- func makeUIView( context: Context ) -> WKWebView {
19- // Configure the web view
20- let config = WKWebViewConfiguration ( )
21- config. allowsInlineMediaPlayback = true
22- config. preferences. javaScriptEnabled = true
23-
24- let webView = WKWebView ( frame: . zero, configuration: config)
25- webView. navigationDelegate = context. coordinator
26- webView. uiDelegate = context. coordinator
27- webView. allowsBackForwardNavigationGestures = true
28-
29- // Load request
30- webView. load ( URLRequest ( url: url) )
31- return webView
32- }
18+ func makeUIView( context: Context ) -> WKWebView {
19+ let config = WKWebViewConfiguration ( )
20+ config. preferences. javaScriptEnabled = true
21+ let webView = WKWebView ( frame: . zero, configuration: config)
22+ webView. navigationDelegate = context. coordinator
23+ webView. uiDelegate = context. coordinator
24+ webView. allowsBackForwardNavigationGestures = true
25+
26+ let request = URLRequest ( url: url, cachePolicy: . reloadIgnoringLocalCacheData, timeoutInterval: 30 )
27+ webView. load ( request)
28+ return webView
29+ }
3330
34- func updateUIView( _ uiView: WKWebView , context: Context ) {
35- // Only reload if the URL changed; avoids flicker
36- if uiView. url != url {
37- uiView. load ( URLRequest ( url: url) )
38- }
39- }
31+ func updateUIView( _ uiView: WKWebView , context: Context ) {
32+ let request = URLRequest ( url: url, cachePolicy: . reloadIgnoringLocalCacheData, timeoutInterval: 30 )
33+ uiView. load ( request)
34+ }
4035
4136 // MARK: - Coordinator
4237 class Coordinator : NSObject , WKNavigationDelegate , WKUIDelegate {
@@ -78,24 +73,6 @@ struct UpdaterWebView: UIViewRepresentable {
7873 // 3) Allow normal navigation
7974 decisionHandler ( . allow)
8075 }
81-
82- // Optional: handle window.open() from JS (so target=_blank still works)
83- func webView( _ webView: WKWebView , createWebViewWith configuration: WKWebViewConfiguration ,
84- for navigationAction: WKNavigationAction , windowFeatures: WKWindowFeatures ) -> WKWebView ? {
85- // If the action has a URL, open externally (Safari)
86- if let url = navigationAction. request. url {
87- UIApplication . shared. open ( url, options: [ : ] , completionHandler: nil )
88- }
89- return nil
90- }
91-
92- // Optional: handle JS alert/confirm/prompt if needed
93- func webView( _ webView: WKWebView , runJavaScriptAlertPanelWithMessage message: String ,
94- initiatedByFrame frame: WKFrameInfo , completionHandler: @escaping ( ) -> Void ) {
95- // simple native alert fallback
96- let alert = UIAlertController ( title: nil , message: message, preferredStyle: . alert)
97- alert. addAction ( UIAlertAction ( title: " OK " , style: . default) { _ in completionHandler ( ) } )
98- UIApplication . shared. windows. first? . rootViewController? . present ( alert, animated: true , completion: nil )
99- }
10076 }
10177}
78+
0 commit comments