Skip to content

Commit

Permalink
fix: Fixed the issue of not being able to recognize the Exit Code.
Browse files Browse the repository at this point in the history
  • Loading branch information
X1a0He committed Nov 15, 2024
1 parent 33daa8f commit bc6cfba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions Adobe Downloader/Scripts/clean-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ sudo /usr/bin/killall -u root -9 Adobe\ Downloader
sudo /bin/launchctl unload /Library/LaunchDaemons/com.x1a0he.macOS.Adobe-Downloader.helper.plist
sudo /bin/rm /Library/LaunchDaemons/com.x1a0he.macOS.Adobe-Downloader.helper.plist
sudo /bin/rm /Library/PrivilegedHelperTools/com.x1a0he.macOS.Adobe-Downloader.helper
sudo /bin/rm -rf ~/Library/Application\ Support/Adobe\ Downloader
sudo /bin/rm ~/Library/Preferences/com.x1a0he.macOS.Adobe-Downloader.plist
sudo /usr/bin/killall -u root -9 com.x1a0he.macOS.Adobe-Downloader.helper
19 changes: 16 additions & 3 deletions Adobe Downloader/Utils/InstallManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ actor InstallManager {
do {
try await PrivilegedHelperManager.shared.executeInstallation(installCommand) { output in
Task { @MainActor in
if let range = output.range(of: "Exit Code: (-?[0-9]+)", options: .regularExpression),
if let range = output.range(of: "Exit Code:\\s*(-?[0-9]+)", options: .regularExpression),
let codeStr = output[range].split(separator: ":").last?.trimmingCharacters(in: .whitespaces),
let exitCode = Int(codeStr) {

if exitCode == 0 {
progressHandler(1.0, String(localized: "安装完成"))
PrivilegedHelperManager.shared.executeCommand("pkill -f Setup") { _ in }
continuation.resume()
return
} else {
let errorMessage: String
switch exitCode {
Expand All @@ -126,8 +127,8 @@ actor InstallManager {
}
progressHandler(0.0, errorMessage)
continuation.resume(throwing: InstallError.installationFailed(errorMessage))
return
}
return
}

if let progress = await self.parseProgress(from: output) {
Expand All @@ -143,7 +144,19 @@ actor InstallManager {
}

private func parseProgress(from output: String) -> Double? {
if let range = output.range(of: "Progress: ([0-9]{1,3})%", options: .regularExpression),
if let range = output.range(of: "Exit Code:\\s*(-?[0-9]+)", options: .regularExpression),
let codeStr = output[range].split(separator: ":").last?.trimmingCharacters(in: .whitespaces),
let exitCode = Int(codeStr) {
if exitCode == 0 {
return 1.0
}
}

if output.range(of: "Progress:\\s*[0-9]+/[0-9]+", options: .regularExpression) != nil {
return nil
}

if let range = output.range(of: "Progress:\\s*([0-9]{1,3})%", options: .regularExpression),
let progressStr = output[range].split(separator: ":").last?.trimmingCharacters(in: .whitespaces),
let progressValue = Double(progressStr.replacingOccurrences(of: "%", with: "")) {
return progressValue / 100.0
Expand Down
4 changes: 3 additions & 1 deletion AdobeDownloaderHelperTool/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ class HelperTool: NSObject, HelperToolProtocol {
if data.isEmpty {
if let task = currentTask, !task.isRunning {
logger.notice("Setup 进程已结束")
let exitCode = task.terminationStatus
reply("Exit Code: \(exitCode)")
currentTask = nil
outputPipe = nil
reply("Completed")
return
} else {
reply("")
}
Expand Down

0 comments on commit bc6cfba

Please sign in to comment.