Fix bootstrap bug

This commit is contained in:
problematicconsumer
2023-11-12 21:55:17 +03:30
parent 344f4f706f
commit 577bb3ded3
4 changed files with 29 additions and 32 deletions

View File

@@ -94,13 +94,32 @@ Future<void> _lazyBootstrap(
if (silentStart) {
FlutterNativeSplash.remove();
}
if (PlatformUtils.isDesktop) {
_logger.debug("initializing [Auto Start Service] and [Window Controller]");
await container.read(autoStartServiceProvider.future);
await container.read(windowControllerProvider.future);
}
await initAppServices(container.read);
await initControllers(container.read);
await container.read(singboxServiceProvider).init();
_logger.debug("initialized [Singbox Service]");
await container.read(activeProfileProvider.future);
await container.read(deepLinkServiceProvider.future);
if (PlatformUtils.isDesktop) {
try {
await container
.read(systemTrayControllerProvider.future)
.timeout(const Duration(seconds: 1));
_logger.debug("initialized [System Tray Controller]");
} catch (error, stackTrace) {
_logger.warning(
"error initializing [System Tray Controller]",
error,
stackTrace,
);
}
}
runApp(
ProviderScope(
@@ -130,29 +149,3 @@ void initLoggers(
logOptions: LogOptions(logLevel),
);
}
Future<void> initAppServices(
Result Function<Result>(ProviderListenable<Result>) read,
) async {
_logger.debug("initializing app services");
await Future.wait(
[
read(singboxServiceProvider).init(),
],
);
_logger.debug('initialized app services');
}
Future<void> initControllers(
Result Function<Result>(ProviderListenable<Result>) read,
) async {
_logger.debug("initializing controllers");
await Future.wait(
[
read(activeProfileProvider.future),
read(deepLinkServiceProvider.future),
if (PlatformUtils.isDesktop) read(systemTrayControllerProvider.future),
],
);
_logger.debug("initialized base controllers");
}

View File

@@ -90,8 +90,9 @@ class ConnectivityController extends _$ConnectivityController with AppLogger {
final activeProfile = await ref.read(activeProfileProvider.future);
await _core
.start(activeProfile!.id, ref.read(disableMemoryLimitProvider))
.mapLeft((err) {
loggy.warning("error connecting $err", err);
.mapLeft((err) async {
loggy.warning("error connecting", err);
await ref.read(startedByUserProvider.notifier).update(false);
state = AsyncError(err, StackTrace.current);
}).run();
}

View File

@@ -31,7 +31,7 @@ class WindowController extends _$WindowController
await windowManager.hide();
}
await Future.delayed(
const Duration(seconds: 1),
const Duration(seconds: 3),
() async {
if (ref.read(startedByUserProvider)) {
loggy.debug("previously started by user, trying to connect");

View File

@@ -30,7 +30,10 @@ class SystemTrayController extends _$SystemTrayController
_initialized = true;
}
final connection = await ref.watch(connectivityControllerProvider.future);
final connection = switch (ref.watch(connectivityControllerProvider)) {
AsyncData(:final value) => value,
_ => const Disconnected(),
};
final serviceMode = ref.watch(serviceModeStoreProvider);
final t = ref.watch(translationsProvider);