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() {
|
|
|
|
|
launchAtStartup.setup(
|
2024-05-20 15:15:09 +08:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 01:40:39 +08:00
|
|
|
updateStatus(bool isAutoLaunch) async {
|
2025-04-09 16:46:14 +08:00
|
|
|
if(kDebugMode){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-23 18:33:40 +08:00
|
|
|
if (await isEnable == isAutoLaunch) return;
|
|
|
|
|
if (isAutoLaunch == true) {
|
2024-04-30 23:38:49 +08:00
|
|
|
enable();
|
|
|
|
|
} else {
|
|
|
|
|
disable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final autoLaunch = system.isDesktop ? AutoLaunch() : null;
|