1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

👌 Swift 6 compatibility

This commit is contained in:
2022-10-18 23:41:46 +02:00
parent 507d7d5b23
commit 1c0d9f6826
7 changed files with 35 additions and 11 deletions

View File

@ -79,11 +79,11 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--configuration:/tmp/pmc_working.json"
argument = "--configuration:~/.phpmon_fconf_working.json"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--configuration:/tmp/pmc_broken.json"
argument = "--configuration:~/.phpmon_fconf_broken.json"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>

View File

@ -8,6 +8,9 @@
import Foundation
extension Process: @unchecked Sendable {}
extension Timer: @unchecked Sendable {}
class RealShell: ShellProtocol {
/**
The launch path of the terminal in question that is used.
@ -123,7 +126,8 @@ class RealShell: ShellProtocol {
withTimeout timeout: TimeInterval = 5.0
) async throws -> (Process, ShellOutput) {
let task = getShellProcess(for: command)
var output = ShellOutput(out: "", err: "")
// TODO: Make ShellOutput a struct again and add a class type for this use case only
let output = ShellOutput(out: "", err: "")
task.listen { incoming in
output.out += incoming; didReceiveOutput(incoming, .stdOut)
@ -134,7 +138,7 @@ class RealShell: ShellProtocol {
return try await withCheckedThrowingContinuation({ continuation in
var timer: Timer?
task.terminationHandler = { process in
task.terminationHandler = { [timer, output] process in
process.haltListening()
timer?.invalidate()

View File

@ -52,7 +52,7 @@ enum ShellStream: Codable {
case stdOut, stdErr, stdIn
}
struct ShellOutput {
class ShellOutput {
var out: String
var err: String
@ -60,6 +60,11 @@ struct ShellOutput {
return err.lengthOfBytes(using: .utf8) > 0
}
init(out: String, err: String) {
self.out = out
self.err = err
}
static func out(_ out: String?, _ err: String? = nil) -> ShellOutput {
return ShellOutput(out: out ?? "", err: err ?? "")
}

View File

@ -31,10 +31,11 @@ public struct TestableConfiguration: Codable {
}
static func loadFrom(path: String) -> TestableConfiguration {
let url = URL(fileURLWithPath: path.replacingTildeWithHomeDirectory)
return try! JSONDecoder().decode(
TestableConfiguration.self,
from: try! String(contentsOf: URL(fileURLWithPath: path), encoding: .utf8)
.data(using: .utf8)!
from: try! String(contentsOf: url, encoding: .utf8).data(using: .utf8)!
)
}
}

View File

@ -51,7 +51,7 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate {
// MARK: - Outlet Interactions
@IBAction func pressedCreateLink(_ sender: Any) async {
func createLink() async {
let path = pathControl.url!.path
let name = inputDomainName.stringValue
@ -89,6 +89,10 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate {
)
}
@IBAction func pressedCreateLink(_ sender: Any) {
Task { await createLink() }
}
@IBAction func pressedCancel(_ sender: Any) {
dismissView(outcome: .cancel)
}

View File

@ -110,7 +110,7 @@ class DomainListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource
@MainActor public func setUIBusy() {
// If it takes more than 0.5s to set the UI to not busy, show a spinner
timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { _ in
self.progressIndicator.startAnimation(true)
DispatchQueue.main.async { self.progressIndicator.startAnimation(true) }
})
tableView.alphaValue = 0.3

View File

@ -11,10 +11,20 @@ import XCTest
class TestableConfigurationTest: XCTestCase {
func test_configuration_can_be_saved_as_json() async {
var configuration = TestableConfigurations.working
try! configuration.toJson().write(toFile: "/tmp/pmc_working.json", atomically: true, encoding: .utf8)
try! configuration.toJson().write(
toFile: NSHomeDirectory() + "/.phpmon_fconf_working.json",
atomically: true,
encoding: .utf8
)
configuration.filesystem["/opt/homebrew/bin/php"] = nil
try! configuration.toJson().write(toFile: "/tmp/pmc_broken.json", atomically: true, encoding: .utf8)
try! configuration.toJson().write(
toFile: NSHomeDirectory() + "/.phpmon_fconf_broken.json",
atomically: true,
encoding: .utf8
)
}
}