fit-webview-bridge 0.2.1a1__tar.gz → 0.2.1a3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fit-webview-bridge might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: fit-webview-bridge
3
- Version: 0.2.1a1
3
+ Version: 0.2.1a3
4
4
  Summary: Qt native WebView bridge with PySide6 bindings
5
5
  Author: FIT Project
6
6
  License: LGPL-3.0-or-later
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fit-webview-bridge"
3
- version = "0.2.1a1"
3
+ version = "0.2.1a3"
4
4
  description = "Qt native WebView bridge with PySide6 bindings"
5
5
  requires-python = ">=3.11,<3.14"
6
6
  dependencies = ["PySide6==6.9.0", "shiboken6==6.9.0", "shiboken6-generator==6.9.0"]
@@ -133,10 +133,15 @@ didBecomeDownload:(WKDownload *)download
133
133
  if (self.owner) {
134
134
  emit self.owner->downloadStarted(QString(), QString());
135
135
  }
136
- // Progress via NSProgress (best effort): alcuni siti non lo popolano
137
- [download.progress addObserver:self
138
- forKeyPath:@"fractionCompleted"
139
- options:NSKeyValueObservingOptionNew
136
+
137
+ [download.progress addObserver:self forKeyPath:@"fractionCompleted"
138
+ options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial)
139
+ context:NULL];
140
+ [download.progress addObserver:self forKeyPath:@"completedUnitCount"
141
+ options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial)
142
+ context:NULL];
143
+ [download.progress addObserver:self forKeyPath:@"totalUnitCount"
144
+ options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial)
140
145
  context:NULL];
141
146
  }
142
147
 
@@ -153,9 +158,15 @@ didBecomeDownload:(WKDownload *)download
153
158
  emit self.owner->downloadStarted(QString::fromUtf8(suggested.UTF8String),
154
159
  destPath);
155
160
  }
156
- [download.progress addObserver:self
157
- forKeyPath:@"fractionCompleted"
158
- options:NSKeyValueObservingOptionNew
161
+
162
+ [download.progress addObserver:self forKeyPath:@"fractionCompleted"
163
+ options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial)
164
+ context:NULL];
165
+ [download.progress addObserver:self forKeyPath:@"completedUnitCount"
166
+ options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial)
167
+ context:NULL];
168
+ [download.progress addObserver:self forKeyPath:@"totalUnitCount"
169
+ options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial)
159
170
  context:NULL];
160
171
  }
161
172
 
@@ -212,22 +223,30 @@ completionHandler:(void (^)(NSURL * _Nullable destination))completionHandler
212
223
  - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)obj
213
224
  change:(NSDictionary *)change context:(void *)ctx
214
225
  {
215
- if (![keyPath isEqualToString:@"fractionCompleted"]) {
226
+ if (![obj isKindOfClass:[NSProgress class]] || !self.owner) {
216
227
  [super observeValueForKeyPath:keyPath ofObject:obj change:change context:ctx];
217
228
  return;
218
229
  }
219
- if (!self.owner) return;
220
230
 
221
231
  NSProgress* prog = (NSProgress*)obj;
222
232
  int64_t total = prog.totalUnitCount; // può essere -1 (sconosciuto)
223
233
  int64_t done = prog.completedUnitCount;
224
- emit self.owner->downloadProgress(done, total >= 0 ? total : -1);
234
+
235
+ // Emetti SEMPRE su main (thread-safety Qt/UI)
236
+ dispatch_async(dispatch_get_main_queue(), ^{
237
+ emit self.owner->downloadProgress(done, (total >= 0 ? total : -1));
238
+ });
225
239
  }
226
240
 
241
+
227
242
  - (void)downloadDidFinish:(WKDownload *)download {
228
243
  if (!self.owner) return;
229
244
 
230
- @try { [download.progress removeObserver:self forKeyPath:@"fractionCompleted"]; } @catch (...) {}
245
+ @try {
246
+ [download.progress removeObserver:self forKeyPath:@"fractionCompleted"];
247
+ [download.progress removeObserver:self forKeyPath:@"completedUnitCount"];
248
+ [download.progress removeObserver:self forKeyPath:@"totalUnitCount"];
249
+ } @catch (...) {}
231
250
 
232
251
  NSString* finalPath = [self.downloadPaths objectForKey:download];
233
252
  if (finalPath) {
@@ -241,7 +260,11 @@ completionHandler:(void (^)(NSURL * _Nullable destination))completionHandler
241
260
  - (void)download:(WKDownload *)download didFailWithError:(NSError *)error resumeData:(NSData *)resumeData {
242
261
  if (!self.owner) return;
243
262
 
244
- @try { [download.progress removeObserver:self forKeyPath:@"fractionCompleted"]; } @catch (...) {}
263
+ @try {
264
+ [download.progress removeObserver:self forKeyPath:@"fractionCompleted"];
265
+ [download.progress removeObserver:self forKeyPath:@"completedUnitCount"];
266
+ [download.progress removeObserver:self forKeyPath:@"totalUnitCount"];
267
+ } @catch (...) {}
245
268
 
246
269
  NSString* finalPath = [self.downloadPaths objectForKey:download];
247
270
  QString qpath = finalPath ? QString::fromUtf8(finalPath.UTF8String) : QString();