Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Jun 20, 2023
2 parents 191e9f8 + fb48c99 commit aeb92b7
Show file tree
Hide file tree
Showing 50 changed files with 735 additions and 703 deletions.
59 changes: 47 additions & 12 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:async';
import 'dart:io' as io;
import 'dart:ui';

import 'package:collection/collection.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/foundation.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
Expand All @@ -11,31 +14,37 @@ import 'package:ouisync_plugin/ouisync_plugin.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

import '../flavors.dart';
import '../generated/l10n.dart';
import 'cubits/cubits.dart';
import 'pages/pages.dart';
import 'utils/loggers/ouisync_app_logger.dart';
import 'utils/platform/platform.dart';
import 'utils/utils.dart';

Future<Widget> initOuiSyncApp(Color? themePrimaryColor) async {
final windowManager = PlatformWindowManager();
Future<Widget> initOuiSyncApp() async {
// When dumping log from logcat, we get logs from past ouisync runs as well,
// so add a line on each start of the app to know which part of the log
// belongs to the last app instance.
print("-------------------- OuiSync (${F.name}) Start --------------------");

Loggy.initLoggy();
final windowManager = PlatformWindowManager();

final appDir = await getApplicationSupportDirectory();
final configPath = p.join(appDir.path, Constants.configDirName);
final logPath = await LogUtils.path;

if (kDebugMode) {
print('app dir: ${appDir.path}');
print('log dir: ${io.File(logPath).parent.path}');
}

final session = Session.create(
configPath: configPath,
logPath: logPath,
);

Loggy.initLoggy(logPrinter: AppLogPrinter());

_setupErrorReporting();

logDebug('app dir: ${appDir.path}');
logDebug('log dir: ${io.File(logPath).parent.path}');

await session.initNetwork(
defaultPortForwardingEnabled: true,
defaultLocalDiscoveryEnabled: true,
Expand All @@ -47,7 +56,7 @@ Future<Widget> initOuiSyncApp(Color? themePrimaryColor) async {

return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(appBarTheme: AppBarTheme(color: themePrimaryColor)),
theme: ThemeData(appBarTheme: AppBarTheme(color: F.color)),
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
Expand Down Expand Up @@ -78,7 +87,7 @@ class OuiSyncApp extends StatefulWidget {
State<OuiSyncApp> createState() => _OuiSyncAppState();
}

class _OuiSyncAppState extends State<OuiSyncApp> with OuiSyncAppLogger {
class _OuiSyncAppState extends State<OuiSyncApp> with AppLogger {
final _mediaReceiver = MediaReceiver();
final _backgroundManager = PlatformBackgroundManager();

Expand Down Expand Up @@ -140,3 +149,29 @@ class _OuiSyncAppState extends State<OuiSyncApp> with OuiSyncAppLogger {
);
}
}

void _setupErrorReporting() {
// Errors from flutter
FlutterError.onError = (details) {
// Invoke the default handler
FlutterError.presentError(details);

_onError(details);
};

// Errors from outside of flutter
PlatformDispatcher.instance.onError = (exception, stack) {
_onError(FlutterErrorDetails(exception: exception, stack: stack));

// Invoke the default handler
return false;
};
}

void _onError(FlutterErrorDetails details) {
logError("Unhandled Exception:", details.exception, details.stack);

if (Firebase.apps.isNotEmpty) {
unawaited(FirebaseCrashlytics.instance.recordFlutterFatalError(details));
}
}
6 changes: 4 additions & 2 deletions lib/app/cubits/nat_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dns_client/dns_client.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class NatDetection extends Cubit<NatDetectionType> {
import '../utils/log.dart';

class NatDetection extends Cubit<NatDetectionType> with AppLogger {
int _nextTask = 1;
int _highestRunningTask = 0;
final DnsClient _dns = DnsOverHttps.google();
Expand Down Expand Up @@ -63,7 +65,7 @@ class NatDetection extends Cubit<NatDetectionType> {

return;
} catch (e) {
print("Failed to get endpoint echo: $e");
loggy.error("Failed to get endpoint echo:", e);
_emit(currentTask, _NatDetectionTypeError("$e"));
} finally {
socket?.close();
Expand Down
4 changes: 2 additions & 2 deletions lib/app/cubits/power_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:ouisync_plugin/ouisync_plugin.dart' as oui;
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../generated/l10n.dart';
import '../utils/hotspot.dart';
import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/log.dart';
import '../utils/settings.dart';

const _unspecifiedV4 = "0.0.0.0:0";
Expand Down Expand Up @@ -76,7 +76,7 @@ class PowerControlState {
}
}

class PowerControl extends Cubit<PowerControlState> with OuiSyncAppLogger {
class PowerControl extends Cubit<PowerControlState> with AppLogger {
final oui.Session _session;
final Settings _settings;
final Connectivity _connectivity = Connectivity();
Expand Down
3 changes: 1 addition & 2 deletions lib/app/cubits/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:ouisync_plugin/state_monitor.dart';

import '../../generated/l10n.dart';
import '../models/models.dart';
import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/utils.dart';

class RepoState extends Equatable {
Expand Down Expand Up @@ -88,7 +87,7 @@ class RepoState extends Equatable {
bool get canWrite => accessMode == oui.AccessMode.write;
}

class RepoCubit extends Cubit<RepoState> with OuiSyncAppLogger {
class RepoCubit extends Cubit<RepoState> with AppLogger {
final Folder _currentFolder = Folder();
final SettingsRepoEntry _settingsRepoEntry;
final oui.Repository _handle;
Expand Down
7 changes: 3 additions & 4 deletions lib/app/cubits/repos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import 'package:path/path.dart' as p;

import '../../generated/l10n.dart';
import '../models/models.dart';
import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/utils.dart';
import 'cubits.dart';

// List of available storage servers.
// TODO: This should be configurable
const _storageServers = ["storage.ouisync.net"];

class ReposCubit extends WatchSelf<ReposCubit> with OuiSyncAppLogger {
class ReposCubit extends WatchSelf<ReposCubit> with AppLogger {
final SplayTreeMap<String, RepoEntry> _repos =
SplayTreeMap<String, RepoEntry>((key1, key2) => key1.compareTo(key2));
bool _isLoading = false;
Expand Down Expand Up @@ -344,12 +343,12 @@ class ReposCubit extends WatchSelf<ReposCubit> with OuiSyncAppLogger {
Future<void> renameRepository(
String oldName, String newName, Uint8List reopenToken) async {
if (!_repos.containsKey(oldName)) {
print("Error renaming repository \"$oldName\": Does not exist");
loggy.error("Error renaming repository \"$oldName\": Does not exist");
return;
}

if (_repos.containsKey(newName)) {
print(
loggy.error(
"Error renaming repository \"$oldName\": Repository \"$newName\" already exists");
return;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/app/cubits/security.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ouisync_plugin/ouisync_plugin.dart';

import '../../generated/l10n.dart';
import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/utils.dart';
import '../widgets/inputs/password_validation_input.dart';
import 'cubits.dart';
Expand Down Expand Up @@ -55,7 +54,7 @@ class SecurityState extends Equatable {
[isBiometricsAvailable, authMode, password, previewPassword, message];
}

class SecurityCubit extends Cubit<SecurityState> with OuiSyncAppLogger {
class SecurityCubit extends Cubit<SecurityState> with AppLogger {
SecurityCubit._(this._repoCubit, this._shareToken, SecurityState state)
: super(state);

Expand Down
4 changes: 2 additions & 2 deletions lib/app/cubits/sort_list.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/log.dart';

class SortListState extends Equatable {
final SortBy sortBy;
Expand All @@ -24,7 +24,7 @@ class SortListState extends Equatable {
List<Object?> get props => [sortBy, direction, listType];
}

class SortListCubit extends Cubit<SortListState> with OuiSyncAppLogger {
class SortListCubit extends Cubit<SortListState> with AppLogger {
SortListCubit._(SortListState state) : super(state);

static SortListCubit create(
Expand Down
4 changes: 2 additions & 2 deletions lib/app/cubits/upgrade_exists.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter_bloc/flutter_bloc.dart';

import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/log.dart';
import '../utils/settings.dart';

class UpgradeExistsCubit extends Cubit<bool> with OuiSyncAppLogger {
class UpgradeExistsCubit extends Cubit<bool> with AppLogger {
final Future<int> _currentProtocolVersion;
final Settings _settings;

Expand Down
14 changes: 8 additions & 6 deletions lib/app/mixins/repo_actions_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '../widgets/widgets.dart';

typedef CheckForBiometricsFunction = Future<bool?> Function();

mixin RepositoryActionsMixin {
mixin RepositoryActionsMixin on AppLogger {
/// rename => ReposCubit.renameRepository
Future<void> renameRepository(BuildContext context,
{required RepoCubit repository,
Expand Down Expand Up @@ -328,13 +328,15 @@ mixin RepositoryActionsMixin {
databaseId: databaseId, password: securedPassword);

if (upgraded == null) {
print('Upgrading repo $repositoryName to AUTH_MODE version2 failed.');
loggy.error(
'Upgrading repo $repositoryName to AUTH_MODE version2 failed.');

return;
}

if (upgraded == false) {
print('Removing the old entry (version1) for $repositoryName in the '
loggy.warning(
'Removing the old entry (version1) for $repositoryName in the '
'secure storage failed, but the creating the new entry (version2) '
'was successful.');
}
Expand Down Expand Up @@ -436,7 +438,7 @@ mixin RepositoryActionsMixin {
databaseId: databaseId, authMode: authMode);

if (secureStorageResult.exception != null) {
print(secureStorageResult.exception);
loggy.error(secureStorageResult.exception);

return null;
}
Expand All @@ -452,7 +454,7 @@ mixin RepositoryActionsMixin {
authMode: AuthMode.version2);

if (addTempResult.exception != null) {
print(addTempResult.exception);
loggy.error(addTempResult.exception);

return null;
}
Expand All @@ -463,7 +465,7 @@ mixin RepositoryActionsMixin {
authenticationRequired: false);

if (deleteOldResult.exception != null) {
print(deleteOldResult.exception);
loggy.error(deleteOldResult.exception);

return false;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/app/pages/add_repository_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:permission_handler/permission_handler.dart';

import '../../generated/l10n.dart';
import '../cubits/cubits.dart';
import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/platform/platform.dart';
import '../utils/utils.dart';
import 'pages.dart';
Expand All @@ -18,8 +17,7 @@ class AddRepositoryPage extends StatefulWidget {
State<AddRepositoryPage> createState() => _AddRepositoryPageState();
}

class _AddRepositoryPageState extends State<AddRepositoryPage>
with OuiSyncAppLogger {
class _AddRepositoryPageState extends State<AddRepositoryPage> with AppLogger {
final formKey = GlobalKey<FormState>();

final _tokenController = TextEditingController(text: '');
Expand Down Expand Up @@ -64,7 +62,8 @@ class _AddRepositoryPageState extends State<AddRepositoryPage>
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Row(children: [
Fields.constrainedText(S.current.messageAddRepoQR, flex: 0, color: Colors.black)
Fields.constrainedText(S.current.messageAddRepoQR,
flex: 0, color: Colors.black)
]),
if (_isDesktop)
Row(children: [
Expand Down Expand Up @@ -156,7 +155,8 @@ class _AddRepositoryPageState extends State<AddRepositoryPage>
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Fields.constrainedText(S.current.messageAddRepoLink, flex: 0, color: Colors.black),
Fields.constrainedText(S.current.messageAddRepoLink,
flex: 0, color: Colors.black),
],
),
Dimensions.spacingVerticalDouble,
Expand Down
8 changes: 4 additions & 4 deletions lib/app/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import '../cubits/cubits.dart';
import '../mixins/mixins.dart';
import '../models/models.dart';
import '../utils/click_counter.dart';
import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/platform/platform.dart';
import '../utils/utils.dart';
import '../widgets/repository_progress.dart';
Expand All @@ -42,7 +41,7 @@ class MainPage extends StatefulWidget {
}

class _MainPageState extends State<MainPage>
with TickerProviderStateMixin, RepositoryActionsMixin, OuiSyncAppLogger {
with TickerProviderStateMixin, AppLogger, RepositoryActionsMixin {
final ReposCubit _repositories;
final PowerControl _powerControl;

Expand Down Expand Up @@ -163,13 +162,14 @@ class _MainPageState extends State<MainPage>

Future<void> mountFileSystem() async {
if (!io.Platform.isWindows) {
loggy.app('File System mounting is currently supported only on Windows OS');
loggy.app(
'File System mounting is currently supported only on Windows OS');
return;
}

try {
await widget.session.mountAllRepositories("O:");
} on Error catch(error) {
} on Error catch (error) {
loggy.app("Failed to mount repositories ${error.code}: ${error.message}");
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/app/pages/repository_security_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import '../../generated/l10n.dart';
import '../cubits/repo.dart';
import '../cubits/security.dart';
import '../mixins/repo_actions_mixin.dart';
import '../utils/loggers/ouisync_app_logger.dart';
import '../utils/utils.dart';
import '../widgets/widgets.dart';

Expand All @@ -31,7 +30,7 @@ class RepositorySecurity extends StatefulWidget {
}

class _RepositorySecurityState extends State<RepositorySecurity>
with RepositoryActionsMixin, OuiSyncAppLogger {
with AppLogger, RepositoryActionsMixin {
final _passwordInputKey = GlobalKey<FormFieldState>();
final _retypePasswordInputKey = GlobalKey<FormFieldState>();

Expand Down
Loading

0 comments on commit aeb92b7

Please sign in to comment.