fit-webview-bridge 0.2.4a1__tar.gz → 0.2.5a1__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.4a1
3
+ Version: 0.2.5a1
4
4
  Summary: Qt native WebView bridge with PySide6 bindings
5
5
  Author: FIT Project
6
6
  License: LGPL-3.0-or-later
@@ -63,6 +63,9 @@ class Main(QMainWindow):
63
63
  # segnali base
64
64
  self.view.titleChanged.connect(self.setWindowTitle)
65
65
  self.view.loadProgress.connect(lambda p: print("progress:", p))
66
+ self.view.setUserAgent(
67
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15"
68
+ )
66
69
 
67
70
  # abilita/disabilita i bottoni in base alla navigazione
68
71
  self.btnBack.setEnabled(False)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fit-webview-bridge"
3
- version = "0.2.4a1"
3
+ version = "0.2.5a1"
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"]
@@ -28,6 +28,12 @@ public:
28
28
  Q_INVOKABLE QString downloadDirectory() const;
29
29
  void renderErrorPage(const QUrl& url, const QString& reason, int httpStatus);
30
30
 
31
+ // ==== USER AGENT ====
32
+ Q_INVOKABLE void setUserAgent(const QString& ua); // UA completo
33
+ Q_INVOKABLE QString userAgent() const; // restituisce l’override (se presente)
34
+ Q_INVOKABLE void resetUserAgent(); // rimuove l’override
35
+ Q_INVOKABLE void setApplicationNameForUserAgent(const QString& appName); // opzionale
36
+
31
37
  signals:
32
38
  void loadFinished(bool ok);
33
39
  void urlChanged(const QUrl& url);
@@ -49,4 +55,7 @@ protected:
49
55
 
50
56
  private:
51
57
  struct Impl; Impl* d = nullptr;
58
+
59
+ // --- NEW: helper che applica UA
60
+ void applyUserAgent();
52
61
  };
@@ -53,6 +53,10 @@ struct WKWebViewWidget::Impl {
53
53
  WKUserContentController* ucc = nil;
54
54
  FitUrlMsgHandler* msg = nil;
55
55
  QString downloadDir; // es. ~/Downloads
56
+
57
+ // --- UA ---
58
+ QString customUA; // override UA (se non vuoto)
59
+ QString appUA; // suffix via configuration (opzionale)
56
60
  };
57
61
 
58
62
  // =======================
@@ -854,6 +858,8 @@ WKWebViewWidget::WKWebViewWidget(QWidget* parent)
854
858
  d->delegate.webView = d->wk;
855
859
  [d->wk setNavigationDelegate:d->delegate];
856
860
  [d->wk setUIDelegate:d->delegate];
861
+
862
+ applyUserAgent();
857
863
  }
858
864
 
859
865
  WKWebViewWidget::~WKWebViewWidget() {
@@ -1001,4 +1007,59 @@ void WKWebViewWidget::renderErrorPage(const QUrl& url,
1001
1007
  // Carica l'HTML direttamente nella webview
1002
1008
  [d->wk loadHTMLString:[NSString stringWithUTF8String:html.toUtf8().constData()]
1003
1009
  baseURL:[NSURL URLWithString:@"about:blank"]];
1004
- }
1010
+ }
1011
+
1012
+ // --- NEW: metodo privato
1013
+ void WKWebViewWidget::applyUserAgent() {
1014
+ if (!(d && d->wk)) return;
1015
+ @autoreleasepool {
1016
+ // Suffix via configuration.applicationNameForUserAgent
1017
+ if (d->appUA.isEmpty()) {
1018
+ @try { [d->wk.configuration setValue:nil forKey:@"applicationNameForUserAgent"]; } @catch(...) {}
1019
+ } else {
1020
+ NSString* s = [NSString stringWithUTF8String:d->appUA.toUtf8().constData()];
1021
+ @try {
1022
+ if ([d->wk.configuration respondsToSelector:@selector(setApplicationNameForUserAgent:)]) {
1023
+ d->wk.configuration.applicationNameForUserAgent = s;
1024
+ } else {
1025
+ [d->wk.configuration setValue:s forKey:@"applicationNameForUserAgent"];
1026
+ }
1027
+ } @catch(...) {}
1028
+ }
1029
+
1030
+ // Override totale via customUserAgent
1031
+ if (d->customUA.isEmpty()) {
1032
+ @try { d->wk.customUserAgent = nil; } @catch(...) {
1033
+ @try { [d->wk setValue:nil forKey:@"customUserAgent"]; } @catch(...) {}
1034
+ }
1035
+ } else {
1036
+ NSString* ua = [NSString stringWithUTF8String:d->customUA.toUtf8().constData()];
1037
+ @try { d->wk.customUserAgent = ua; } @catch(...) {
1038
+ @try { [d->wk setValue:ua forKey:@"customUserAgent"]; } @catch(...) {}
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+
1044
+ // --- API pubblica UA
1045
+ void WKWebViewWidget::setUserAgent(const QString& ua) {
1046
+ if (!d) return;
1047
+ d->customUA = ua.trimmed();
1048
+ applyUserAgent();
1049
+ }
1050
+
1051
+ QString WKWebViewWidget::userAgent() const {
1052
+ return d ? d->customUA : QString();
1053
+ }
1054
+
1055
+ void WKWebViewWidget::resetUserAgent() {
1056
+ if (!d) return;
1057
+ d->customUA.clear();
1058
+ applyUserAgent();
1059
+ }
1060
+
1061
+ void WKWebViewWidget::setApplicationNameForUserAgent(const QString& appName) {
1062
+ if (!d) return;
1063
+ d->appUA = appName.trimmed();
1064
+ applyUserAgent();
1065
+ }