Skip to content

Commit

Permalink
re-use custom bottom bar on desktop and Android. update ffi subscribe…
Browse files Browse the repository at this point in the history
…r to work with boolean values
  • Loading branch information
atavism committed Nov 26, 2023
1 parent 340bff1 commit ca84816
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 382 deletions.
10 changes: 10 additions & 0 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ func EmailAddress() *C.char {
return C.CString("")
}

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

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

// loadSettings loads the initial settings at startup, either from disk or using defaults.
func loadSettings(configDir string) *app.Settings {
path := filepath.Join(configDir, "settings.yaml")
Expand Down
11 changes: 10 additions & 1 deletion lib/common/ffi_subscriber.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'common.dart';
import 'common_desktop.dart';

extension BoolParsing on String {
bool parseBool() {
return this.toLowerCase() == 'true';
}
}

class FfiValueNotifier<T> extends SubscribedNotifier<T?> {
FfiValueNotifier(
Expand All @@ -10,7 +15,11 @@ class FfiValueNotifier<T> extends SubscribedNotifier<T?> {
bool details = false,
T Function(Uint8List serialized)? deserialize,
}) : super(defaultValue, removeFromCache) {
value = ffiFunction().toDartString() as T?;
if (defaultValue is String?) {
value = ffiFunction().toDartString() as T?;
} else {
value = ffiFunction().toDartString().parseBool() as T?;
}
}
}

Expand Down
21 changes: 18 additions & 3 deletions lib/common/session_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,16 @@ class SessionModel extends Model {
}

Widget replicaAddr(ValueWidgetBuilder<String> builder) {
return subscribedSingleValueBuilder<String>(
if (Platform.isAndroid) {
return subscribedSingleValueBuilder<String>(
'replicaAddr',
defaultValue: '',
builder: builder,
);
}
return ffiValueBuilder<String>(
'replicaAddr',
defaultValue: '',
ffiReplicaAddr,
builder: builder,
);
}
Expand All @@ -264,8 +271,16 @@ class SessionModel extends Model {
}

Widget chatEnabled(ValueWidgetBuilder<bool> builder) {
return subscribedSingleValueBuilder<bool>(
if (Platform.isAndroid) {
return subscribedSingleValueBuilder<bool>(
'chatEnabled',
defaultValue: false,
builder: builder,
);
}
return ffiValueBuilder<bool>(
'chatEnabled',
ffiChatEnabled,
defaultValue: false,
builder: builder,
);
Expand Down
7 changes: 2 additions & 5 deletions lib/custom_bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class CustomBottomBar extends StatelessWidget {

@override
Widget build(BuildContext context) {
return messagingModel
.getOnBoardingStatus((context, hasBeenOnboarded, child) {
return sessionModel.chatEnabled((context, chatEnabled, _) {
return sessionModel.chatEnabled((context, chatEnabled, _) {
return sessionModel.replicaAddr((context, replicaAddr, child) {
final replicaEnabled = replicaAddr != '';

Expand Down Expand Up @@ -57,14 +55,13 @@ class CustomBottomBar extends StatelessWidget {
currentIndex,
chatEnabled,
replicaEnabled,
hasBeenOnboarded!,
true,
isDevelop,
isTesting,
replicaAddr,
),
);
});
});
});
}

Expand Down
9 changes: 8 additions & 1 deletion lib/custom_bottom_item.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:lantern/common/common.dart';
import 'package:lantern/common/common_desktop.dart';

class CustomBottomBarItem extends StatelessWidget {
const CustomBottomBarItem({
Expand Down Expand Up @@ -51,7 +52,13 @@ class CustomBottomBarItem extends StatelessWidget {
),
),
onTap: (() {
sessionModel.setSelectedTab(name);
if (Platform.isAndroid) {
sessionModel.setSelectedTab(name);
} else {
final tab = name.toNativeUtf8();
setSelectTab(tab);
context.pushRoute(DesktopHome());
}
}),
child: Container(
decoration: ShapeDecoration(
Expand Down
223 changes: 0 additions & 223 deletions lib/desktop/custom_bottom_bar.dart

This file was deleted.

Loading

0 comments on commit ca84816

Please sign in to comment.