mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
👌 Improvements to BetterAlert, apply() configs
- MainActor fixes for BetterAlert - Added `apply` for TestableConfiguration
This commit is contained in:
@ -76,7 +76,7 @@
|
|||||||
<EnvironmentVariable
|
<EnvironmentVariable
|
||||||
key = "SLOW_SHELL_MODE"
|
key = "SLOW_SHELL_MODE"
|
||||||
value = ""
|
value = ""
|
||||||
isEnabled = "YES">
|
isEnabled = "NO">
|
||||||
</EnvironmentVariable>
|
</EnvironmentVariable>
|
||||||
<EnvironmentVariable
|
<EnvironmentVariable
|
||||||
key = "PAINT_PHPMON_SWIFTUI_VIEWS"
|
key = "PAINT_PHPMON_SWIFTUI_VIEWS"
|
||||||
|
@ -16,8 +16,7 @@ class ActiveFileSystem {
|
|||||||
static var shared: FileSystemProtocol = RealFileSystem()
|
static var shared: FileSystemProtocol = RealFileSystem()
|
||||||
|
|
||||||
public static func useTestable(_ files: [String: FakeFile]) {
|
public static func useTestable(_ files: [String: FakeFile]) {
|
||||||
// TODO
|
Self.shared = TestableFileSystem(files: files)
|
||||||
// Self.shared = TestableShell(expectations: expectations)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func useSystem() {
|
public static func useSystem() {
|
||||||
|
@ -12,6 +12,11 @@ struct TestableConfiguration {
|
|||||||
let architecture: String
|
let architecture: String
|
||||||
let filesystem: [String: FakeFile]
|
let filesystem: [String: FakeFile]
|
||||||
let shellOutput: [String: BatchFakeShellOutput]
|
let shellOutput: [String: BatchFakeShellOutput]
|
||||||
|
|
||||||
|
func apply() {
|
||||||
|
ActiveShell.useTestable(shellOutput)
|
||||||
|
ActiveFileSystem.useTestable(filesystem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// swiftlint:disable colon trailing_comma
|
// swiftlint:disable colon trailing_comma
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class TestableFileSystem: FileSystemProtocol {
|
class TestableFileSystem: FileSystemProtocol {
|
||||||
|
init(files: [String: FakeFile]) {
|
||||||
|
self.files = files
|
||||||
|
}
|
||||||
|
|
||||||
|
var files: [String: FakeFile]
|
||||||
|
|
||||||
func isExecutableFile(_ path: String) -> Bool {
|
func isExecutableFile(_ path: String) -> Bool {
|
||||||
// TODO
|
// TODO
|
||||||
return false
|
return false
|
||||||
|
@ -57,13 +57,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
|||||||
*/
|
*/
|
||||||
override init() {
|
override init() {
|
||||||
logger.verbosity = .info
|
logger.verbosity = .info
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
logger.verbosity = .performance
|
logger.verbosity = .performance
|
||||||
|
TestableConfigurations.working.apply()
|
||||||
// TODO: Enable to fake broken setup during testing
|
|
||||||
// ActiveShell.useTestable(Testables.working.shellOutput)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if CommandLine.arguments.contains("--v") {
|
if CommandLine.arguments.contains("--v") {
|
||||||
logger.verbosity = .performance
|
logger.verbosity = .performance
|
||||||
Log.info("Extra verbose mode has been activated.")
|
Log.info("Extra verbose mode has been activated.")
|
||||||
|
@ -29,7 +29,7 @@ class Startup {
|
|||||||
|
|
||||||
// If we get here, something's gone wrong and the check has failed...
|
// If we get here, something's gone wrong and the check has failed...
|
||||||
Log.info("[FAIL] \(check.name)")
|
Log.info("[FAIL] \(check.name)")
|
||||||
showAlert(for: check)
|
await showAlert(for: check)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +45,7 @@ class Startup {
|
|||||||
- ones that require an app restart, which prompt the user to exit the app
|
- ones that require an app restart, which prompt the user to exit the app
|
||||||
- ones that allow the app to continue, which allow the user to retry
|
- ones that allow the app to continue, which allow the user to retry
|
||||||
*/
|
*/
|
||||||
private func showAlert(for check: EnvironmentCheck) {
|
@MainActor private func showAlert(for check: EnvironmentCheck) {
|
||||||
DispatchQueue.main.async {
|
|
||||||
if check.requiresAppRestart {
|
if check.requiresAppRestart {
|
||||||
BetterAlert()
|
BetterAlert()
|
||||||
.withInformation(
|
.withInformation(
|
||||||
@ -68,7 +67,6 @@ class Startup {
|
|||||||
.withPrimary(text: "OK")
|
.withPrimary(text: "OK")
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Because the Switcher requires various environment guarantees, the switcher is only
|
Because the Switcher requires various environment guarantees, the switcher is only
|
||||||
|
@ -12,7 +12,7 @@ extension MainMenu {
|
|||||||
|
|
||||||
// MARK: - Actions
|
// MARK: - Actions
|
||||||
|
|
||||||
@objc func fixHomebrewPermissions() {
|
@MainActor @objc func fixHomebrewPermissions() {
|
||||||
if !BetterAlert()
|
if !BetterAlert()
|
||||||
.withInformation(
|
.withInformation(
|
||||||
title: "alert.fix_homebrew_permissions.title".localized,
|
title: "alert.fix_homebrew_permissions.title".localized,
|
||||||
|
@ -31,8 +31,8 @@ class BetterAlert {
|
|||||||
|
|
||||||
public func withPrimary(
|
public func withPrimary(
|
||||||
text: String,
|
text: String,
|
||||||
action: @escaping (BetterAlertVC) -> Void = { vc in
|
action: @MainActor @escaping (BetterAlertVC) -> Void = { vc in
|
||||||
DispatchQueue.main.async { vc.close(with: .alertFirstButtonReturn) }
|
vc.close(with: .alertFirstButtonReturn)
|
||||||
}
|
}
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.noticeVC.buttonPrimary.title = text
|
self.noticeVC.buttonPrimary.title = text
|
||||||
@ -42,8 +42,8 @@ class BetterAlert {
|
|||||||
|
|
||||||
public func withSecondary(
|
public func withSecondary(
|
||||||
text: String,
|
text: String,
|
||||||
action: ((BetterAlertVC) -> Void)? = { vc in
|
action: (@MainActor (BetterAlertVC) -> Void)? = { vc in
|
||||||
DispatchQueue.main.async { vc.close(with: .alertSecondButtonReturn) }
|
vc.close(with: .alertSecondButtonReturn)
|
||||||
}
|
}
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.noticeVC.buttonSecondary.title = text
|
self.noticeVC.buttonSecondary.title = text
|
||||||
@ -53,7 +53,7 @@ class BetterAlert {
|
|||||||
|
|
||||||
public func withTertiary(
|
public func withTertiary(
|
||||||
text: String = "",
|
text: String = "",
|
||||||
action: ((BetterAlertVC) -> Void)? = nil
|
action: (@MainActor (BetterAlertVC) -> Void)? = nil
|
||||||
) -> Self {
|
) -> Self {
|
||||||
if text == "" {
|
if text == "" {
|
||||||
self.noticeVC.buttonTertiary.bezelStyle = .helpButton
|
self.noticeVC.buttonTertiary.bezelStyle = .helpButton
|
||||||
@ -84,7 +84,7 @@ class BetterAlert {
|
|||||||
Shows the modal and returns a ModalResponse.
|
Shows the modal and returns a ModalResponse.
|
||||||
If you wish to simply show the alert and disregard the outcome, use `show`.
|
If you wish to simply show the alert and disregard the outcome, use `show`.
|
||||||
*/
|
*/
|
||||||
public func runModal() -> NSApplication.ModalResponse {
|
@MainActor public func runModal() -> NSApplication.ModalResponse {
|
||||||
if !Thread.isMainThread {
|
if !Thread.isMainThread {
|
||||||
fatalError("You should always present alerts on the main thread!")
|
fatalError("You should always present alerts on the main thread!")
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ class BetterAlert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Shows the modal and returns true if the user pressed the primary button. */
|
/** Shows the modal and returns true if the user pressed the primary button. */
|
||||||
public func didSelectPrimary() -> Bool {
|
@MainActor public func didSelectPrimary() -> Bool {
|
||||||
return self.runModal() == .alertFirstButtonReturn
|
return self.runModal() == .alertFirstButtonReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ class BetterAlertVC: NSViewController {
|
|||||||
@IBOutlet weak var buttonSecondary: NSButton!
|
@IBOutlet weak var buttonSecondary: NSButton!
|
||||||
@IBOutlet weak var buttonTertiary: NSButton!
|
@IBOutlet weak var buttonTertiary: NSButton!
|
||||||
|
|
||||||
var actionPrimary: (BetterAlertVC) -> Void = { _ in }
|
var actionPrimary: (@MainActor (BetterAlertVC) -> Void) = { _ in }
|
||||||
var actionSecondary: ((BetterAlertVC) -> Void)?
|
var actionSecondary: (@MainActor (BetterAlertVC) -> Void)?
|
||||||
var actionTertiary: ((BetterAlertVC) -> Void)?
|
var actionTertiary: (@MainActor (BetterAlertVC) -> Void)?
|
||||||
|
|
||||||
@IBOutlet weak var imageView: NSImageView!
|
@IBOutlet weak var imageView: NSImageView!
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user