Files
FlClash/lib/common/launch.dart
T

51 lines
1.0 KiB
Dart
Raw Normal View History

2024-04-30 23:38:49 +08:00
import 'dart:async';
import 'dart:io';
2024-12-03 21:47:12 +08:00
2025-04-09 16:46:14 +08:00
import 'package:flutter/foundation.dart';
2024-04-30 23:38:49 +08:00
import 'package:launch_at_startup/launch_at_startup.dart';
import 'constant.dart';
import 'system.dart';
class AutoLaunch {
static AutoLaunch? _instance;
AutoLaunch._internal() {
launcher.setup(appName: appName, appPath: Platform.resolvedExecutable);
2024-04-30 23:38:49 +08:00
}
factory AutoLaunch() {
_instance ??= AutoLaunch._internal();
return _instance!;
}
@visibleForTesting
static LaunchAtStartup launcher = launchAtStartup;
2024-04-30 23:38:49 +08:00
Future<bool> get isEnable async {
return launcher.isEnabled();
2024-04-30 23:38:49 +08:00
}
Future<bool> enable() async {
return launcher.enable();
2024-04-30 23:38:49 +08:00
}
Future<bool> disable() async {
return launcher.disable();
2024-04-30 23:38:49 +08:00
}
2025-06-07 01:48:34 +08:00
Future<void> updateStatus(bool isAutoLaunch) async {
if (kDebugMode) {
2025-04-09 16:46:14 +08:00
return;
}
2024-08-23 18:33:40 +08:00
if (await isEnable == isAutoLaunch) return;
if (isAutoLaunch == true) {
unawaited(enable());
2024-04-30 23:38:49 +08:00
} else {
unawaited(disable());
2024-04-30 23:38:49 +08:00
}
}
}
final autoLaunch = system.isDesktop && !safeModeBuild ? AutoLaunch() : null;