Files
MWClash/lib/common/launch.dart

47 lines
931 B
Dart
Raw Normal View History

2024-04-30 23:38:49 +08:00
import 'dart:async';
import 'dart:io';
import 'package:launch_at_startup/launch_at_startup.dart';
import 'constant.dart';
import 'system.dart';
class AutoLaunch {
static AutoLaunch? _instance;
AutoLaunch._internal() {
launchAtStartup.setup(
appName: appName,
2024-04-30 23:38:49 +08:00
appPath: Platform.resolvedExecutable,
);
}
factory AutoLaunch() {
_instance ??= AutoLaunch._internal();
return _instance!;
}
Future<bool> get isEnable async {
return await launchAtStartup.isEnabled();
}
Future<bool> enable() async {
return await launchAtStartup.enable();
}
Future<bool> disable() async {
return await launchAtStartup.disable();
}
updateStatus(bool value) async {
final isEnable = await this.isEnable;
if (isEnable == value) return;
if (value == true) {
enable();
} else {
disable();
}
}
}
final autoLaunch = system.isDesktop ? AutoLaunch() : null;