58 lines
1.8 KiB
Dart
58 lines
1.8 KiB
Dart
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<bool> isRegistedStartup(String label) async {
|
|
var c = Completer<bool>();
|
|
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<bool> registStartup(String executableFilePath,
|
|
{String? label}) async {
|
|
var c = Completer<bool>();
|
|
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<bool> unregistStartup(String label) async {
|
|
var c = Completer<bool>();
|
|
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;
|
|
}
|
|
}
|