@@ -197,6 +197,8 @@ struct WebUIViewWithSave: NSViewRepresentable {
197
197
198
198
@Binding var savingDataTrigger : Bool
199
199
@Binding var savingData : Data ?
200
+
201
+ @Binding var isStop : Bool
200
202
201
203
func makeCoordinator( ) -> Coordinator {
202
204
Coordinator ( )
@@ -209,20 +211,6 @@ struct WebUIViewWithSave: NSViewRepresentable {
209
211
}
210
212
211
213
func updateNSView( _ nsView: NSViewType , context: Context ) {
212
- if savingData != nil {
213
- if let data = savingData {
214
- nsView. load ( data, mimeType: " application/x-webarchive " , characterEncodingName: " utf-8 " , baseURL: getDocumentsDirectory ( ) )
215
- }
216
- } else if urlStr. isEmpty {
217
- let host = URL ( string: baseURLStr) ? . host ?? " "
218
- nsView. loadHTMLString ( html, baseURL: URL ( string: " https:// \( host) " ) )
219
- } else {
220
- if let url = URL ( string: urlStr) {
221
- let r = URLRequest ( url: url)
222
- nsView. load ( r)
223
- }
224
- }
225
-
226
214
if savingDataTrigger == true {
227
215
nsView. createWebArchiveData { result in
228
216
do {
@@ -234,6 +222,25 @@ struct WebUIViewWithSave: NSViewRepresentable {
234
222
}
235
223
savingDataTrigger = false
236
224
}
225
+
226
+ if isStop == true {
227
+ return
228
+ }
229
+
230
+ if savingData != nil {
231
+ if let data = savingData {
232
+ nsView. load ( data, mimeType: " application/x-webarchive " , characterEncodingName: " utf-8 " , baseURL: getDocumentsDirectory ( ) )
233
+ isStop = true
234
+ }
235
+ } else {
236
+ if let url = URL ( string: urlStr) {
237
+ let r = URLRequest ( url: url)
238
+ nsView. load ( r)
239
+ isStop = true
240
+ }
241
+ }
242
+
243
+
237
244
}
238
245
239
246
class Coordinator : NSObject , WKNavigationDelegate {
0 commit comments