import 'dart:io'; import 'dart:async'; import 'package:path/path.dart'; import 'package:dart_framework/core/process.dart'; class OSStartup { static final String windowsStartupPath = '\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\'; static Future isRegistedStartup(String label) async { var c = Completer(); var exist = false; if (Platform.isMacOS) { } else if (Platform.isWindows) { //For Windows 8, 10 var userPath = Platform.environment['UserProfile']; exist = File('$userPath$windowsStartupPath$label').existsSync(); } else if (Platform.isLinux) {} c.complete(exist); return c.future; } static Future registStartup(String executableFilePath, {String? label}) async { var c = Completer(); var file = File(executableFilePath); var fileName = basename(file.path); var targetName = label ?? fileName; ProcessResult? result; if (Platform.isMacOS) { } else if (Platform.isWindows) { //For Windows 8, 10 var symbolicPath = '%userprofile%$windowsStartupPath$targetName'; result = await ProcessExecutor.run( StringBuffer('mklink "$symbolicPath" "$executableFilePath"')); } else if (Platform.isLinux) {} c.complete(result == null ? false : result.exitCode == 0); return c.future; } static Future unregistStartup(String label) async { var c = Completer(); var success = false; if (Platform.isMacOS) { } else if (Platform.isWindows) { //For Windows 8, 10 var userPath = Platform.environment['UserProfile']; var file = File('$userPath$windowsStartupPath$label'); if (file.existsSync()) { await file.delete(); success = true; } } else if (Platform.isLinux) {} c.complete(success); return c.future; } }