Files
FlClash/lib/common/launch.dart
T
chen08209 1e97716636 feat(platform): move desktop windows to plugins/window and rework the tray
plugins/window replaces the window_manager fork on every desktop.

Changelog: Tray hotkeys, node delays and a delay test
2026-09-30 11:39:58 +08:00

51 lines
1.0 KiB
Dart

import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
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);
}
factory AutoLaunch() {
_instance ??= AutoLaunch._internal();
return _instance!;
}
@visibleForTesting
static LaunchAtStartup launcher = launchAtStartup;
Future<bool> get isEnable async {
return launcher.isEnabled();
}
Future<bool> enable() async {
return launcher.enable();
}
Future<bool> disable() async {
return launcher.disable();
}
Future<void> updateStatus(bool isAutoLaunch) async {
if (kDebugMode) {
return;
}
if (await isEnable == isAutoLaunch) return;
if (isAutoLaunch == true) {
unawaited(enable());
} else {
unawaited(disable());
}
}
}
final autoLaunch = system.isDesktop && !safeModeBuild ? AutoLaunch() : null;