Skip to content

Commit

Permalink
update deps and dht update listening
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed Jan 2, 2025
1 parent 6d80033 commit 9cabf87
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 146 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ app.*.map.json
# WASM
/web/wasm/

android/key.properties
android/key.properties

# FVM Version Cache
.fvm/
3 changes: 2 additions & 1 deletion lib/data/providers/distributed_storage/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ abstract class DistributedStorage {
required String secret,
required String content});

Future<void> watchDHTRecord(String key);
Future<void> watchDHTRecord(
String key, Future<void> Function(String key) onNetworkUpdate);

Future<CoagContact> updateContactSharingDHT(CoagContact contact,
{Future<String> Function()? pskGenerator});
Expand Down
6 changes: 5 additions & 1 deletion lib/data/providers/distributed_storage/dht.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class VeilidDhtStorage extends DistributedStorage {
}

@override
Future<void> watchDHTRecord(String key) async {
Future<void> watchDHTRecord(
String key, Future<void> Function(String key) onNetworkUpdate) async {
final _key = Typed<FixedEncodedString43>.fromString(key);
final DHTRecord record;
if (_openedRecords.containsKey(_key)) {
Expand All @@ -103,6 +104,9 @@ class VeilidDhtStorage extends DistributedStorage {
}
final defaultSubkey = record.subkeyOrDefault(-1);
await record.watch(subkeys: [ValueSubkeyRange.single(defaultSubkey)]);
await record.listen(
(record, data, subkeys) => onNetworkUpdate(record.key.toString()),
localChanges: false);
}

// TODO: Can we update the sharedProfile here as well or not because we're lacking the profile contact?
Expand Down
18 changes: 11 additions & 7 deletions lib/data/repositories/contacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ class ContactsRepository {
ProcessorRepository.instance
.streamProcessorConnectionState()
.listen(_veilidConnectionStateChangeCallback);

// TODO: This doesn't seem to work, double check; current workaround via timerDhtRefresh
ProcessorRepository.instance
.streamUpdateValueChange()
.listen(_veilidUpdateValueChangeCallback);
}

/////////////////////
Expand Down Expand Up @@ -312,8 +307,8 @@ class ContactsRepository {
}
}
if (contact.dhtSettingsForReceiving != null) {
await distributedStorage
.watchDHTRecord(contact.dhtSettingsForReceiving!.key);
await distributedStorage.watchDHTRecord(
contact.dhtSettingsForReceiving!.key, _dhtRecordUpdateCallback);
}
}

Expand All @@ -325,6 +320,7 @@ class ContactsRepository {
unawaited(updateAndWatchReceivingDHT());
unawaited(updateSharingDHT());
}
// TODO: Also handle network unavailable changes?
}

Future<void> _veilidUpdateValueChangeCallback(
Expand Down Expand Up @@ -580,6 +576,14 @@ class ContactsRepository {
await updateContactFromDHT(updatedContact);
}

Future<void> _dhtRecordUpdateCallback(String key) async {
for (final contact in _contacts.values) {
if (key == contact.dhtSettingsForReceiving?.key) {
return updateContactFromDHT(contact);
}
}
}

//////////
// CIRCLES
Map<String, String> getCircles() => _circles;
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/locations/check_in/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class CheckInCubit extends Cubit<CheckInState> {
}
}

// TODO: Check in is e.g. called as the on submit callback in the check in form,
// but the errors are not handled transparently for the user
Future<void> checkIn(
{required String name,
required String details,
Expand Down Expand Up @@ -111,6 +113,7 @@ class CheckInCubit extends Cubit<CheckInState> {
// }
} on TimeoutException {
if (!isClosed) {
// TODO: Where can this be picked up by the UI?
emit(state.copyWith(status: CheckInStatus.locationTimeout));
}
return;
Expand Down
16 changes: 15 additions & 1 deletion lib/ui/locations/check_in/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _MyFormState extends State<MyForm> {
end: DateTime.now()
.add(Duration(hours: _state.hours, minutes: _state.minutes)));
_state = _state.copyWith(status: FormzSubmissionStatus.success);
Navigator.pop(context);
// Navigator.pop(context);
} catch (e) {
_state = _state.copyWith(status: FormzSubmissionStatus.failure);
}
Expand Down Expand Up @@ -326,6 +326,20 @@ class CheckInWidget extends StatelessWidget {
child: Text(
'Location services seem to be disabled, GPS based check-in is not possible.')));
}
if (state.status.isLocationTimeout) {
// TODO: Display error and leave filled out form in place
// optionally, switch form to manual location choice
return SizedBox(
width: MediaQuery.of(context).size.width,
child: const Padding(
padding: EdgeInsets.only(
left: 16, right: 16, bottom: 32, top: 8),
child: Text(
'Could not determine GPS location, please try again.')));
}

// TODO: What to do on success?
// Navigator.pop(context);

return MyForm(
circles: state.circles,
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/settings/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:workmanager/workmanager.dart';

part 'cubit.g.dart';
part 'state.dart';
Expand All @@ -14,7 +13,6 @@ class SettingsCubit extends Cubit<SettingsState> {
: super(const SettingsState(
message: '',
status: SettingsStatus.initial,
backgroundPermission: BackgroundRefreshPermissionState.unknown,
darkMode: false,
autoAddressResolution: true,
mapProvider: 'mapbox'));
Expand Down
12 changes: 0 additions & 12 deletions lib/ui/settings/cubit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions lib/ui/settings/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:workmanager/workmanager.dart';

import '../../veilid_processor/views/signal_strength_meter.dart';
import 'cubit.dart';
import 'licenses/page.dart';

// TODO: Move to cubit?
Future<Widget> _backgroundPermissionStatus() async {
final hasPermission = await Workmanager().checkBackgroundRefreshPermission();
if (hasPermission != BackgroundRefreshPermissionState.available) {
return Text('Background app refresh is disabled, please enable in '
'App settings. Status ${hasPermission.name}');
}
return const Text('Background app refresh is enabled :)');
}

class SettingsPage extends StatelessWidget {
const SettingsPage({super.key});

Expand Down
14 changes: 3 additions & 11 deletions lib/ui/settings/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ extension SettingsStatusX on SettingsStatus {
@JsonSerializable()
final class SettingsState extends Equatable {
const SettingsState(
{required this.backgroundPermission,
required this.darkMode,
{required this.darkMode,
required this.mapProvider,
required this.autoAddressResolution,
required this.status,
Expand All @@ -27,20 +26,13 @@ final class SettingsState extends Equatable {

final SettingsStatus status;
final String message;
final BackgroundRefreshPermissionState backgroundPermission;
final bool darkMode;
final String mapProvider;
final bool autoAddressResolution;

Map<String, dynamic> toJson() => _$SettingsStateToJson(this);

@override
List<Object?> get props => [
status,
message,
backgroundPermission,
darkMode,
mapProvider,
autoAddressResolution
];
List<Object?> get props =>
[status, message, darkMode, mapProvider, autoAddressResolution];
}
20 changes: 7 additions & 13 deletions lib/veilid_processor/repository/processor_repository.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:rxdart/subjects.dart';
import 'package:veilid_support/veilid_support.dart';

import '../../tools/tools.dart';
Expand All @@ -10,14 +9,14 @@ import '../models/models.dart';
class ProcessorRepository {
ProcessorRepository._()
: startedUp = false,
_updateValueChangeStreamController =
BehaviorSubject<VeilidUpdateValueChange>(),
_controllerConnectionState = StreamController.broadcast(sync: true),
processorConnectionState = ProcessorConnectionState(
attachment: const VeilidStateAttachment(
attachment: VeilidStateAttachment(
state: AttachmentState.detached,
publicInternetReady: false,
localNetworkReady: false),
localNetworkReady: false,
uptime: TimestampDuration(value: BigInt.zero),
attachedUptime: null),
network: VeilidStateNetwork(
started: false,
bpsDown: BigInt.zero,
Expand Down Expand Up @@ -89,9 +88,6 @@ class ProcessorRepository {
startedUp = false;
}

Stream<VeilidUpdateValueChange> streamUpdateValueChange() =>
_updateValueChangeStreamController.asBroadcastStream();

Stream<ProcessorConnectionState> streamProcessorConnectionState() =>
_controllerConnectionState.stream;

Expand All @@ -101,7 +97,9 @@ class ProcessorRepository {
attachment: VeilidStateAttachment(
state: updateAttachment.state,
publicInternetReady: updateAttachment.publicInternetReady,
localNetworkReady: updateAttachment.localNetworkReady));
localNetworkReady: updateAttachment.localNetworkReady,
uptime: updateAttachment.uptime,
attachedUptime: updateAttachment.attachedUptime));
}

void processUpdateConfig(VeilidUpdateConfig updateConfig) {
Expand All @@ -128,16 +126,12 @@ class ProcessorRepository {

// Send value updates to DHTRecordPool
DHTRecordPool.instance.processRemoteValueChange(updateValueChange);
_updateValueChangeStreamController.add(updateValueChange);
}

////////////////////////////////////////////
StreamSubscription<VeilidUpdate>? _updateSubscription;
final StreamController<ProcessorConnectionState> _controllerConnectionState;

final BehaviorSubject<VeilidUpdateValueChange>
_updateValueChangeStreamController;
bool startedUp;
ProcessorConnectionState processorConnectionState;
}
2 changes: 2 additions & 0 deletions packages/veilid_support/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
Expand Down
4 changes: 2 additions & 2 deletions packages/veilid_support/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
veilid: a54f57b7bcf0e4e072fe99272d76ca126b2026d0
veilid: c92b8b9b51c81b0b13118bf8369fb3b8a1b434cf

PODFILE CHECKSUM: 16208599a12443d53889ba2270a4985981cfb204

COCOAPODS: 1.15.2
COCOAPODS: 1.15.0
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Cocoa
import FlutterMacOS

@NSApplicationMain
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
}
Loading

0 comments on commit 9cabf87

Please sign in to comment.