Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Pabon committed Nov 5, 2024
2 parents e61505d + a88a5ce commit d159a69
Show file tree
Hide file tree
Showing 33 changed files with 260 additions and 202 deletions.
20 changes: 11 additions & 9 deletions lib/app/cubits/connectivity_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:network_info_plus/network_info_plus.dart';
import 'package:ouisync/ouisync.dart';

import '../utils/log.dart';
import '../utils/utils.dart' show AppLogger;
import 'cubits.dart' show CubitActions;

class ConnectivityInfoState extends Equatable {
final String tcpListenerV4;
Expand Down Expand Up @@ -71,7 +72,8 @@ class ConnectivityInfoState extends Equatable {
"externalAddressV6: $externalAddressV6)";
}

class ConnectivityInfo extends Cubit<ConnectivityInfoState> with AppLogger {
class ConnectivityInfo extends Cubit<ConnectivityInfoState>
with AppLogger, CubitActions {
final Session _session;
final _networkInfo = NetworkInfo();

Expand All @@ -89,7 +91,7 @@ class ConnectivityInfo extends Cubit<ConnectivityInfoState> with AppLogger {
return;
}

emit(state.copyWith(
emitUnlessClosed(state.copyWith(
tcpListenerV4: tcpListenerV4 ?? '',
tcpListenerV6: tcpListenerV6 ?? '',
quicListenerV4: quicListenerV4 ?? '',
Expand All @@ -104,9 +106,9 @@ class ConnectivityInfo extends Cubit<ConnectivityInfoState> with AppLogger {

if (localIPv4 != null) {
final port = _extractPort(quicListenerV4 ?? tcpListenerV4 ?? '');
emit(state.copyWith(localAddressV4: "$localIPv4:$port"));
emitUnlessClosed(state.copyWith(localAddressV4: "$localIPv4:$port"));
} else {
emit(state.copyWith(localAddressV4: ""));
emitUnlessClosed(state.copyWith(localAddressV4: ""));
}

final localIPv6 = await _networkInfo.getWifiIPv6();
Expand All @@ -117,9 +119,9 @@ class ConnectivityInfo extends Cubit<ConnectivityInfoState> with AppLogger {

if (localIPv6 != null) {
final port = _extractPort(quicListenerV6 ?? tcpListenerV6 ?? '');
emit(state.copyWith(localAddressV6: "[$localIPv6]:$port"));
emitUnlessClosed(state.copyWith(localAddressV6: "[$localIPv6]:$port"));
} else {
emit(state.copyWith(localAddressV6: ""));
emitUnlessClosed(state.copyWith(localAddressV6: ""));
}

final externalAddressV4 = await _session.externalAddressV4 ?? "";
Expand All @@ -128,15 +130,15 @@ class ConnectivityInfo extends Cubit<ConnectivityInfoState> with AppLogger {
return;
}

emit(state.copyWith(externalAddressV4: externalAddressV4));
emitUnlessClosed(state.copyWith(externalAddressV4: externalAddressV4));

final externalAddressV6 = await _session.externalAddressV6 ?? "";

if (isClosed) {
return;
}

emit(state.copyWith(externalAddressV6: externalAddressV6));
emitUnlessClosed(state.copyWith(externalAddressV6: externalAddressV6));
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/app/cubits/cubits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export 'repos.dart';
export 'sort_list.dart';
export 'state_monitor.dart';
export 'upgrade_exists.dart';
export 'utils.dart';
export 'value.dart';
export 'watch.dart';
12 changes: 6 additions & 6 deletions lib/app/cubits/entry_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ouisync/bindings.dart';

import '../utils/log.dart';
import 'cubits.dart';
import '../utils/utils.dart' show AppLogger;
import 'cubits.dart' show CubitActions, NavigationCubit, RepoCubit, ReposCubit;

enum BottomSheetType { move, upload, gone }

Expand Down Expand Up @@ -73,7 +73,7 @@ class SaveMediaSheetState extends Equatable implements EntryBottomSheetState {
class HideSheetState implements EntryBottomSheetState {}

class EntryBottomSheetCubit extends Cubit<EntryBottomSheetState>
with AppLogger {
with AppLogger, CubitActions {
EntryBottomSheetCubit() : super(HideSheetState());

void showMoveEntry({
Expand All @@ -82,7 +82,7 @@ class EntryBottomSheetCubit extends Cubit<EntryBottomSheetState>
required String entryPath,
required EntryType entryType,
}) =>
emit(
emitUnlessClosed(
MoveEntrySheetState(
repoCubit: repoCubit,
navigationCubit: navigationCubit,
Expand All @@ -93,12 +93,12 @@ class EntryBottomSheetCubit extends Cubit<EntryBottomSheetState>

void showSaveMedia(
{required ReposCubit reposCubit, required List<String> paths}) =>
emit(
emitUnlessClosed(
SaveMediaSheetState(
reposCubit: reposCubit,
sharedMediaPaths: paths,
),
);

void hide() => emit(HideSheetState());
void hide() => emitUnlessClosed(HideSheetState());
}
6 changes: 3 additions & 3 deletions lib/app/cubits/file_progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:stream_transform/stream_transform.dart';

import 'repo.dart';
import 'cubits.dart' show CubitActions, RepoCubit;

/// Cubit representing sync progress of a file.
class FileProgress extends Cubit<int?> {
class FileProgress extends Cubit<int?> with CubitActions {
FileProgress(RepoCubit repo, this.path) : super(null) {
_subscription =
repo.events.startWith(null).asyncMapSample((_) => _fetch(repo)).listen(
emit,
emitUnlessClosed,
onError: (e, st) {}, // these errors are not important - ignore
);
}
Expand Down
8 changes: 5 additions & 3 deletions lib/app/cubits/job.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter_bloc/flutter_bloc.dart';

import 'cubits.dart' show CubitActions;

class JobState {
int soFar;
int total;
Expand All @@ -14,14 +16,14 @@ class JobState {
);
}

class Job extends Cubit<JobState> {
class Job extends Cubit<JobState> with CubitActions {
Job(int soFar, int total) : super(JobState(soFar: soFar, total: total));

void update(int soFar) {
emit(state.copyWith(soFar: soFar));
emitUnlessClosed(state.copyWith(soFar: soFar));
}

void cancel() {
emit(state.copyWith(cancel: true));
emitUnlessClosed(state.copyWith(cancel: true));
}
}
11 changes: 7 additions & 4 deletions lib/app/cubits/navigation.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import '../models/repo_location.dart';
import '../utils/utils.dart';

import '../models/models.dart' show RepoLocation;
import '../utils/utils.dart' show AppLogger;
import 'cubits.dart' show CubitActions;

class NavigationState {
final RepoLocation? repoLocation;
Expand All @@ -14,7 +16,8 @@ class NavigationState {
});
}

class NavigationCubit extends Cubit<NavigationState> with AppLogger {
class NavigationCubit extends Cubit<NavigationState>
with AppLogger, CubitActions {
NavigationCubit()
: super(NavigationState(
repoLocation: null,
Expand All @@ -23,7 +26,7 @@ class NavigationCubit extends Cubit<NavigationState> with AppLogger {
));

void current(RepoLocation repoLocation, String path, bool isFolder) =>
emit(NavigationState(
emitUnlessClosed(NavigationState(
repoLocation: repoLocation,
path: path,
isFolder: isFolder,
Expand Down
11 changes: 6 additions & 5 deletions lib/app/cubits/power_control.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ouisync/ouisync.dart' as oui;
import 'package:equatable/equatable.dart';

import '../../generated/l10n.dart';
import '../utils/utils.dart';
import 'utils.dart';
import '../utils/utils.dart'
show AppLogger, LocalInterfaceAddr, LocalInterfaceWatch, AppLoggy, Settings;
import '../utils/watch.dart' as watch;
import 'cubits.dart' show CubitActions;

const _unspecifiedV4 = "0.0.0.0:0";
const _unspecifiedV6 = "[::]:0";
Expand Down Expand Up @@ -105,7 +106,7 @@ class PowerControlState {
}

class PowerControl extends Cubit<PowerControlState>
with CubitActions, AppLogger {
with AppLogger, CubitActions {
final oui.Session _session;
final Settings _settings;
final Connectivity _connectivity;
Expand Down Expand Up @@ -171,7 +172,7 @@ class PowerControl extends Cubit<PowerControlState>
return;
}

emit(state.copyWith(userWantsPortForwardingEnabled: value));
emitUnlessClosed(state.copyWith(userWantsPortForwardingEnabled: value));

await _session.setPortForwardingEnabled(value);
}
Expand Down
35 changes: 21 additions & 14 deletions lib/app/cubits/repo_creation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ouisync/ouisync.dart' show AccessMode, ShareToken;

import '../../generated/l10n.dart';
import '../models/auth_mode.dart';
import '../models/local_secret.dart';
import '../models/repo_entry.dart';
import '../models/repo_location.dart';
import '../utils/dialogs.dart';
import '../utils/log.dart';
import '../utils/strings.dart';
import 'repos.dart';
import 'utils.dart';
import '../models/models.dart'
show
ErrorRepoEntry,
LocalSecretKeyAndSalt,
LocalSecretInput,
LocalSecretManual,
LocalSecretMode,
LocalSecretRandom,
LoadingRepoEntry,
MissingRepoEntry,
OpenRepoEntry,
RepoLocation,
SetLocalSecret;
import '../utils/utils.dart' show AppLogger, Dialogs, Strings;
import 'cubits.dart' show CubitActions, ReposCubit;

class RepoCreationState {
static const initialLocalSecretMode = LocalSecretMode.randomStored;
Expand Down Expand Up @@ -159,7 +165,7 @@ class RepoCreationCubit extends Cubit<RepoCreationState>
final useCacheServers =
await reposCubit.cacheServers.isEnabledForShareToken(token);

emit(state.copyWith(
emitUnlessClosed(state.copyWith(
accessMode: accessMode,
suggestedName: suggestedName,
token: token,
Expand All @@ -175,7 +181,7 @@ class RepoCreationCubit extends Cubit<RepoCreationState>
}

void setUseCacheServers(bool value) {
emit(state.copyWith(useCacheServers: value));
emitUnlessClosed(state.copyWith(useCacheServers: value));
}

void setLocalSecret(LocalSecretInput input) {
Expand Down Expand Up @@ -213,7 +219,8 @@ class RepoCreationCubit extends Cubit<RepoCreationState>
),
};

emit(state.copyWith(substate: substate, localSecretMode: input.mode));
emitUnlessClosed(
state.copyWith(substate: substate, localSecretMode: input.mode));
}

Future<void> save() async {
Expand Down Expand Up @@ -245,11 +252,11 @@ class RepoCreationCubit extends Cubit<RepoCreationState>

switch (repoEntry) {
case OpenRepoEntry():
emit(state.copyWith(
emitUnlessClosed(state.copyWith(
substate: RepoCreationSuccess(location: substate.location),
));
case ErrorRepoEntry():
emit(state.copyWith(
emitUnlessClosed(state.copyWith(
substate: RepoCreationFailure(
location: substate.location,
error: repoEntry.error,
Expand Down
38 changes: 25 additions & 13 deletions lib/app/cubits/repo_security.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ import 'dart:async';

import 'package:flutter_bloc/flutter_bloc.dart';

import '../models/auth_mode.dart';
import '../models/local_secret.dart';
import '../utils/local_auth.dart';
import '../utils/log.dart';
import '../utils/master_key.dart';
import '../utils/option.dart';
import '../utils/password_hasher.dart';
import '../models/models.dart'
show
AuthMode,
AuthModeBlindOrManual,
AuthModeKeyStoredOnDevice,
AuthModePasswordStoredOnDevice,
LocalSecret,
LocalSecretKeyAndSalt,
LocalSecretInput,
LocalSecretKey,
LocalSecretManual,
LocalSecretMode,
LocalSecretRandom,
LocalPassword,
SecretKeyOrigin,
SecretKeyStore;
import '../utils/utils.dart'
show AppLogger, LocalAuth, MasterKey, None, Option, PasswordHasher, Some;
import 'repo.dart';
import 'utils.dart';

Expand Down Expand Up @@ -175,19 +186,19 @@ class RepoSecurityCubit extends Cubit<RepoSecurityState>
}

void setOrigin(SecretKeyOrigin value) {
emit(state.copyWith(origin: value));
emitUnlessClosed(state.copyWith(origin: value));
}

void setStore(bool value) {
emit(state.copyWith(userWantsToStoreSecret: value));
emitUnlessClosed(state.copyWith(userWantsToStoreSecret: value));
}

void setSecureWithBiometrics(bool value) {
emit(state.copyWith(secureWithBiometrics: value));
emitUnlessClosed(state.copyWith(secureWithBiometrics: value));
}

void setLocalPassword(String? value) {
emit(state.copyWith(
emitUnlessClosed(state.copyWith(
localPassword: value != null ? Some(LocalPassword(value)) : None(),
));
}
Expand Down Expand Up @@ -221,7 +232,7 @@ class RepoSecurityCubit extends Cubit<RepoSecurityState>
? Some(newLocalSecretInput.password)
: None<LocalPassword>();

emit(state.copyWith(
emitUnlessClosed(state.copyWith(
oldLocalSecretMode: newAuthMode.localSecretMode,
updatedLocalPassword: newLocalPassword,
));
Expand All @@ -244,7 +255,8 @@ class RepoSecurityCubit extends Cubit<RepoSecurityState>
oldSecret: state.oldLocalSecret,
newSecret: newLocalSecret,
);
emit(state.copyWith(oldLocalSecret: newLocalSecret.toLocalSecret()));
emitUnlessClosed(
state.copyWith(oldLocalSecret: newLocalSecret.toLocalSecret()));
loggy.debug('Repo local secret updated');
} catch (e, st) {
loggy.error(
Expand Down
Loading

0 comments on commit d159a69

Please sign in to comment.