mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
👌 Swift 6 compatibility
This commit is contained in:
@ -79,11 +79,11 @@
|
|||||||
isEnabled = "NO">
|
isEnabled = "NO">
|
||||||
</CommandLineArgument>
|
</CommandLineArgument>
|
||||||
<CommandLineArgument
|
<CommandLineArgument
|
||||||
argument = "--configuration:/tmp/pmc_working.json"
|
argument = "--configuration:~/.phpmon_fconf_working.json"
|
||||||
isEnabled = "YES">
|
isEnabled = "YES">
|
||||||
</CommandLineArgument>
|
</CommandLineArgument>
|
||||||
<CommandLineArgument
|
<CommandLineArgument
|
||||||
argument = "--configuration:/tmp/pmc_broken.json"
|
argument = "--configuration:~/.phpmon_fconf_broken.json"
|
||||||
isEnabled = "NO">
|
isEnabled = "NO">
|
||||||
</CommandLineArgument>
|
</CommandLineArgument>
|
||||||
</CommandLineArguments>
|
</CommandLineArguments>
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
extension Process: @unchecked Sendable {}
|
||||||
|
extension Timer: @unchecked Sendable {}
|
||||||
|
|
||||||
class RealShell: ShellProtocol {
|
class RealShell: ShellProtocol {
|
||||||
/**
|
/**
|
||||||
The launch path of the terminal in question that is used.
|
The launch path of the terminal in question that is used.
|
||||||
@ -123,7 +126,8 @@ class RealShell: ShellProtocol {
|
|||||||
withTimeout timeout: TimeInterval = 5.0
|
withTimeout timeout: TimeInterval = 5.0
|
||||||
) async throws -> (Process, ShellOutput) {
|
) async throws -> (Process, ShellOutput) {
|
||||||
let task = getShellProcess(for: command)
|
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
|
task.listen { incoming in
|
||||||
output.out += incoming; didReceiveOutput(incoming, .stdOut)
|
output.out += incoming; didReceiveOutput(incoming, .stdOut)
|
||||||
@ -134,7 +138,7 @@ class RealShell: ShellProtocol {
|
|||||||
return try await withCheckedThrowingContinuation({ continuation in
|
return try await withCheckedThrowingContinuation({ continuation in
|
||||||
var timer: Timer?
|
var timer: Timer?
|
||||||
|
|
||||||
task.terminationHandler = { process in
|
task.terminationHandler = { [timer, output] process in
|
||||||
process.haltListening()
|
process.haltListening()
|
||||||
|
|
||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
|
@ -52,7 +52,7 @@ enum ShellStream: Codable {
|
|||||||
case stdOut, stdErr, stdIn
|
case stdOut, stdErr, stdIn
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ShellOutput {
|
class ShellOutput {
|
||||||
var out: String
|
var out: String
|
||||||
var err: String
|
var err: String
|
||||||
|
|
||||||
@ -60,6 +60,11 @@ struct ShellOutput {
|
|||||||
return err.lengthOfBytes(using: .utf8) > 0
|
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 {
|
static func out(_ out: String?, _ err: String? = nil) -> ShellOutput {
|
||||||
return ShellOutput(out: out ?? "", err: err ?? "")
|
return ShellOutput(out: out ?? "", err: err ?? "")
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,11 @@ public struct TestableConfiguration: Codable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func loadFrom(path: String) -> TestableConfiguration {
|
static func loadFrom(path: String) -> TestableConfiguration {
|
||||||
|
let url = URL(fileURLWithPath: path.replacingTildeWithHomeDirectory)
|
||||||
|
|
||||||
return try! JSONDecoder().decode(
|
return try! JSONDecoder().decode(
|
||||||
TestableConfiguration.self,
|
TestableConfiguration.self,
|
||||||
from: try! String(contentsOf: URL(fileURLWithPath: path), encoding: .utf8)
|
from: try! String(contentsOf: url, encoding: .utf8).data(using: .utf8)!
|
||||||
.data(using: .utf8)!
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate {
|
|||||||
|
|
||||||
// MARK: - Outlet Interactions
|
// MARK: - Outlet Interactions
|
||||||
|
|
||||||
@IBAction func pressedCreateLink(_ sender: Any) async {
|
func createLink() async {
|
||||||
let path = pathControl.url!.path
|
let path = pathControl.url!.path
|
||||||
let name = inputDomainName.stringValue
|
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) {
|
@IBAction func pressedCancel(_ sender: Any) {
|
||||||
dismissView(outcome: .cancel)
|
dismissView(outcome: .cancel)
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ class DomainListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource
|
|||||||
@MainActor public func setUIBusy() {
|
@MainActor public func setUIBusy() {
|
||||||
// If it takes more than 0.5s to set the UI to not busy, show a spinner
|
// 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
|
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
|
tableView.alphaValue = 0.3
|
||||||
|
@ -11,10 +11,20 @@ import XCTest
|
|||||||
class TestableConfigurationTest: XCTestCase {
|
class TestableConfigurationTest: XCTestCase {
|
||||||
func test_configuration_can_be_saved_as_json() async {
|
func test_configuration_can_be_saved_as_json() async {
|
||||||
var configuration = TestableConfigurations.working
|
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
|
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
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user