Skip to content

Commit 6136e76

Browse files
Adam Fiskclaude
authored andcommitted
peer-proxy: add macOS native handler
macOS routes through MethodChannel → Swift → MobileSetPeerShareEnabled (gomobile-bind) rather than the FFI path that Windows + Linux use. The previous review fix gated the toggle to PlatformUtils.isFFISupported to avoid a MissingPluginException on macOS, but per Phase 1 plan macOS should be supported. * macos/Runner/Handlers/MethodHandler.swift: new setPeerProxyEnabled case + setPeerProxyEnabled function calling MobileSetPeerShareEnabled, plus an isPeerProxyEnabled case calling MobileIsPeerShareEnabled. Mirrors the existing setBlockAdsEnabled handler exactly. (The MobileSet/IsPeerShareEnabled gomobile bindings come from the SetPeerShareEnabled / IsPeerShareEnabled methods added to lantern-core/mobile/mobile.go in PR 8729; the Liblantern xcframework needs a rebuild via `make macos-framework` to pick them up.) * lantern_platform_service.dart: restore the MethodChannel passthrough for setPeerProxyEnabled / isPeerProxyEnabled. The "not supported on this platform" stubs from the prior review fix are no longer appropriate now that there's a native handler. * vpn_setting.dart: widen the toggle gate from isFFISupported (Windows + Linux) to isDesktop (Windows + Linux + macOS). * radiance_settings_providers.dart: same widening for the isPeerProxyEnabled probe in _refresh. Verified locally: `make macos-framework` rebuilds successfully and exports MobileSetPeerShareEnabled / MobileIsPeerShareEnabled. flutter analyze clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c1605ef commit 6136e76

4 files changed

Lines changed: 45 additions & 13 deletions

File tree

lib/features/home/provider/radiance_settings_providers.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class RadianceSettings extends _$RadianceSettings {
3030
final telemetryF = svc.isTelemetryEnabled();
3131
final splitF = PlatformUtils.isIOS ? null : svc.isSplitTunnelingEnabled();
3232
// Peer-proxy probe runs only on platforms with native handlers
33-
// (FFI-supported = Windows + Linux). On other platforms the call would
34-
// fail with MissingPluginException on every settings init.
35-
final peerF = PlatformUtils.isFFISupported ? svc.isPeerProxyEnabled() : null;
33+
// (Windows + Linux via FFI, macOS via MethodChannel — i.e. all desktop).
34+
// On iOS / Android the call would fail with MissingPluginException on
35+
// every settings init.
36+
final peerF = PlatformUtils.isDesktop ? svc.isPeerProxyEnabled() : null;
3637

3738
final results = await Future.wait([
3839
blockAdsF,

lib/features/setting/vpn_setting.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class VPNSetting extends HookConsumerWidget {
120120
},
121121
),
122122
),
123-
if (PlatformUtils.isFFISupported) ...{
123+
if (PlatformUtils.isDesktop) ...{
124124
SizedBox(height: 16),
125125
AppCard(
126126
padding: EdgeInsets.zero,

lib/lantern/lantern_platform_service.dart

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,28 @@ class LanternPlatformService implements LanternCoreService {
290290
}
291291
}
292292

293-
// Peer-proxy has no native MethodChannel handler outside the FFI path.
294-
// The toggle is gated to PlatformUtils.isFFISupported in the UI, so these
295-
// implementations exist for interface conformance only and return a clear
296-
// error rather than a MissingPluginException if ever invoked.
297293
@override
298294
Future<Either<Failure, Unit>> setPeerProxyEnabled(bool enabled) async {
299-
return Left(Failure(
300-
error: 'peer-proxy not supported on this platform',
301-
localizedErrorMessage: 'peer-proxy not supported on this platform',
302-
));
295+
try {
296+
await _methodChannel.invokeMethod('setPeerProxyEnabled', {
297+
'enabled': enabled,
298+
});
299+
return right(unit);
300+
} catch (e, st) {
301+
appLogger.error('setPeerProxyEnabled failed', e, st);
302+
return Left(e.toFailure());
303+
}
303304
}
304305

305306
@override
306307
Future<Either<Failure, bool>> isPeerProxyEnabled() async {
307-
return right(false);
308+
try {
309+
final res = await _methodChannel.invokeMethod<bool>('isPeerProxyEnabled');
310+
return right(res ?? false);
311+
} catch (e, st) {
312+
appLogger.error('isPeerProxyEnabled failed', e, st);
313+
return Left(e.toFailure());
314+
}
308315
}
309316

310317
@override

macos/Runner/Handlers/MethodHandler.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ class MethodHandler {
245245
let enabled = data?["enabled"] as? Bool ?? false
246246
self.setBlockAdsEnabled(result: result, enabled: enabled)
247247

248+
case "isPeerProxyEnabled":
249+
Task {
250+
await MainActor.run { result(MobileIsPeerShareEnabled()) }
251+
}
252+
253+
case "setPeerProxyEnabled":
254+
let data = call.arguments as? [String: Any]
255+
let enabled = data?["enabled"] as? Bool ?? false
256+
self.setPeerProxyEnabled(result: result, enabled: enabled)
257+
248258
case "updateTelemetryEvents":
249259
guard let consent: Bool = self.decodeValue(from: call.arguments, result: result) else {
250260
return
@@ -1152,6 +1162,20 @@ class MethodHandler {
11521162
}
11531163
}
11541164

1165+
func setPeerProxyEnabled(result: @escaping FlutterResult, enabled: Bool) {
1166+
Task {
1167+
var error: NSError?
1168+
MobileSetPeerShareEnabled(enabled, &error)
1169+
if let error {
1170+
await self.handleFlutterError(error, result: result, code: "SET_PEER_PROXY_ERROR")
1171+
return
1172+
}
1173+
await MainActor.run {
1174+
result("ok")
1175+
}
1176+
}
1177+
}
1178+
11551179
func updateTelemetryEvents(consent: Bool, result: @escaping FlutterResult) {
11561180
Task {
11571181
var error: NSError?

0 commit comments

Comments
 (0)