Refactor desktop window management and tray
This commit is contained in:
@@ -14,20 +14,19 @@ import 'package:hiddify/core/preferences/general_preferences.dart';
|
||||
import 'package:hiddify/core/preferences/preferences_migration.dart';
|
||||
import 'package:hiddify/core/preferences/preferences_provider.dart';
|
||||
import 'package:hiddify/features/app/widget/app.dart';
|
||||
import 'package:hiddify/features/common/window/window_controller.dart';
|
||||
import 'package:hiddify/features/auto_start/notifier/auto_start_notifier.dart';
|
||||
import 'package:hiddify/features/geo_asset/data/geo_asset_data_providers.dart';
|
||||
import 'package:hiddify/features/log/data/log_data_providers.dart';
|
||||
import 'package:hiddify/features/profile/data/profile_data_providers.dart';
|
||||
import 'package:hiddify/features/profile/notifier/active_profile_notifier.dart';
|
||||
import 'package:hiddify/features/system_tray/system_tray_controller.dart';
|
||||
import 'package:hiddify/services/auto_start_service.dart';
|
||||
import 'package:hiddify/features/system_tray/notifier/system_tray_notifier.dart';
|
||||
import 'package:hiddify/features/window/notifier/window_notifier.dart';
|
||||
import 'package:hiddify/services/deep_link_service.dart';
|
||||
import 'package:hiddify/singbox/service/singbox_service_provider.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:loggy/loggy.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
Future<void> lazyBootstrap(
|
||||
WidgetsBinding widgetsBinding,
|
||||
@@ -42,7 +41,6 @@ Future<void> lazyBootstrap(
|
||||
Logger.logPlatformDispatcherError;
|
||||
|
||||
final stopWatch = Stopwatch()..start();
|
||||
if (PlatformUtils.isDesktop) await windowManager.ensureInitialized();
|
||||
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
@@ -95,6 +93,27 @@ Future<void> lazyBootstrap(
|
||||
|
||||
final debug = container.read(debugModeNotifierProvider) || kDebugMode;
|
||||
|
||||
if (PlatformUtils.isDesktop) {
|
||||
await _init(
|
||||
"window controller",
|
||||
() => container.read(windowNotifierProvider.future),
|
||||
);
|
||||
|
||||
final silentStart = container.read(silentStartNotifierProvider);
|
||||
Logger.bootstrap
|
||||
.debug("silent start [${silentStart ? "Enabled" : "Disabled"}]");
|
||||
if (!silentStart) {
|
||||
await container.read(windowNotifierProvider.notifier).open(focus: false);
|
||||
} else {
|
||||
Logger.bootstrap.debug("silent start, remain hidden accessible via tray");
|
||||
}
|
||||
|
||||
await _init(
|
||||
"auto start service",
|
||||
() => container.read(autoStartNotifierProvider.future),
|
||||
);
|
||||
}
|
||||
|
||||
await _init(
|
||||
"logs repository",
|
||||
() => container.read(logRepositoryProvider.future),
|
||||
@@ -111,24 +130,6 @@ Future<void> lazyBootstrap(
|
||||
() => container.read(profileRepositoryProvider.future),
|
||||
);
|
||||
|
||||
final silentStart = container.read(silentStartNotifierProvider);
|
||||
Logger.bootstrap
|
||||
.debug("silent start [${silentStart ? "Enabled" : "Disabled"}]");
|
||||
if (silentStart) {
|
||||
FlutterNativeSplash.remove();
|
||||
}
|
||||
|
||||
if (PlatformUtils.isDesktop) {
|
||||
await _init(
|
||||
"auto start service",
|
||||
() => container.read(autoStartServiceProvider.future),
|
||||
);
|
||||
await _init(
|
||||
"window controller",
|
||||
() => container.read(windowControllerProvider.future),
|
||||
);
|
||||
}
|
||||
|
||||
await _init(
|
||||
"sing-box",
|
||||
() => container.read(singboxServiceProvider).init(),
|
||||
@@ -146,7 +147,7 @@ Future<void> lazyBootstrap(
|
||||
if (PlatformUtils.isDesktop) {
|
||||
await _safeInit(
|
||||
"system tray",
|
||||
() => container.read(systemTrayControllerProvider.future),
|
||||
() => container.read(systemTrayNotifierProvider.future),
|
||||
timeout: 1000,
|
||||
);
|
||||
}
|
||||
@@ -163,7 +164,7 @@ Future<void> lazyBootstrap(
|
||||
),
|
||||
);
|
||||
|
||||
if (!silentStart) FlutterNativeSplash.remove();
|
||||
FlutterNativeSplash.remove();
|
||||
}
|
||||
|
||||
Future<T> _init<T>(
|
||||
|
||||
Reference in New Issue
Block a user