Skip to content

Commit

Permalink
re-use home and lantern app widgets on desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed Nov 30, 2023
1 parent f1f2229 commit bfe8eea
Show file tree
Hide file tree
Showing 21 changed files with 650 additions and 709 deletions.
60 changes: 60 additions & 0 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,61 @@ func EmailAddress() *C.char {
return C.CString("")
}

//export Referral
func Referral() *C.char {
return C.CString("")
}

//export ChatEnabled
func ChatEnabled() *C.char {
return C.CString("false")
}

//export PlayVersion
func PlayVersion() *C.char {
return C.CString("false")
}

//export StoreVersion
func StoreVersion() *C.char {
return C.CString("false")
}

//export Lang
func Lang() *C.char {
return C.CString("en")
}

//export Country
func Country() *C.char {
return C.CString("US")
}

//export SdkVersion
func SdkVersion() *C.char {
return C.CString("1.0.0")
}

//export VpnStatus
func VpnStatus() *C.char {
return C.CString("disconnected")
}

//export HasSucceedingProxy
func HasSucceedingProxy() *C.char {
return C.CString("true")
}

//export OnBoardingStatus
func OnBoardingStatus() *C.char {
return C.CString("true")
}

//export AcceptedTermsVersion
func AcceptedTermsVersion() *C.char {
return C.CString("0")
}

//export ProUser
func ProUser() *C.char {
if isProUser, ok := a.IsProUser(); isProUser && ok {
Expand All @@ -141,6 +191,16 @@ func ProUser() *C.char {
return C.CString("false")
}

//export DevelopmentMode
func DevelopmentMode() *C.char {
return C.CString("false")
}

//export SplitTunneling
func SplitTunneling() *C.char {
return C.CString("false")
}

//export ReplicaAddr
func ReplicaAddr() *C.char {
return C.CString("")
Expand Down
26 changes: 14 additions & 12 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ class LanternApp extends StatelessWidget {
// Since this notification is visible on all screens and we want the
// animation state to remain consistent across screens, we put the animation
// controller here at the app level since the app contains all screens.
sessionModel.networkAvailable
.addListener(toggleConnectivityWarningIfNecessary);
sessionModel.proxyAvailable
.addListener(toggleConnectivityWarningIfNecessary);
networkWarningAnimationController = AnimationController(
duration: shortAnimationDuration,
vsync: _TickerProviderImpl(),
);
networkWarningAnimation = Tween(begin: 0.0, end: 1.0)
.animate(networkWarningAnimationController)
..addListener(networkWarningAnimationChanged);
toggleConnectivityWarningIfNecessary();
if (Platform.isAndroid) {
sessionModel.networkAvailable
.addListener(toggleConnectivityWarningIfNecessary);
sessionModel.proxyAvailable
.addListener(toggleConnectivityWarningIfNecessary);
networkWarningAnimationController = AnimationController(
duration: shortAnimationDuration,
vsync: _TickerProviderImpl(),
);
networkWarningAnimation = Tween(begin: 0.0, end: 1.0)
.animate(networkWarningAnimationController)
..addListener(networkWarningAnimationChanged);
toggleConnectivityWarningIfNecessary();
}
}

final translations = Localization.ensureInitialized();
Expand Down
2 changes: 1 addition & 1 deletion lib/common/common_desktop.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export 'dart:convert';
export 'dart:ffi'; // For FFI

export 'package:lantern/desktop/ffi.dart';
export 'package:lantern/ffi.dart';
export 'package:ffi/ffi.dart';
export 'package:ffi/src/utf8.dart';
5 changes: 4 additions & 1 deletion lib/common/ffi_subscriber.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ class FfiValueNotifier<T> extends SubscribedNotifier<T?> {
bool details = false,
T Function(Uint8List serialized)? deserialize,
}) : super(defaultValue, removeFromCache) {
if (defaultValue is String?) {
if (defaultValue is int?) {
value = int.parse(ffiFunction().toDartString()) as T?;
} else if (defaultValue is String) {
value = ffiFunction().toDartString() as T?;
} else {
value = ffiFunction().toDartString().parseBool() as T?;
}
cancel = () => {};
}
}

Expand Down
8 changes: 5 additions & 3 deletions lib/common/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ abstract class Model {
final Map<String, FfiListNotifier> _ffiListNotifierCache = HashMap();

Model(String name) {
methodChannel = MethodChannel('${name}_method_channel');
_updatesChannel = ModelEventChannel('${name}_event_channel');
if (Platform.isAndroid) {
methodChannel = MethodChannel('${name}_method_channel');
_updatesChannel = ModelEventChannel('${name}_event_channel');
}
}

Future<T> get<T>(String path) async {
Expand Down Expand Up @@ -93,7 +95,7 @@ abstract class Model {
T Function(Uint8List serialized)? deserialize,
}) {
var result =
_ffiValueNotifierCache[path] as FfiValueNotifier<T>?;
_ffiValueNotifierCache[path] as FfiValueNotifier<T?>?;
if (result == null) {
result = FfiValueNotifier(
ffiFunction,
Expand Down
Loading

0 comments on commit bfe8eea

Please sign in to comment.