From 86c7de1d9ab3c67431dac9cc967ff0d96969ea60 Mon Sep 17 00:00:00 2001 From: leedongmyung Date: Sun, 5 Jan 2025 07:11:25 +0900 Subject: [PATCH] update osstartup --- bin/main.dart | 10 +++++----- lib/utils/os_startup.dart | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 5870a52..d343a5a 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -10,14 +10,14 @@ import 'package:dart_framework/charset.dart'; void main() async { Application('dartframework', 'com.toki-labs.dartframework', () async { - // print(await OSStartup.unregistStartup(appIdendifier)); + print(await OSStartup.unregistStartup(appIdendifier)); // print(await OSStartup.isRegistedStartup(appIdendifier)); - print(await OSStartup.registStartup( - Platform.resolvedExecutable, appIdendifier, - logStandardFilePath: '$dataPath\\startup_log.txt', - logErrorFilePath: '$dataPath\\startup_err.txt')); + // print(await OSStartup.registStartup( + // Platform.resolvedExecutable, appIdendifier, + // logStandardFilePath: '$dataPath\\startup_log.txt', + // logErrorFilePath: '$dataPath\\startup_err.txt')); // var md5 = generateMd5('test'); // print('$md5 / ${md5.length}'); diff --git a/lib/utils/os_startup.dart b/lib/utils/os_startup.dart index af0a3a1..59f566e 100644 --- a/lib/utils/os_startup.dart +++ b/lib/utils/os_startup.dart @@ -316,6 +316,11 @@ Register-ScheduledTask -TaskName \$TaskName -Action \$Action -Trigger \$Trigger Exit '''; + String getScriptPath(String label) { + var debugPath = isDebug ? '.debug' : ''; + return '${dataPath.replaceAll('/', '\\')}$debugPath\\$label.ps1'; + } + @override Future isRegistedStartup(String label) async { var shell = 'Get-ScheduledTask | Where-Object {\$_.TaskName -eq "$label"}'; @@ -343,7 +348,7 @@ Exit {List? arguments, String? logStandardFilePath, String? logErrorFilePath}) async { - var scriptPath = '${dataPath.replaceAll('/', '\\')}\\$label.ps1'; + var scriptPath = getScriptPath(label); var startupScript = startupScriptTemplate.replaceAll( '{EXECUTABLE_PATH}', executableFilePath.replaceAll('/', '\\')); var args = ''; @@ -389,6 +394,8 @@ Exit print(process.stderr.toString()); print(process.exitCode); + tempFile.deleteSync(); + return dataFutrue(process.exitCode == 0); } @@ -406,6 +413,12 @@ Exit print(process.stdout.toString()); print(process.stderr.toString()); print(process.exitCode); + + var scriptFile = File(getScriptPath(label)); + if (scriptFile.existsSync()) { + scriptFile.deleteSync(); + } + return dataFutrue(process.exitCode == 0); } }