Skip to content

Commit

Permalink
proxy-only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
r3pr3ss10n committed Aug 27, 2024
1 parent 4e3c608 commit a73a3c9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class MainActivity: FlutterActivity() {
"stop_proxy" -> stopProxyService(result)
"is_proxy_running" -> isProxyRunning(result)
"test_service" -> testService(result)
"open_binary_sc" -> openBinary(result)
"open_binary" -> openBinary(result)
"open_me" -> openMe(result)
else -> result.notImplemented()
}
}
Expand Down Expand Up @@ -81,7 +82,9 @@ class MainActivity: FlutterActivity() {
startService(serviceIntent)
}

requestVpnPermission()
if (call.argument<Boolean>("vpn_mode") == true) {
requestVpnPermission()
}

result.success("Proxy service started, VPN request initiated")
}
Expand Down
2 changes: 1 addition & 1 deletion lib/globals.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const appVersion = "1.0";
const appVersion = "1.1";
20 changes: 18 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class HomePage extends HookWidget {
} else {
try {
var params = buildParams();
await platform.invokeMethod('start_proxy', {'params': params});
await platform.invokeMethod('start_proxy', {'params': params, 'vpn_mode': SpUtil.getBool('use_vpn_mode', defValue: true)});
isRunning.value = true;
} on PlatformException catch (e) {
print("Failed to start proxy: '${e.message}'.");
Expand Down Expand Up @@ -180,7 +180,11 @@ class SettingsPage extends HookWidget {

@override
Widget build(BuildContext context) {

final vpnMode = useState(SpUtil.getBool('use_vpn_mode', defValue: true)!);

final enableDoh = useState(SpUtil.getBool('doh', defValue: true)!);

final TextEditingController dnsController = useTextEditingController(
text: SpUtil.getString('dns', defValue: '8.8.8.8'),
);
Expand All @@ -193,6 +197,11 @@ class SettingsPage extends HookWidget {
SpUtil.putBool('doh', enableDoh.value);
}

void updateVpnMode(bool? value) {
vpnMode.value = value ?? true;
SpUtil.putBool('use_vpn_mode', vpnMode.value);
}

void updateDns(String value) {
if (_isValidIp(value)) {
SpUtil.putString('dns', value);
Expand All @@ -212,13 +221,20 @@ class SettingsPage extends HookWidget {
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
CheckboxListTile(
secondary: const Icon(Icons.vpn_key),
title: const Text('Use VPN mode'),
subtitle: const Text('If disabled - only Proxy server will be started'),
value: vpnMode.value,
onChanged: updateVpnMode,
),
CheckboxListTile(
secondary: const Icon(Icons.public),
title: const Text('Enable DOH'),
value: enableDoh.value,
onChanged: updateDoh,
),
SizedBox(height: 15,),
const SizedBox(height: 15,),
TextField(
controller: dnsController,
decoration: const InputDecoration(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1
version: 1.1.0+1

environment:
sdk: ^3.5.1
Expand Down

0 comments on commit a73a3c9

Please sign in to comment.