Skip to content

Commit ba28353

Browse files
authored
Merge pull request #82 from chaopengCoder/master
iOS clicks 'Don't allow' button
2 parents fa21408 + da23cfb commit ba28353

File tree

3 files changed

+107
-57
lines changed

3 files changed

+107
-57
lines changed

example/pubspec.lock

+60-32
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,56 @@ packages:
55
dependency: transitive
66
description:
77
name: async
8-
url: "https://pub.dartlang.org"
8+
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
9+
url: "https://pub.dev"
910
source: hosted
10-
version: "2.9.0"
11+
version: "2.10.0"
1112
boolean_selector:
1213
dependency: transitive
1314
description:
1415
name: boolean_selector
15-
url: "https://pub.dartlang.org"
16+
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
17+
url: "https://pub.dev"
1618
source: hosted
17-
version: "2.1.0"
19+
version: "2.1.1"
1820
characters:
1921
dependency: transitive
2022
description:
2123
name: characters
22-
url: "https://pub.dartlang.org"
24+
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
25+
url: "https://pub.dev"
2326
source: hosted
2427
version: "1.2.1"
2528
clock:
2629
dependency: transitive
2730
description:
2831
name: clock
29-
url: "https://pub.dartlang.org"
32+
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
33+
url: "https://pub.dev"
3034
source: hosted
3135
version: "1.1.1"
3236
collection:
3337
dependency: transitive
3438
description:
3539
name: collection
36-
url: "https://pub.dartlang.org"
40+
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
41+
url: "https://pub.dev"
3742
source: hosted
38-
version: "1.16.0"
43+
version: "1.17.0"
3944
cupertino_icons:
4045
dependency: "direct main"
4146
description:
4247
name: cupertino_icons
43-
url: "https://pub.dartlang.org"
48+
sha256: "1989d917fbe8e6b39806207df5a3fdd3d816cbd090fac2ce26fb45e9a71476e5"
49+
url: "https://pub.dev"
4450
source: hosted
4551
version: "1.0.4"
4652
fake_async:
4753
dependency: transitive
4854
description:
4955
name: fake_async
50-
url: "https://pub.dartlang.org"
56+
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
57+
url: "https://pub.dev"
5158
source: hosted
5259
version: "1.3.1"
5360
flutter:
@@ -59,40 +66,53 @@ packages:
5966
dependency: "direct dev"
6067
description:
6168
name: flutter_lints
62-
url: "https://pub.dartlang.org"
69+
sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493
70+
url: "https://pub.dev"
6371
source: hosted
6472
version: "1.0.4"
6573
flutter_test:
6674
dependency: "direct dev"
6775
description: flutter
6876
source: sdk
6977
version: "0.0.0"
78+
js:
79+
dependency: transitive
80+
description:
81+
name: js
82+
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
83+
url: "https://pub.dev"
84+
source: hosted
85+
version: "0.6.5"
7086
lints:
7187
dependency: transitive
7288
description:
7389
name: lints
74-
url: "https://pub.dartlang.org"
90+
sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c
91+
url: "https://pub.dev"
7592
source: hosted
7693
version: "1.0.1"
7794
matcher:
7895
dependency: transitive
7996
description:
8097
name: matcher
81-
url: "https://pub.dartlang.org"
98+
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
99+
url: "https://pub.dev"
82100
source: hosted
83-
version: "0.12.12"
101+
version: "0.12.13"
84102
material_color_utilities:
85103
dependency: transitive
86104
description:
87105
name: material_color_utilities
88-
url: "https://pub.dartlang.org"
106+
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
107+
url: "https://pub.dev"
89108
source: hosted
90-
version: "0.1.5"
109+
version: "0.2.0"
91110
meta:
92111
dependency: transitive
93112
description:
94113
name: meta
95-
url: "https://pub.dartlang.org"
114+
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
115+
url: "https://pub.dev"
96116
source: hosted
97117
version: "1.8.0"
98118
openvpn_flutter:
@@ -106,7 +126,8 @@ packages:
106126
dependency: transitive
107127
description:
108128
name: path
109-
url: "https://pub.dartlang.org"
129+
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
130+
url: "https://pub.dev"
110131
source: hosted
111132
version: "1.8.2"
112133
sky_engine:
@@ -118,51 +139,58 @@ packages:
118139
dependency: transitive
119140
description:
120141
name: source_span
121-
url: "https://pub.dartlang.org"
142+
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
143+
url: "https://pub.dev"
122144
source: hosted
123-
version: "1.9.0"
145+
version: "1.9.1"
124146
stack_trace:
125147
dependency: transitive
126148
description:
127149
name: stack_trace
128-
url: "https://pub.dartlang.org"
150+
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
151+
url: "https://pub.dev"
129152
source: hosted
130-
version: "1.10.0"
153+
version: "1.11.0"
131154
stream_channel:
132155
dependency: transitive
133156
description:
134157
name: stream_channel
135-
url: "https://pub.dartlang.org"
158+
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
159+
url: "https://pub.dev"
136160
source: hosted
137-
version: "2.1.0"
161+
version: "2.1.1"
138162
string_scanner:
139163
dependency: transitive
140164
description:
141165
name: string_scanner
142-
url: "https://pub.dartlang.org"
166+
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
167+
url: "https://pub.dev"
143168
source: hosted
144-
version: "1.1.1"
169+
version: "1.2.0"
145170
term_glyph:
146171
dependency: transitive
147172
description:
148173
name: term_glyph
149-
url: "https://pub.dartlang.org"
174+
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
175+
url: "https://pub.dev"
150176
source: hosted
151177
version: "1.2.1"
152178
test_api:
153179
dependency: transitive
154180
description:
155181
name: test_api
156-
url: "https://pub.dartlang.org"
182+
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
183+
url: "https://pub.dev"
157184
source: hosted
158-
version: "0.4.12"
185+
version: "0.4.16"
159186
vector_math:
160187
dependency: transitive
161188
description:
162189
name: vector_math
163-
url: "https://pub.dartlang.org"
190+
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
191+
url: "https://pub.dev"
164192
source: hosted
165-
version: "2.1.2"
193+
version: "2.1.4"
166194
sdks:
167-
dart: ">=2.17.0-0 <3.0.0"
195+
dart: ">=2.18.0 <3.0.0"
168196
flutter: ">=2.5.0"

ios/Classes/SwiftOpenVPNFlutterPlugin.swift

+32-16
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import NetworkExtension
55
public class SwiftOpenVPNFlutterPlugin: NSObject, FlutterPlugin {
66
private static var utils : VPNUtils! = VPNUtils()
77

8-
private static var EVENT_CHANNEL_VPN_STAGE : String = "id.laskarmedia.openvpn_flutter/vpnstage"
9-
private static var METHOD_CHANNEL_VPN_CONTROL : String = "id.laskarmedia.openvpn_flutter/vpncontrol"
8+
private static var EVENT_CHANNEL_VPN_STAGE = "id.laskarmedia.openvpn_flutter/vpnstage"
9+
private static var METHOD_CHANNEL_VPN_CONTROL = "id.laskarmedia.openvpn_flutter/vpncontrol"
1010

11-
public static var stage: FlutterEventSink?
11+
public static var stage: FlutterEventSink?
1212
private var initialized : Bool = false
1313

1414
public static func register(with registrar: FlutterPluginRegistrar) {
1515
let instance = SwiftOpenVPNFlutterPlugin()
1616
instance.onRegister(registrar)
17-
1817
}
1918

2019
public func onRegister(_ registrar: FlutterPluginRegistrar){
@@ -23,7 +22,7 @@ public class SwiftOpenVPNFlutterPlugin: NSObject, FlutterPlugin {
2322

2423
vpnStageE.setStreamHandler(StageHandler())
2524
vpnControlM.setMethodCallHandler({(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
26-
switch call.method{
25+
switch call.method {
2726
case "status":
2827
SwiftOpenVPNFlutterPlugin.utils.getTraffictStats()
2928
result(UserDefaults.init(suiteName: SwiftOpenVPNFlutterPlugin.utils.groupIdentifier)?.string(forKey: "connectionUpdate"))
@@ -36,15 +35,21 @@ public class SwiftOpenVPNFlutterPlugin: NSObject, FlutterPlugin {
3635
let localizedDescription: String? = (call.arguments as? [String: Any])?["localizedDescription"] as? String
3736
let groupIdentifier: String? = (call.arguments as? [String: Any])?["groupIdentifier"] as? String
3837
if providerBundleIdentifier == nil {
39-
result(FlutterError(code: "-2", message: "providerBundleIdentifier content empty or null", details: nil));
38+
result(FlutterError(code: "-2",
39+
message: "providerBundleIdentifier content empty or null",
40+
details: nil));
4041
return;
4142
}
4243
if localizedDescription == nil {
43-
result(FlutterError(code: "-3", message: "localizedDescription content empty or null", details: nil));
44+
result(FlutterError(code: "-3",
45+
message: "localizedDescription content empty or null",
46+
details: nil));
4447
return;
4548
}
4649
if groupIdentifier == nil {
47-
result(FlutterError(code: "-4", message: "groupIdentifier content empty or null", details: nil));
50+
result(FlutterError(code: "-4",
51+
message: "groupIdentifier content empty or null",
52+
details: nil));
4853
return;
4954
}
5055
SwiftOpenVPNFlutterPlugin.utils.groupIdentifier = groupIdentifier
@@ -54,7 +59,7 @@ public class SwiftOpenVPNFlutterPlugin: NSObject, FlutterPlugin {
5459
if err == nil{
5560
result(SwiftOpenVPNFlutterPlugin.utils.currentStatus())
5661
}else{
57-
result(FlutterError(code: "-4", message: err.debugDescription, details: err?.localizedDescription));
62+
result(FlutterError(code: "-4", message: err?.localizedDescription, details: err?.localizedDescription));
5863
}
5964
}
6065
self.initialized = true
@@ -64,28 +69,34 @@ public class SwiftOpenVPNFlutterPlugin: NSObject, FlutterPlugin {
6469
break;
6570
case "connect":
6671
if !self.initialized {
67-
result(FlutterError(code: "-1", message: "VPNEngine need to be initialize", details: nil));
72+
result(FlutterError(code: "-1",
73+
message: "VPNEngine need to be initialize",
74+
details: nil));
6875
}
6976
let config: String? = (call.arguments as? [String : Any])? ["config"] as? String
7077
let username: String? = (call.arguments as? [String : Any])? ["username"] as? String
7178
let password: String? = (call.arguments as? [String : Any])? ["password"] as? String
7279
if config == nil{
73-
result(FlutterError(code: "-2", message:"Config is empty or nulled", details: "Config can't be nulled"))
80+
result(FlutterError(code: "-2",
81+
message:"Config is empty or nulled",
82+
details: "Config can't be nulled"))
7483
return
7584
}
85+
7686
SwiftOpenVPNFlutterPlugin.utils.configureVPN(config: config, username: username, password: password, completion: {(success:Error?) -> Void in
7787
if(success == nil){
7888
result(nil)
7989
}else{
80-
result(FlutterError(code: "-5", message: success?.localizedDescription, details: success.debugDescription))
90+
result(FlutterError(code: "99",
91+
message: "permission denied",
92+
details: success?.localizedDescription))
8193
}
8294
})
8395
break;
8496
case "dispose":
8597
self.initialized = false
8698
default:
8799
break;
88-
89100
}
90101
})
91102
}
@@ -181,7 +192,6 @@ class VPNUtils {
181192
else{
182193
return "disconnected"
183194
}
184-
// return "DISCONNECTED"
185195
}
186196

187197
func configureVPN(config: String?, username : String?,password : String?,completion:@escaping (_ error : Error?) -> Void) {
@@ -211,9 +221,13 @@ class VPNUtils {
211221
}
212222
do {
213223
if self.vpnStageObserver != nil {
214-
NotificationCenter.default.removeObserver(self.vpnStageObserver!, name: NSNotification.Name.NEVPNStatusDidChange, object: nil)
224+
NotificationCenter.default.removeObserver(self.vpnStageObserver!,
225+
name: NSNotification.Name.NEVPNStatusDidChange,
226+
object: nil)
215227
}
216-
self.vpnStageObserver = NotificationCenter.default.addObserver(forName: NSNotification.Name.NEVPNStatusDidChange, object: nil , queue: nil) { [weak self] notification in
228+
self.vpnStageObserver = NotificationCenter.default.addObserver(forName: NSNotification.Name.NEVPNStatusDidChange,
229+
object: nil ,
230+
queue: nil) { [weak self] notification in
217231
let nevpnconn = notification.object as! NEVPNConnection
218232
let status = nevpnconn.status
219233
self?.onVpnStatusChanged(notification: status)
@@ -235,6 +249,8 @@ class VPNUtils {
235249
completion(error);
236250
}
237251
})
252+
} else {
253+
completion(error);
238254
}
239255
})
240256
}

lib/src/vpn_engine.dart

+15-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22
import 'dart:convert';
33
import 'dart:io';
44
import 'dart:math';
5+
import 'package:flutter/foundation.dart';
56
import 'package:flutter/services.dart';
67
import 'model/vpn_status.dart';
78

@@ -120,21 +121,26 @@ class OpenVPN {
120121
///username & password : set your username and password if your config file has auth-user-pass
121122
///
122123
///bypassPackages : exclude some apps to access/use the VPN Connection, it was List<String> of applications package's name (Android Only)
123-
void connect(String config, String name,
124+
Future connect(String config, String name,
124125
{String? username,
125126
String? password,
126127
List<String>? bypassPackages,
127-
bool certIsRequired = false}) async {
128+
bool certIsRequired = false}) {
128129
if (!initialized) throw ("OpenVPN need to be initialized");
129130
if (!certIsRequired) config += "client-cert-not-required";
130131
_tempDateTime = DateTime.now();
131-
_channelControl.invokeMethod("connect", {
132-
"config": config,
133-
"name": name,
134-
"username": username,
135-
"password": password,
136-
"bypass_packages": bypassPackages ?? []
137-
});
132+
133+
try {
134+
return _channelControl.invokeMethod("connect", {
135+
"config": config,
136+
"name": name,
137+
"username": username,
138+
"password": password,
139+
"bypass_packages": bypassPackages ?? []
140+
});
141+
} on PlatformException catch (e) {
142+
throw ArgumentError(e.message);
143+
}
138144
}
139145

140146
///Disconnect from VPN

0 commit comments

Comments
 (0)