mirror of
https://github.com/hiddify/hiddify-next.git
synced 2026-06-05 21:05:07 +08:00
"not important" formating text for better understaning changes in next commit
This commit is contained in:
parent
384dc60a0c
commit
71423a576d
@ -30,10 +30,7 @@ import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
Future<void> lazyBootstrap(
|
||||
WidgetsBinding widgetsBinding,
|
||||
Environment env,
|
||||
) async {
|
||||
Future<void> lazyBootstrap(WidgetsBinding widgetsBinding, Environment env) async {
|
||||
if (!kIsWeb) {
|
||||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
||||
}
|
||||
@ -43,48 +40,28 @@ Future<void> lazyBootstrap(
|
||||
|
||||
final stopWatch = Stopwatch()..start();
|
||||
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
environmentProvider.overrideWithValue(env),
|
||||
],
|
||||
);
|
||||
final container = ProviderContainer(overrides: [environmentProvider.overrideWithValue(env)]);
|
||||
|
||||
await _init(
|
||||
"directories",
|
||||
() => container.read(appDirectoriesProvider.future),
|
||||
);
|
||||
await _init("directories", () => container.read(appDirectoriesProvider.future));
|
||||
LoggerController.init(container.read(logPathResolverProvider).appFile().path);
|
||||
|
||||
final appInfo = await _init(
|
||||
"app info",
|
||||
() => container.read(appInfoProvider.future),
|
||||
);
|
||||
await _init(
|
||||
"preferences",
|
||||
() => container.read(sharedPreferencesProvider.future),
|
||||
);
|
||||
final appInfo = await _init("app info", () => container.read(appInfoProvider.future));
|
||||
await _init("preferences", () => container.read(sharedPreferencesProvider.future));
|
||||
|
||||
final enableAnalytics = await container.read(analyticsControllerProvider.future);
|
||||
if (enableAnalytics) {
|
||||
await _init(
|
||||
"analytics",
|
||||
() => container.read(analyticsControllerProvider.notifier).enableAnalytics(),
|
||||
);
|
||||
await _init("analytics", () => container.read(analyticsControllerProvider.notifier).enableAnalytics());
|
||||
}
|
||||
|
||||
await _init(
|
||||
"preferences migration",
|
||||
() async {
|
||||
try {
|
||||
await PreferencesMigration(
|
||||
sharedPreferences: container.read(sharedPreferencesProvider).requireValue,
|
||||
).migrate();
|
||||
} catch (e, stackTrace) {
|
||||
Logger.bootstrap.error("preferences migration failed", e, stackTrace);
|
||||
if (env == Environment.dev) rethrow;
|
||||
Logger.bootstrap.info("clearing preferences");
|
||||
await container.read(sharedPreferencesProvider).requireValue.clear();
|
||||
}
|
||||
await _init("preferences migration", () async {
|
||||
try {
|
||||
await PreferencesMigration(sharedPreferences: container.read(sharedPreferencesProvider).requireValue).migrate();
|
||||
} catch (e, stackTrace) {
|
||||
Logger.bootstrap.error("preferences migration failed", e, stackTrace);
|
||||
if (env == Environment.dev) rethrow;
|
||||
Logger.bootstrap.info("clearing preferences");
|
||||
await container.read(sharedPreferencesProvider).requireValue.clear();
|
||||
}
|
||||
});
|
||||
|
||||
await _init("db migration from v1 to v2", () async {
|
||||
@ -107,10 +84,7 @@ Future<void> lazyBootstrap(
|
||||
final debug = container.read(debugModeNotifierProvider) || kDebugMode;
|
||||
|
||||
if (PlatformUtils.isDesktop) {
|
||||
await _init(
|
||||
"window controller",
|
||||
() => container.read(windowNotifierProvider.future),
|
||||
);
|
||||
await _init("window controller", () => container.read(windowNotifierProvider.future));
|
||||
|
||||
final silentStart = container.read(Preferences.silentStart);
|
||||
Logger.bootstrap.debug("silent start [${silentStart ? "Enabled" : "Disabled"}]");
|
||||
@ -119,38 +93,19 @@ Future<void> lazyBootstrap(
|
||||
} else {
|
||||
Logger.bootstrap.debug("silent start, remain hidden accessible via tray");
|
||||
}
|
||||
await _init(
|
||||
"auto start service",
|
||||
() => container.read(autoStartNotifierProvider.future),
|
||||
);
|
||||
await _init("auto start service", () => container.read(autoStartNotifierProvider.future));
|
||||
}
|
||||
await _init(
|
||||
"logs repository",
|
||||
() => container.read(logRepositoryProvider.future),
|
||||
);
|
||||
await _init("logs repository", () => container.read(logRepositoryProvider.future));
|
||||
await _init("logger controller", () => LoggerController.postInit(debug));
|
||||
|
||||
Logger.bootstrap.info(appInfo.format());
|
||||
|
||||
await _init(
|
||||
"profile repository",
|
||||
() => container.read(profileRepositoryProvider.future),
|
||||
);
|
||||
await _init("profile repository", () => container.read(profileRepositoryProvider.future));
|
||||
|
||||
await _init(
|
||||
"translations",
|
||||
() => container.read(translationsProvider.future),
|
||||
);
|
||||
await _init("translations", () => container.read(translationsProvider.future));
|
||||
|
||||
await _safeInit(
|
||||
"active profile",
|
||||
() => container.read(activeProfileProvider.future),
|
||||
timeout: 1000,
|
||||
);
|
||||
await _init(
|
||||
"sing-box",
|
||||
() => container.read(hiddifyCoreServiceProvider).init(ref: container),
|
||||
);
|
||||
await _safeInit("active profile", () => container.read(activeProfileProvider.future), timeout: 1000);
|
||||
await _init("sing-box", () => container.read(hiddifyCoreServiceProvider).init(ref: container));
|
||||
if (!kIsWeb) {
|
||||
// await _safeInit(
|
||||
// "deep link service",
|
||||
@ -167,12 +122,9 @@ Future<void> lazyBootstrap(
|
||||
// }
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
await _safeInit(
|
||||
"android display mode",
|
||||
() async {
|
||||
await FlutterDisplayMode.setHighRefreshRate();
|
||||
},
|
||||
);
|
||||
await _safeInit("android display mode", () async {
|
||||
await FlutterDisplayMode.setHighRefreshRate();
|
||||
});
|
||||
}
|
||||
}
|
||||
Logger.bootstrap.info("bootstrap took [${stopWatch.elapsedMilliseconds}ms]");
|
||||
@ -181,12 +133,8 @@ Future<void> lazyBootstrap(
|
||||
runApp(
|
||||
ProviderScope(
|
||||
parent: container,
|
||||
observers: [
|
||||
RiverpodObserver(),
|
||||
],
|
||||
child: SentryUserInteractionWidget(
|
||||
child: const App(),
|
||||
),
|
||||
observers: [RiverpodObserver()],
|
||||
child: SentryUserInteractionWidget(child: const App()),
|
||||
),
|
||||
);
|
||||
|
||||
@ -196,11 +144,7 @@ Future<void> lazyBootstrap(
|
||||
SentryFlutter.setAppStartEnd(DateTime.now().toUtc());
|
||||
}
|
||||
|
||||
Future<T> _init<T>(
|
||||
String name,
|
||||
Future<T> Function() initializer, {
|
||||
int? timeout,
|
||||
}) async {
|
||||
Future<T> _init<T>(String name, Future<T> Function() initializer, {int? timeout}) async {
|
||||
final stopWatch = Stopwatch()..start();
|
||||
Logger.bootstrap.info("initializing [$name]");
|
||||
Future<T> func() => timeout != null ? initializer().timeout(Duration(milliseconds: timeout)) : initializer();
|
||||
@ -216,11 +160,7 @@ Future<T> _init<T>(
|
||||
}
|
||||
}
|
||||
|
||||
Future<T?> _safeInit<T>(
|
||||
String name,
|
||||
Future<T> Function() initializer, {
|
||||
int? timeout,
|
||||
}) async {
|
||||
Future<T?> _safeInit<T>(String name, Future<T> Function() initializer, {int? timeout}) async {
|
||||
try {
|
||||
return await _init(name, initializer, timeout: timeout);
|
||||
} catch (e) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user