mac shell udpate
This commit is contained in:
parent
671faca019
commit
363f96834b
1 changed files with 45 additions and 21 deletions
|
|
@ -2,6 +2,7 @@ import 'dart:io';
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:dart_framework/utils/path.dart';
|
||||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:dart_framework/platform/process.dart';
|
||||
|
||||
|
|
@ -73,13 +74,39 @@ class _StartupMac extends _Startup {
|
|||
<string>{LABEL}</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>{FILE_PATH}</string>{PARAMETERS}
|
||||
<string>{FILE_PATH}</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>{LOG_STANDARD}{LOG_ERROR}
|
||||
</dict>
|
||||
</plist>""";
|
||||
|
||||
final pathTemplate = """#!/bin/bash
|
||||
|
||||
# Load .zprofile if it exists
|
||||
if [ -f ~/.zprofile ]; then
|
||||
source ~/.zprofile
|
||||
fi
|
||||
|
||||
# Load .bash_profile if it exists
|
||||
if [ -f ~/.bash_profile ]; then
|
||||
source ~/.bash_profile
|
||||
fi
|
||||
|
||||
# Load .bashrc if it exists (optional)
|
||||
if [ -f ~/.bashrc ]; then
|
||||
source ~/.bashrc
|
||||
fi
|
||||
|
||||
# Load .zshrc if it exists (optional)
|
||||
if [ -f ~/.zshrc ]; then
|
||||
source ~/.zshrc
|
||||
fi
|
||||
|
||||
# Run your command
|
||||
{COMMAND}
|
||||
""";
|
||||
|
||||
final logStandardTemplate = """
|
||||
|
||||
<key>StandardOutPath</key>
|
||||
|
|
@ -105,31 +132,29 @@ class _StartupMac extends _Startup {
|
|||
{List<String>? arguments,
|
||||
String? logStandardFilePath,
|
||||
String? logErrorFilePath}) async {
|
||||
var c = Completer<bool>();
|
||||
final tagLabel = '{LABEL}';
|
||||
final tagPath = '{FILE_PATH}';
|
||||
var success = false;
|
||||
|
||||
//compose parameters
|
||||
var parameters = '';
|
||||
if (arguments != null) {
|
||||
for (var arg in arguments) {
|
||||
parameters += """
|
||||
|
||||
<string>$arg</string>""";
|
||||
}
|
||||
}
|
||||
|
||||
//create plist in LaunchAgents
|
||||
final plistName = '$label.plist';
|
||||
final userPath = await Path.userPath;
|
||||
var success = false;
|
||||
final appDir = Directory('$userPath/Library/$label');
|
||||
final file = File('${appDir.path}/launch.sh');
|
||||
|
||||
if(!appDir.existsSync()) {
|
||||
appDir.createSync(recursive: true);
|
||||
}
|
||||
|
||||
var param = arguments == null ? '' : ' ${arguments.join(' ')}';
|
||||
var launchContent = pathTemplate.replaceAll('{COMMAND}', '$executableFilePath$param');
|
||||
file.writeAsStringSync(launchContent);
|
||||
|
||||
//create plist in LaunchAgents
|
||||
|
||||
final tagLogStandard = '{LOG_STANDARD}';
|
||||
final tagLogError = '{LOG_ERROR}';
|
||||
final tagParameters = '{PARAMETERS}';
|
||||
var plistContent = plistTemplate
|
||||
.replaceAll(tagLabel, label)
|
||||
.replaceAll(tagPath, executableFilePath)
|
||||
.replaceAll(tagParameters, parameters);
|
||||
.replaceAll(tagPath, file.path);
|
||||
if (logStandardFilePath == null) {
|
||||
plistContent = plistContent.replaceAll(tagLogStandard, '');
|
||||
} else {
|
||||
|
|
@ -147,11 +172,10 @@ class _StartupMac extends _Startup {
|
|||
await plistFile.writeAsString(plistContent);
|
||||
|
||||
var result = await ProcessExecutor.run(
|
||||
StringBuffer('chmod +x "$executableFilePath"'));
|
||||
StringBuffer('chmod +x "$executableFilePath" && chmod +x "${file.path}" '));
|
||||
success = result.exitCode == 0;
|
||||
|
||||
c.complete(success);
|
||||
return c.future;
|
||||
return dataFutrue(success);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
Loading…
Reference in a new issue