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() {
|
2026-09-05 20:09:39 +08:00
|
|
|
launcher.setup(appName: appName, appPath: Platform.resolvedExecutable);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
factory AutoLaunch() {
|
|
|
|
|
_instance ??= AutoLaunch._internal();
|
|
|
|
|
return _instance!;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
@visibleForTesting
|
|
|
|
|
static LaunchAtStartup launcher = launchAtStartup;
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
Future<bool> get isEnable async {
|
2026-09-05 20:09:39 +08:00
|
|
|
return launcher.isEnabled();
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> enable() async {
|
2026-09-05 20:09:39 +08:00
|
|
|
return launcher.enable();
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> disable() async {
|
2026-09-05 20:09:39 +08:00
|
|
|
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) {
|
2026-09-05 20:09:39 +08:00
|
|
|
unawaited(enable());
|
2024-04-30 23:38:49 +08:00
|
|
|
} else {
|
2026-09-05 20:09:39 +08:00
|
|
|
unawaited(disable());
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-25 03:56:56 +08:00
|
|
|
final autoLaunch = system.isDesktop && !safeModeBuild ? AutoLaunch() : null;
|