From ae431aa0c326360a743094de5b3f5d0d4b0fb092 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Fri, 4 Aug 2023 22:37:06 +0530 Subject: [PATCH 01/22] use Android Proxy Selector instead or env vars. --- .../FlutterSystemProxyPlugin.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/browserstack/fluttersystemproxy/flutter_system_proxy/FlutterSystemProxyPlugin.java b/android/src/main/java/com/browserstack/fluttersystemproxy/flutter_system_proxy/FlutterSystemProxyPlugin.java index d30bc29..eebebb0 100644 --- a/android/src/main/java/com/browserstack/fluttersystemproxy/flutter_system_proxy/FlutterSystemProxyPlugin.java +++ b/android/src/main/java/com/browserstack/fluttersystemproxy/flutter_system_proxy/FlutterSystemProxyPlugin.java @@ -3,6 +3,10 @@ import androidx.annotation.NonNull; import android.text.TextUtils; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.ProxySelector; +import java.net.URI; import java.util.HashMap; import java.util.Map; @@ -31,12 +35,26 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin @Override public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { if (call.method.equals("getDeviceProxy")) { - Map map = new HashMap(); - map.put("http.proxyHost", System.getProperty("http.proxyHost")); - map.put("http.proxyPort", System.getProperty("http.proxyPort")); - map.put("https.proxyHost", System.getProperty("https.proxyHost")); - map.put("https.proxyPort", System.getProperty("https.proxyPort")); - result.success(map); + HashMap _map = new HashMap() { + { + put("host", null); + put("port", null); + } + }; + String url = call.argument("url"); + ProxySelector selector = ProxySelector.getDefault(); + try { + for (Proxy proxy : selector.select(new URI(url))) { + if (proxy.type() == Proxy.Type.HTTP) { + InetSocketAddress addr = (InetSocketAddress) proxy.address(); + _map.put("host", addr.getHostName()); + _map.put("port", Integer.toString(addr.getPort())); + } + } + result.success(_map); + } catch (Exception ex) { + result.error("URL Error",ex.getMessage(),null); + } } else { result.notImplemented(); } From e0a4e79662d938718eeead9da8418285bb0c5292 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Fri, 4 Aug 2023 22:37:29 +0530 Subject: [PATCH 02/22] use minSDKVersion 31 in example --- example/android/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 00bccc7..d44d61f 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 + compileSdkVersion 31 defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). From fd792361af2ffadc7a4085cf246bf61502a3f315 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Fri, 4 Aug 2023 22:38:15 +0530 Subject: [PATCH 03/22] ios: use min platform version 11.0 for example --- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Podfile | 2 +- example/ios/Podfile.lock | 6 +-- example/ios/Runner.xcodeproj/project.pbxproj | 37 ++++++++++++------- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 2 + 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9367d48..9625e10 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 11.0 diff --git a/example/ios/Podfile b/example/ios/Podfile index 1e8c3c9..313ea4a 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index be03354..0b05a0d 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -14,9 +14,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_system_proxy/ios" SPEC CHECKSUMS: - Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c + Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 flutter_system_proxy: 96eb97e3857a1d1bc533a6f7387a1f0dcb63d782 -PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c +PODFILE CHECKSUM: 7368163408c647b7eb699d0d788ba6718e18fb8d -COCOAPODS: 1.11.2 +COCOAPODS: 1.11.3 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index d9b1a5c..43420ed 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ @@ -68,7 +68,6 @@ 3D695DD80D4DCA36C1B83028 /* Pods-Runner.release.xcconfig */, 2B955829EF2302761365E6DB /* Pods-Runner.profile.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -156,7 +155,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -263,7 +262,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -340,7 +339,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -356,10 +355,14 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = KA2N5S86T8; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyExample; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyDhvani; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -414,7 +417,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -463,7 +466,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -480,10 +483,14 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = KA2N5S86T8; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyExample; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyDhvani; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -499,10 +506,14 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = KA2N5S86T8; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyExample; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyDhvani; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140c..3db53b6 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ + CADisableMinimumFrameDurationOnPhone + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable From b4cb8b55102048008b2152e32bba743bbd24a6ec Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Fri, 4 Aug 2023 22:39:30 +0530 Subject: [PATCH 04/22] fix: use Foundation Lib for executing pac --- .../SwiftFlutterSystemProxyPlugin.swift | 87 +++++++++++++++---- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift index f881fc3..4c588de 100644 --- a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift +++ b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift @@ -11,28 +11,77 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { switch call.method { case "getDeviceProxy": - let systemProxySettings = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() ?? [:] as CFDictionary - result(systemProxySettings as NSDictionary) - break - case "executePAC": - let systemProxySettings = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() ?? [:] as CFDictionary - let proxyDict = systemProxySettings as NSDictionary - if(proxyDict.value(forKey:"ProxyAutoConfigEnable")as! Bool){ - let args = call.arguments as! NSDictionary - let url = args.value(forKey:"url") as! String - let host = args.value(forKey:"host") as! String - let js = args.value(forKey:"js") as! String - let jsEngine:JSContext = JSContext() - jsEngine.evaluateScript(js) - let fn = "FindProxyForURL(\"" + url + "\",\""+host+"\")" - let proxy = jsEngine.evaluateScript(fn) - result(proxy?.toString()) - }else{ - result("DIRECT") - } + let args = call.arguments as! NSDictionary + let url = args.value(forKey:"url") as! String + var dict:[String:Any] = [:] + findProxyFromEnvironment(url: url,callback: { host, port in + dict["host"] = host + dict["port"] = port + result(dict) + }) break default: result(FlutterMethodNotImplemented) } } + + func findProxyFromEnvironment(url: String,callback: @escaping (_ host:String?,_ port:Int?)->Void) { + let proxConfigDict = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary? + if(proxConfigDict != nil){ + if(proxConfigDict!["ProxyAutoConfigEnable"] as? Int == 1){ + let pacUrl = proxConfigDict!["ProxyAutoConfigURLString"] as? String + let pacContent = proxConfigDict!["ProxyAutoConfigJavaScript"] as? String + if(pacContent != nil){ + self.handlePacContent(pacContent: pacContent! as String, url: url, callback: callback) + } + downloadPac(pacUrl: pacUrl!, callback: { pacContent,error in + + if(error != nil){ + callback(nil,nil) + }else{ + self.handlePacContent(pacContent: pacContent!, url: url, callback: callback) + } + }) + } else if (proxConfigDict!["HTTPEnable"] as? Int == 1){ + callback((proxConfigDict!["HTTPProxy"] as? String),(proxConfigDict!["HTTPPort"] as? Int)) + } else if ( proxConfigDict!["HTTPSEnable"] as? Int == 1){ + callback((proxConfigDict!["HTTPSProxy"] as? String),(proxConfigDict!["HTTPSPort"] as? Int)) + } else { + callback(nil,nil) + } + } + } + + func handlePacContent(pacContent: String,url: String, callback:(_ host:String?,_ port:Int?)->Void){ + let proxies = CFNetworkCopyProxiesForAutoConfigurationScript(pacContent as CFString, CFURLCreateWithString(kCFAllocatorDefault, url as CFString, nil), nil)!.takeUnretainedValue() as? [[CFString: Any]] ?? []; + if(proxies.count > 0){ + let proxy = proxies.first{$0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTP || $0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTPS} + if(proxy != nil){ + let host = proxy?[kCFProxyHostNameKey] ?? nil + let port = proxy?[kCFProxyPortNumberKey] ?? nil + callback(host as? String,port as? Int) + }else{ + callback(nil,nil) + } + }else{ + callback(nil,nil) + } + } + + + func downloadPac(pacUrl:String, callback:@escaping (_ pacContent:String?,_ error: Error?)->Void) { + var pacContent:String = "" + let config = URLSessionConfiguration.default + config.connectionProxyDictionary = [AnyHashable: Any]() + let session = URLSession.init(configuration: config,delegate: nil,delegateQueue: OperationQueue.current) + session.dataTask(with: URL(string: pacUrl)!, completionHandler: { data, response, error in + if(error != nil){ + callback(nil,error) + } + pacContent = String(bytes: data!,encoding: String.Encoding.utf8)! + callback(pacContent,nil) + }).resume() + + } + } From 023f4b9a7e9e4bae561b213f64d8a0f3235a4e7e Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Fri, 4 Aug 2023 22:39:57 +0530 Subject: [PATCH 05/22] return error string instead of "Error" --- example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 9a89b3e..68a6684 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -90,6 +90,6 @@ Future fetchLocalHost() async { return response.toString(); } catch (e) { print(e); - return "Error"; + return e.toString(); } } From 270ad13fef25d7303e17ca1fa33c575278e2613e Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Fri, 4 Aug 2023 22:40:27 +0530 Subject: [PATCH 06/22] clean code --- lib/flutter_system_proxy.dart | 94 +++++------------------------------ 1 file changed, 13 insertions(+), 81 deletions(-) diff --git a/lib/flutter_system_proxy.dart b/lib/flutter_system_proxy.dart index 566de35..c61237c 100644 --- a/lib/flutter_system_proxy.dart +++ b/lib/flutter_system_proxy.dart @@ -1,81 +1,25 @@ import 'dart:async'; -import 'dart:convert'; import 'dart:io'; import 'package:flutter/services.dart'; class FlutterSystemProxy { static const MethodChannel _channel = const MethodChannel('flutter_system_proxy'); - - static Future?> _getSystemProxy(String url) async { - bool isHttps = Uri.parse(url).scheme == 'https'; - dynamic proxySettings = await _channel.invokeMethod("getDeviceProxy"); - if (Platform.isAndroid) { - if (isHttps) { - if (!isNullOrEmpty(proxySettings['https.proxyHost']) && - isPort(proxySettings['https.proxyPort'])) { - return { - "enabled": "true", - "host": proxySettings['https.proxyHost'], - "port": proxySettings['https.proxyPort'] - }; - } - } else { - if (!isNullOrEmpty(proxySettings['http.proxyHost']) && - isPort(proxySettings['http.proxyPort'])) { - return { - "enabled": "true", - "host": proxySettings['http.proxyHost'], - "port": proxySettings['http.proxyPort'] - }; - } - } - return null; - } else if (Platform.isIOS) { - if (proxySettings["ProxyAutoConfigEnable"] == 1) { - return { - "pacEnabled": "true", - "pacUrl": proxySettings['ProxyAutoConfigURLString'] - }; - } else { - if (isHttps) { - if (proxySettings['HTTPSEnable'] == 1) { - return { - "enabled": "true", - "host": proxySettings['HTTPSProxy'].toString(), - "port": proxySettings['HTTPSPort'].toString() - }; - } - } else { - if (proxySettings['HTTPEnable'] == 1) { - return { - "enabled": "true", - "host": proxySettings['HTTPProxy'].toString(), - "port": proxySettings['HTTPPort'].toString() - }; - } - } - return null; - } - } + + /// returns host and port from environment + static Future getEnvironmentProxy(String url) async { + return _channel.invokeMethod("getDeviceProxy", {'url': url}); } + /// returns Proxy String static Future findProxyFromEnvironment(String url) async { - var parsedProxy = await _getSystemProxy(url); - var host = Uri.parse(url).host; - if (parsedProxy != null && parsedProxy["enabled"] == "true") { + dynamic proxySettings = await getEnvironmentProxy(url); + if (!isNullOrEmpty(proxySettings['host']) && + isPort(proxySettings['port'])) { return "PROXY " + - (parsedProxy["host"] as String) + + (proxySettings['host'].toString()) + ":" + - (parsedProxy["port"] as String); - } else if (parsedProxy != null && - parsedProxy["pacEnabled"] == "true" && - parsedProxy["pacUrl"] != null) { - String pacLocation = parsedProxy["pacUrl"] as String; - String jsContents = await contents(pacLocation); - String proxy = await _channel.invokeMethod( - "executePAC", {"url": url, "host": host, "js": jsContents}); - return proxy; + (proxySettings['port'].toString()); } else { return HttpClient.findProxyFromEnvironment(Uri.parse(url)); } @@ -86,24 +30,12 @@ bool isNullOrEmpty(String? str) { return str == null || str == ""; } -bool isPort(String? port) { +bool isPort(dynamic port) { if (port == null) return false; - final number = num.tryParse(port); - if (number != null && number > 0) { + final number = num.tryParse(port.toString()); + if (number != null && number > 0 && number <= 65536) { return true; } else { return false; } } - -Future contents(String url) async { - HttpClient client = new HttpClient(); - var completor = new Completer(); - client.findProxy = null; - var request = await client.getUrl(Uri.parse(url)); - var response = await request.close(); - response.transform(utf8.decoder).listen((contents) { - completor.complete(contents); - }); - return completor.future; -} From 5cfcbeaf12312ce52fe08c1486f98345ebaf4582 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Fri, 4 Aug 2023 22:40:39 +0530 Subject: [PATCH 07/22] release 0.1.0 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index c2711bb..783b0c4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_system_proxy description: A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request. -version: 0.0.2 +version: 0.1.0 homepage: https://github.com/Rushabhshroff/flutter_system_proxy.git environment: From 7792de9dbde183c4b49914e5fdb358ce02f907cb Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Mon, 7 Aug 2023 19:06:04 +0530 Subject: [PATCH 08/22] update: Homepage --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 783b0c4..06303b8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_system_proxy description: A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request. version: 0.1.0 -homepage: https://github.com/Rushabhshroff/flutter_system_proxy.git +homepage: https://github.com/BrowserStackCE/flutter_system_proxy.git environment: sdk: ">=2.12.0 <3.0.0" From 4746e50ae5686502a425d5193cb8f4187a1dafb7 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Mon, 7 Aug 2023 19:06:30 +0530 Subject: [PATCH 09/22] modify project details --- example/ios/Runner.xcodeproj/project.pbxproj | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 43420ed..aa8ab3e 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -355,14 +355,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = KA2N5S86T8; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyDhvani; + PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxy; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -483,14 +482,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = KA2N5S86T8; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyDhvani; + PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxy; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -506,14 +504,13 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = KA2N5S86T8; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxyDhvani; + PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxy; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; From 34f54b96bd8c87b4dab4118927a868ad86c714b8 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Fri, 1 Sep 2023 21:11:06 +0530 Subject: [PATCH 10/22] fix : crash when invalid pac file url --- ios/Classes/SwiftFlutterSystemProxyPlugin.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift index 4c588de..c120094 100644 --- a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift +++ b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift @@ -75,8 +75,9 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { config.connectionProxyDictionary = [AnyHashable: Any]() let session = URLSession.init(configuration: config,delegate: nil,delegateQueue: OperationQueue.current) session.dataTask(with: URL(string: pacUrl)!, completionHandler: { data, response, error in - if(error != nil){ + if(error != nil || data == nil){ callback(nil,error) + return; } pacContent = String(bytes: data!,encoding: String.Encoding.utf8)! callback(pacContent,nil) From b7e84da9b97d338500755dde4ecf0e697e2f0337 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Thu, 28 Sep 2023 14:13:00 +0530 Subject: [PATCH 11/22] --- --- example/ios/Runner.xcodeproj/project.pbxproj | 16 ++- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 2 + example/lib/main.dart | 15 ++- example/pubspec.lock | 127 +++++++++++------- .../SwiftFlutterSystemProxyPlugin.swift | 120 +++++++++++------ pac/test.pac | 8 ++ pubspec.lock | 38 +++--- 8 files changed, 206 insertions(+), 122 deletions(-) create mode 100644 pac/test.pac diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index aa8ab3e..d356f60 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -155,7 +155,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -199,10 +199,12 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -252,6 +254,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -355,13 +358,14 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = 58NJ4M43R4; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxy; + PRODUCT_BUNDLE_IDENTIFIER = "com.browserstack.flutter-system-proxy-bstack"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -482,13 +486,14 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = 58NJ4M43R4; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxy; + PRODUCT_BUNDLE_IDENTIFIER = "com.browserstack.flutter-system-proxy-bstack"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -504,13 +509,14 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = 58NJ4M43R4; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.browserstack.fluttersystemproxy.flutterSystemProxy; + PRODUCT_BUNDLE_IDENTIFIER = "com.browserstack.flutter-system-proxy-bstack"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 3db53b6..b52b2e6 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS + UIApplicationSupportsIndirectInputEvents + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/example/lib/main.dart b/example/lib/main.dart index 68a6684..ad98b99 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'dart:async'; import 'package:dio/adapter.dart'; import 'package:flutter/material.dart'; import 'package:dio/dio.dart'; @@ -34,10 +35,13 @@ class _MyHomePageState extends State { int _counter = 0; String _res = "Response"; void _incrementCounter() { + setState(() { + _counter++; + }); fetchLocalHost().then((value) { + print(value); setState(() { - _counter++; - _res = value; + _res = value.toString(); }); }); } @@ -76,10 +80,10 @@ class _MyHomePageState extends State { } Future fetchLocalHost() async { - try { var dio = new Dio(); var url = 'http://ip-api.com/json'; var proxy = await FlutterSystemProxy.findProxyFromEnvironment(url); + print(proxy); (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) { client.findProxy = (uri) { @@ -87,9 +91,6 @@ Future fetchLocalHost() async { }; }; var response = await dio.get(url); + print(response.toString()); return response.toString(); - } catch (e) { - print(e); - return e.toString(); - } } diff --git a/example/pubspec.lock b/example/pubspec.lock index a16b5b1..bb17097 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,65 +5,66 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.6.1" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.17.2" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be + url: "https://pub.dev" source: hosted - version: "1.0.3" + version: "1.0.5" dio: dependency: "direct main" description: name: dio - url: "https://pub.dartlang.org" + sha256: "7d328c4d898a61efc3cd93655a0955858e29a0aa647f0f9e02d59b3bb275e2e8" + url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "4.0.6" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -75,7 +76,7 @@ packages: path: ".." relative: true source: path - version: "0.0.2" + version: "0.1.0" flutter_test: dependency: "direct dev" description: flutter @@ -85,30 +86,42 @@ packages: dependency: transitive description: name: http_parser - url: "https://pub.dartlang.org" + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "4.0.2" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" + source: hosted + version: "0.12.16" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + url: "https://pub.dev" source: hosted - version: "0.12.10" + version: "0.5.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -118,58 +131,74 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "0.6.0" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.2" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "0.1.4-beta" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=1.20.0" diff --git a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift index c120094..0ed411c 100644 --- a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift +++ b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift @@ -1,7 +1,10 @@ import Flutter import UIKit import JavaScriptCore + public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { + static var proxyCache : [String: [String: Any]] = [:] + public static func register(with registrar: FlutterPluginRegistrar) { let channel = FlutterMethodChannel(name: "flutter_system_proxy", binaryMessenger: registrar.messenger()) let instance = SwiftFlutterSystemProxyPlugin() @@ -11,78 +14,113 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { switch call.method { case "getDeviceProxy": + do { let args = call.arguments as! NSDictionary let url = args.value(forKey:"url") as! String var dict:[String:Any] = [:] - findProxyFromEnvironment(url: url,callback: { host, port in - dict["host"] = host - dict["port"] = port - result(dict) - }) + if(SwiftFlutterSystemProxyPlugin.proxyCache[url] != nil){ + let res = SwiftFlutterSystemProxyPlugin.proxyCache[url] + if(res != nil){ + dict = res as! [String:Any] + } + } else { + let res = try SwiftFlutterSystemProxyPlugin.resolve(url: url) + if(res != nil){ + dict = res as! [String:Any] + } + } + result(dict) + } catch let error { + print("Unexpected Proxy Error: \(error).") + result(error) + } break default: result(FlutterMethodNotImplemented) } } - func findProxyFromEnvironment(url: String,callback: @escaping (_ host:String?,_ port:Int?)->Void) { + static func resolve(url:String)->[String:Any]?{ + if(SwiftFlutterSystemProxyPlugin.proxyCache[url] != nil){ + return SwiftFlutterSystemProxyPlugin.proxyCache[url] + } let proxConfigDict = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary? if(proxConfigDict != nil){ if(proxConfigDict!["ProxyAutoConfigEnable"] as? Int == 1){ let pacUrl = proxConfigDict!["ProxyAutoConfigURLString"] as? String let pacContent = proxConfigDict!["ProxyAutoConfigJavaScript"] as? String if(pacContent != nil){ - self.handlePacContent(pacContent: pacContent! as String, url: url, callback: callback) + self.handlePacContent(pacContent: pacContent! as String, url: url) + }else if(pacUrl != nil){ + self.handlePacUrl(pacUrl: pacUrl!,url: url) } - downloadPac(pacUrl: pacUrl!, callback: { pacContent,error in - - if(error != nil){ - callback(nil,nil) - }else{ - self.handlePacContent(pacContent: pacContent!, url: url, callback: callback) - } - }) } else if (proxConfigDict!["HTTPEnable"] as? Int == 1){ - callback((proxConfigDict!["HTTPProxy"] as? String),(proxConfigDict!["HTTPPort"] as? Int)) + var dict: [String: Any] = [:] + dict["host"] = proxConfigDict!["HTTPProxy"] as? String + dict["port"] = proxConfigDict!["HTTPPort"] as? Int + SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict + } else if ( proxConfigDict!["HTTPSEnable"] as? Int == 1){ - callback((proxConfigDict!["HTTPSProxy"] as? String),(proxConfigDict!["HTTPSPort"] as? Int)) - } else { - callback(nil,nil) + var dict: [String: Any] = [:] + dict["host"] = proxConfigDict!["HTTPSProxy"] as? String + dict["port"] = proxConfigDict!["HTTPSPort"] as? Int + SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict } } + return proxyCache[url] } - func handlePacContent(pacContent: String,url: String, callback:(_ host:String?,_ port:Int?)->Void){ + static func handlePacContent(pacContent: String,url: String){ let proxies = CFNetworkCopyProxiesForAutoConfigurationScript(pacContent as CFString, CFURLCreateWithString(kCFAllocatorDefault, url as CFString, nil), nil)!.takeUnretainedValue() as? [[CFString: Any]] ?? []; if(proxies.count > 0){ let proxy = proxies.first{$0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTP || $0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTPS} if(proxy != nil){ let host = proxy?[kCFProxyHostNameKey] ?? nil let port = proxy?[kCFProxyPortNumberKey] ?? nil - callback(host as? String,port as? Int) - }else{ - callback(nil,nil) + var dict:[String: Any] = [:] + dict["host"] = host + dict["port"] = port + SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict } - }else{ - callback(nil,nil) } } - - - func downloadPac(pacUrl:String, callback:@escaping (_ pacContent:String?,_ error: Error?)->Void) { - var pacContent:String = "" - let config = URLSessionConfiguration.default - config.connectionProxyDictionary = [AnyHashable: Any]() - let session = URLSession.init(configuration: config,delegate: nil,delegateQueue: OperationQueue.current) - session.dataTask(with: URL(string: pacUrl)!, completionHandler: { data, response, error in - if(error != nil || data == nil){ - callback(nil,error) - return; - } - pacContent = String(bytes: data!,encoding: String.Encoding.utf8)! - callback(pacContent,nil) - }).resume() + static func handlePacUrl(pacUrl: String, url: String){ + var _pacUrl = CFURLCreateWithString(kCFAllocatorDefault, pacUrl as CFString?,nil) + var targetUrl = CFURLCreateWithString(kCFAllocatorDefault, url as CFString?, nil) + if(pacUrl != nil && targetUrl != nil){ + var context:CFStreamClientContext = CFStreamClientContext.init(version: 0, info: &targetUrl, retain: nil, release: nil, copyDescription: nil) + let runLoopSource = CFNetworkExecuteProxyAutoConfigurationURL(_pacUrl!,targetUrl!, { client, proxies, error in + let _proxies = proxies as? [[CFString: Any]] ?? []; + if(_proxies != nil){ + if(_proxies.count > 0){ + let proxy = _proxies.first{$0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTP || $0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTPS} + if(proxy != nil){ + let host = proxy?[kCFProxyHostNameKey] ?? nil + let port = proxy?[kCFProxyPortNumberKey] ?? nil + var dict:[String: Any] = [:] + dict["host"] = host + dict["port"] = port + let context = client.assumingMemoryBound(to: CFStreamClientContext.self).pointee + let url = context.info.assumingMemoryBound(to: CFURL.self).pointee + do{ + let urlString = CFURLGetString(url); + SwiftFlutterSystemProxyPlugin.proxyCache[urlString as! String] = dict + print(url) + }catch error{ + print(error) + } + } + } + } + CFRunLoopStop(CFRunLoopGetCurrent()); + }, &context).takeUnretainedValue() + let runLoop = CFRunLoopGetCurrent(); + CFRunLoopAddSource(runLoop, runLoopSource, CFRunLoopMode.defaultMode); + CFRunLoopRun(); + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runLoopSource, CFRunLoopMode.defaultMode); + } } - + } + diff --git a/pac/test.pac b/pac/test.pac new file mode 100644 index 0000000..8378abd --- /dev/null +++ b/pac/test.pac @@ -0,0 +1,8 @@ +function FindProxyForURL(url, host) +{ + if(host.includes("ip-api")){ + return "PROXY 127.0.0.1:8000" + }else{ + return "DIRECT" + } +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 4ed2c66..30ae488 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,14 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -42,14 +42,14 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.4" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" sky_engine: dependency: transitive description: flutter @@ -92,7 +99,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -127,21 +134,14 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.4.9" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.2" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=1.20.0" From 95d71873a1c91b743b234cc2faf78c8f4c4371b5 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Wed, 29 Nov 2023 16:09:47 +0530 Subject: [PATCH 12/22] fix: iOS 17 issue --- .../SwiftFlutterSystemProxyPlugin.swift | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift index 0ed411c..f4efe76 100644 --- a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift +++ b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift @@ -14,27 +14,29 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { switch call.method { case "getDeviceProxy": - do { - let args = call.arguments as! NSDictionary - let url = args.value(forKey:"url") as! String - var dict:[String:Any] = [:] - if(SwiftFlutterSystemProxyPlugin.proxyCache[url] != nil){ + do { + let args = call.arguments as! NSDictionary + let url = args.value(forKey:"url") as! String + var dict:[String:Any] = [:] + if(SwiftFlutterSystemProxyPlugin.proxyCache[url] != nil){ let res = SwiftFlutterSystemProxyPlugin.proxyCache[url] if(res != nil){ dict = res as! [String:Any] } - } else { - let res = try SwiftFlutterSystemProxyPlugin.resolve(url: url) - if(res != nil){ + } + else + { + let res = try SwiftFlutterSystemProxyPlugin.resolve(url: url) + if(res != nil){ dict = res as! [String:Any] + } } - } - result(dict) + result(dict) } catch let error { print("Unexpected Proxy Error: \(error).") result(error) } - break + break default: result(FlutterMethodNotImplemented) } @@ -67,7 +69,7 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict } } - return proxyCache[url] + return SwiftFlutterSystemProxyPlugin.proxyCache[url] } static func handlePacContent(pacContent: String,url: String){ @@ -88,8 +90,9 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { static func handlePacUrl(pacUrl: String, url: String){ var _pacUrl = CFURLCreateWithString(kCFAllocatorDefault, pacUrl as CFString?,nil) var targetUrl = CFURLCreateWithString(kCFAllocatorDefault, url as CFString?, nil) + var info = url; if(pacUrl != nil && targetUrl != nil){ - var context:CFStreamClientContext = CFStreamClientContext.init(version: 0, info: &targetUrl, retain: nil, release: nil, copyDescription: nil) + var context:CFStreamClientContext = CFStreamClientContext.init(version: 0, info: &info, retain: nil, release: nil, copyDescription: nil) let runLoopSource = CFNetworkExecuteProxyAutoConfigurationURL(_pacUrl!,targetUrl!, { client, proxies, error in let _proxies = proxies as? [[CFString: Any]] ?? []; if(_proxies != nil){ @@ -101,15 +104,8 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { var dict:[String: Any] = [:] dict["host"] = host dict["port"] = port - let context = client.assumingMemoryBound(to: CFStreamClientContext.self).pointee - let url = context.info.assumingMemoryBound(to: CFURL.self).pointee - do{ - let urlString = CFURLGetString(url); - SwiftFlutterSystemProxyPlugin.proxyCache[urlString as! String] = dict - print(url) - }catch error{ - print(error) - } + let url = client.assumingMemoryBound(to: String.self).pointee + SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict } } } From 022ef2cc920d3ae0e151508a841f78e891bcdadc Mon Sep 17 00:00:00 2001 From: PaulineMoovency <151649940+PaulineMoovency@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:10:54 +0200 Subject: [PATCH 13/22] Add namespace in build gradle (#17) * add namespace for Android * upgrade version * remove package name in android manifest and create namespace in build.gradle --- android/build.gradle | 1 + android/src/main/AndroidManifest.xml | 2 +- example/pubspec.lock | 26 +++---- pubspec.lock | 102 ++++++++++++++++----------- pubspec.yaml | 4 +- 5 files changed, 76 insertions(+), 59 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 02f756c..c686b5b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -22,6 +22,7 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { + namespace 'com.browserstack.fluttersystemproxy.flutter_system_proxy' compileSdkVersion 30 defaultConfig { diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 0e9c1af..c87b983 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ +> diff --git a/example/pubspec.lock b/example/pubspec.lock index bb17097..e028d5a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: @@ -110,10 +110,10 @@ packages: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" path: dependency: transitive description: @@ -139,18 +139,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -171,10 +171,10 @@ packages: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.1" typed_data: dependency: transitive description: @@ -195,10 +195,10 @@ packages: dependency: transitive description: name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "0.3.0" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.2.0-194.0.dev <4.0.0" flutter: ">=1.20.0" diff --git a/pubspec.lock b/pubspec.lock index 30ae488..ba2716c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,51 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -64,30 +63,34 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.5.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.10.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -97,51 +100,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.6.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + url: "https://pub.dev" + source: hosted + version: "0.3.0" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.2.0-194.0.dev <4.0.0" flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index 06303b8..199ce0a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_system_proxy description: A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request. -version: 0.1.0 +version: 0.1.1 homepage: https://github.com/BrowserStackCE/flutter_system_proxy.git environment: @@ -23,5 +23,3 @@ flutter: pluginClass: FlutterSystemProxyPlugin ios: pluginClass: FlutterSystemProxyPlugin - - From 606b4be3f511c9c6808d108848a0174f6039f0a3 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Wed, 25 Sep 2024 19:21:10 +0530 Subject: [PATCH 14/22] add: Xcode 16 support and fix warnings --- .vscode/settings.json | 3 + .../gradle/wrapper/gradle-wrapper.properties | 5 +- .../gradle/wrapper/gradle-wrapper.properties | 6 +- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Podfile | 2 +- example/ios/Podfile.lock | 6 +- example/ios/Runner.xcodeproj/project.pbxproj | 8 +-- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/AppDelegate.swift | 2 +- example/lib/main.dart | 20 +++--- example/pubspec.lock | 58 ++++++++++++----- .../SwiftFlutterSystemProxyPlugin.swift | 65 +++++++++---------- pac/test.pac | 8 --- pubspec.lock | 56 +++++++++++----- pubspec.yaml | 2 +- test/flutter_system_proxy_test.dart | 1 - 16 files changed, 141 insertions(+), 105 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 pac/test.pac diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 3c9d085..3c72a71 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Wed Sep 25 17:08:44 IST 2024 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index bc6a58a..5b0a67c 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jun 23 08:50:38 CEST 2017 +#Wed Sep 25 17:08:39 IST 2024 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9625e10..7c56964 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/example/ios/Podfile b/example/ios/Podfile index 313ea4a..2c068c4 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -platform :ios, '11.0' +platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 0b05a0d..99a28d8 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -14,9 +14,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_system_proxy/ios" SPEC CHECKSUMS: - Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 flutter_system_proxy: 96eb97e3857a1d1bc533a6f7387a1f0dcb63d782 -PODFILE CHECKSUM: 7368163408c647b7eb699d0d788ba6718e18fb8d +PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048 -COCOAPODS: 1.11.3 +COCOAPODS: 1.15.2 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index d356f60..5723d28 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -155,7 +155,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -342,7 +342,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -420,7 +420,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -469,7 +469,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index b52b2e6..e67b280 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ { int _counter = 0; String _res = "Response"; void _incrementCounter() { - setState(() { - _counter++; - }); fetchLocalHost().then((value) { - print(value); setState(() { - _res = value.toString(); + _counter++; + _res = value; }); }); } @@ -61,11 +57,11 @@ class _MyHomePageState extends State { ), Text( '$_counter', - style: Theme.of(context).textTheme.headline4, + style: Theme.of(context).textTheme.headlineMedium, ), Text( '$_counter:$_res', - style: Theme.of(context).textTheme.bodyText1, + style: Theme.of(context).textTheme.bodyLarge, ) ], ), @@ -80,17 +76,21 @@ class _MyHomePageState extends State { } Future fetchLocalHost() async { + try { var dio = new Dio(); var url = 'http://ip-api.com/json'; var proxy = await FlutterSystemProxy.findProxyFromEnvironment(url); - print(proxy); (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) { client.findProxy = (uri) { return proxy; }; + return null; }; var response = await dio.get(url); - print(response.toString()); return response.toString(); + } catch (e) { + print(e); + return "Error"; + } } diff --git a/example/pubspec.lock b/example/pubspec.lock index e028d5a..46738ad 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -76,7 +76,7 @@ packages: path: ".." relative: true source: path - version: "0.1.0" + version: "0.1.1" flutter_test: dependency: "direct dev" description: flutter @@ -90,38 +90,62 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.15.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -171,10 +195,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.2" typed_data: dependency: transitive description: @@ -191,14 +215,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "14.2.5" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" - flutter: ">=1.20.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift index f4efe76..35b3e84 100644 --- a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift +++ b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift @@ -14,28 +14,23 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { switch call.method { case "getDeviceProxy": - do { let args = call.arguments as! NSDictionary let url = args.value(forKey:"url") as! String - var dict:[String:Any] = [:] + var dict:[String:Any]? = [:] if(SwiftFlutterSystemProxyPlugin.proxyCache[url] != nil){ let res = SwiftFlutterSystemProxyPlugin.proxyCache[url] if(res != nil){ - dict = res as! [String:Any] + dict = res } } else { - let res = try SwiftFlutterSystemProxyPlugin.resolve(url: url) + let res = SwiftFlutterSystemProxyPlugin.resolve(url: url) if(res != nil){ - dict = res as! [String:Any] + dict = res } } result(dict) - } catch let error { - print("Unexpected Proxy Error: \(error).") - result(error) - } break default: result(FlutterMethodNotImplemented) @@ -88,34 +83,32 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { } static func handlePacUrl(pacUrl: String, url: String){ - var _pacUrl = CFURLCreateWithString(kCFAllocatorDefault, pacUrl as CFString?,nil) - var targetUrl = CFURLCreateWithString(kCFAllocatorDefault, url as CFString?, nil) + let _pacUrl = CFURLCreateWithString(kCFAllocatorDefault, pacUrl as CFString?,nil) + let targetUrl = CFURLCreateWithString(kCFAllocatorDefault, url as CFString?, nil) var info = url; - if(pacUrl != nil && targetUrl != nil){ - var context:CFStreamClientContext = CFStreamClientContext.init(version: 0, info: &info, retain: nil, release: nil, copyDescription: nil) - let runLoopSource = CFNetworkExecuteProxyAutoConfigurationURL(_pacUrl!,targetUrl!, { client, proxies, error in - let _proxies = proxies as? [[CFString: Any]] ?? []; - if(_proxies != nil){ - if(_proxies.count > 0){ - let proxy = _proxies.first{$0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTP || $0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTPS} - if(proxy != nil){ - let host = proxy?[kCFProxyHostNameKey] ?? nil - let port = proxy?[kCFProxyPortNumberKey] ?? nil - var dict:[String: Any] = [:] - dict["host"] = host - dict["port"] = port - let url = client.assumingMemoryBound(to: String.self).pointee - SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict - } - } - } - CFRunLoopStop(CFRunLoopGetCurrent()); - }, &context).takeUnretainedValue() - let runLoop = CFRunLoopGetCurrent(); - CFRunLoopAddSource(runLoop, runLoopSource, CFRunLoopMode.defaultMode); - CFRunLoopRun(); - CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runLoopSource, CFRunLoopMode.defaultMode); - } + withUnsafeMutablePointer(to: &info, { infoPointer in + var context:CFStreamClientContext = CFStreamClientContext.init(version: 0, info: infoPointer, retain: nil, release: nil, copyDescription: nil) + let runLoopSource = CFNetworkExecuteProxyAutoConfigurationURL(_pacUrl!,targetUrl!, { client, proxies, error in + let _proxies = proxies as? [[CFString: Any]] ?? []; + if(_proxies.count > 0){ + let proxy = _proxies.first{$0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTP || $0[kCFProxyTypeKey] as! CFString == kCFProxyTypeHTTPS} + if(proxy != nil){ + let host = proxy?[kCFProxyHostNameKey] ?? nil + let port = proxy?[kCFProxyPortNumberKey] ?? nil + var dict:[String: Any] = [:] + dict["host"] = host + dict["port"] = port + let url = client.assumingMemoryBound(to: String.self).pointee + SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict + } + } + CFRunLoopStop(CFRunLoopGetCurrent()); + }, &context); + let runLoop = CFRunLoopGetCurrent(); + CFRunLoopAddSource(runLoop, runLoopSource, CFRunLoopMode.defaultMode); + CFRunLoopRun(); + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runLoopSource, CFRunLoopMode.defaultMode); + }) } } diff --git a/pac/test.pac b/pac/test.pac deleted file mode 100644 index 8378abd..0000000 --- a/pac/test.pac +++ /dev/null @@ -1,8 +0,0 @@ -function FindProxyForURL(url, host) -{ - if(host.includes("ip-api")){ - return "PROXY 127.0.0.1:8000" - }else{ - return "DIRECT" - } -} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index ba2716c..df9b838 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -59,38 +59,62 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.15.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -140,10 +164,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.2" vector_math: dependency: transitive description: @@ -152,14 +176,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "14.2.5" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" - flutter: ">=1.20.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 199ce0a..d22e252 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_system_proxy description: A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request. -version: 0.1.1 +version: 0.1.2 homepage: https://github.com/BrowserStackCE/flutter_system_proxy.git environment: diff --git a/test/flutter_system_proxy_test.dart b/test/flutter_system_proxy_test.dart index 85b48ae..203d4af 100644 --- a/test/flutter_system_proxy_test.dart +++ b/test/flutter_system_proxy_test.dart @@ -1,6 +1,5 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:flutter_system_proxy/flutter_system_proxy.dart'; void main() { const MethodChannel channel = MethodChannel('flutter_system_proxy'); From 17399b7686749480ac42e821f1e15a63b5346710 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Wed, 25 Sep 2024 19:29:14 +0530 Subject: [PATCH 15/22] release: v0.1.4 --- example/pubspec.lock | 2 +- pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 46738ad..fbdf565 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -76,7 +76,7 @@ packages: path: ".." relative: true source: path - version: "0.1.1" + version: "0.1.4" flutter_test: dependency: "direct dev" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index d22e252..f9ac293 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_system_proxy description: A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request. -version: 0.1.2 +version: 0.1.4 homepage: https://github.com/BrowserStackCE/flutter_system_proxy.git environment: From d8f08bbb4871a4149ed207d43902fa4e249fc3d4 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Thu, 26 Sep 2024 09:42:45 +0530 Subject: [PATCH 16/22] add: backward compatibility for <= Xcode15 --- ios/Classes/SwiftFlutterSystemProxyPlugin.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift index 35b3e84..12270f3 100644 --- a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift +++ b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift @@ -105,11 +105,20 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { CFRunLoopStop(CFRunLoopGetCurrent()); }, &context); let runLoop = CFRunLoopGetCurrent(); - CFRunLoopAddSource(runLoop, runLoopSource, CFRunLoopMode.defaultMode); + CFRunLoopAddSource(runLoop, getRunLoopSource(runLoopSource), CFRunLoopMode.defaultMode); CFRunLoopRun(); CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runLoopSource, CFRunLoopMode.defaultMode); }) } + //For backward compatibility <= XCode 15 + static func getRunLoopSource(_ runLoopSource: T) -> CFRunLoopSource { + if let unmanagedValue = runLoopSource as? Unmanaged { + return unmanagedValue.takeUnretainedValue() + } else { + return runLoopSource as! CFRunLoopSource + } + } + } From bd9aa7e0cb8bb1a40f350408c5aa3190bb12facd Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Thu, 26 Sep 2024 09:45:17 +0530 Subject: [PATCH 17/22] release v0.1.5 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index f9ac293..8de951d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_system_proxy description: A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request. -version: 0.1.4 +version: 0.1.5 homepage: https://github.com/BrowserStackCE/flutter_system_proxy.git environment: From 66d28cd701630468a3ffac5956160a204f05794f Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Thu, 26 Sep 2024 10:31:56 +0530 Subject: [PATCH 18/22] use built-in constants for ProxyDict --- .../SwiftFlutterSystemProxyPlugin.swift | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift index 12270f3..d4d64da 100644 --- a/ios/Classes/SwiftFlutterSystemProxyPlugin.swift +++ b/ios/Classes/SwiftFlutterSystemProxyPlugin.swift @@ -41,26 +41,20 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin { if(SwiftFlutterSystemProxyPlugin.proxyCache[url] != nil){ return SwiftFlutterSystemProxyPlugin.proxyCache[url] } - let proxConfigDict = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary? - if(proxConfigDict != nil){ - if(proxConfigDict!["ProxyAutoConfigEnable"] as? Int == 1){ - let pacUrl = proxConfigDict!["ProxyAutoConfigURLString"] as? String - let pacContent = proxConfigDict!["ProxyAutoConfigJavaScript"] as? String + let proxConfigDict = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary? + if proxConfigDict != nil { + if(proxConfigDict?[kCFNetworkProxiesProxyAutoConfigEnable] as? Int == 1){ + let pacUrl = proxConfigDict?[kCFNetworkProxiesProxyAutoConfigURLString] as! String? + let pacContent = proxConfigDict?[kCFNetworkProxiesProxyAutoConfigJavaScript] as! String? if(pacContent != nil){ - self.handlePacContent(pacContent: pacContent! as String, url: url) + self.handlePacContent(pacContent: pacContent!, url: url) }else if(pacUrl != nil){ self.handlePacUrl(pacUrl: pacUrl!,url: url) } - } else if (proxConfigDict!["HTTPEnable"] as? Int == 1){ + } else if (proxConfigDict![kCFNetworkProxiesHTTPEnable] as! Int == 1){ var dict: [String: Any] = [:] - dict["host"] = proxConfigDict!["HTTPProxy"] as? String - dict["port"] = proxConfigDict!["HTTPPort"] as? Int - SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict - - } else if ( proxConfigDict!["HTTPSEnable"] as? Int == 1){ - var dict: [String: Any] = [:] - dict["host"] = proxConfigDict!["HTTPSProxy"] as? String - dict["port"] = proxConfigDict!["HTTPSPort"] as? Int + dict["host"] = proxConfigDict![kCFNetworkProxiesHTTPProxy] as? String + dict["port"] = proxConfigDict![kCFNetworkProxiesHTTPPort] as? Int SwiftFlutterSystemProxyPlugin.proxyCache[url] = dict } } From 9863b4ddb0ed43bb65959e4af63beeedb2a97bc6 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Thu, 26 Sep 2024 14:11:48 +0530 Subject: [PATCH 19/22] update gradle plugin version & compile sdk version --- android/build.gradle | 4 ++-- example/android/build.gradle | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index c686b5b..2199420 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:8.6.0' } } @@ -23,7 +23,7 @@ apply plugin: 'com.android.library' android { namespace 'com.browserstack.fluttersystemproxy.flutter_system_proxy' - compileSdkVersion 30 + compileSdkVersion 35 defaultConfig { minSdkVersion 16 diff --git a/example/android/build.gradle b/example/android/build.gradle index 7fe1f18..30c5769 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:8.6.0' } } @@ -22,6 +22,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } From 5f9abf4d867814677052cebfc9ba5aee3404cf8e Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Thu, 26 Sep 2024 14:12:27 +0530 Subject: [PATCH 20/22] upgrade compileSdkVersion & add namespace --- example/android/app/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index d44d61f..2f0cbf5 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,12 +25,12 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 31 - + compileSdkVersion 35 + namespace "com.browserstack.fluttersystemproxy.flutter_system_proxy_example" defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.browserstack.fluttersystemproxy.flutter_system_proxy_example" - minSdkVersion 16 + minSdkVersion flutter.minSdkVersion targetSdkVersion 30 versionCode flutterVersionCode.toInteger() versionName flutterVersionName From 9dd88dead9935bffeda440994468d8aab064b816 Mon Sep 17 00:00:00 2001 From: Rushabh Shroff Date: Thu, 26 Sep 2024 15:14:58 +0530 Subject: [PATCH 21/22] update android project --- example/android/app/build.gradle | 15 ++++------ .../android/app/src/main/AndroidManifest.xml | 3 +- example/android/build.gradle | 11 ------- example/android/settings.gradle | 29 ++++++++++++++----- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 2f0cbf5..ab5353e 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,8 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +11,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,9 +21,6 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { compileSdkVersion 35 namespace "com.browserstack.fluttersystemproxy.flutter_system_proxy_example" @@ -31,7 +28,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.browserstack.fluttersystemproxy.flutter_system_proxy_example" minSdkVersion flutter.minSdkVersion - targetSdkVersion 30 + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 438577f..971b721 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -10,7 +10,8 @@ android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" - android:windowSoftInputMode="adjustResize"> + android:windowSoftInputMode="adjustResize" + android:exported="false">