mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-08 05:30:05 +01:00
👌 Cleanup, ensure all tests pass
This commit is contained in:
@@ -51,6 +51,9 @@ class Alert {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Notify the user about something by showing an alert.
|
||||
*/
|
||||
public static func notify(message: String, info: String, style: NSAlert.Style = .informational) {
|
||||
_ = present(
|
||||
messageText: message,
|
||||
@@ -61,7 +64,11 @@ class Alert {
|
||||
)
|
||||
}
|
||||
|
||||
public static func notifyAbout(error: Error&AlertableError) {
|
||||
/**
|
||||
Notify the user about a particular error (which must be `Alertable`)
|
||||
by showing an alert.
|
||||
*/
|
||||
public static func notify(about error: Error & AlertableError) {
|
||||
let key = error.getErrorMessageKey()
|
||||
_ = present(
|
||||
messageText: "\(key).title".localized,
|
||||
|
||||
@@ -20,13 +20,19 @@ extension MainMenu {
|
||||
}
|
||||
|
||||
/**
|
||||
Attempts asynchronous execution of a callback that may throw an Error.
|
||||
Attempts asynchronous execution of a callback that may throw an `Error`.
|
||||
While the callback is being executed, the UI will be marked as busy.
|
||||
|
||||
- Parameter execute: Callback of the work that needs to happen.
|
||||
- Parameter success: Callback that is fired when all was OK.
|
||||
- Parameter failure: Callback that is fired when an Error was thrown.
|
||||
(Preferably, if an `Error` is thrown, it should also be an `AlertableError`,
|
||||
which will make presenting errors easier.)
|
||||
|
||||
- Parameter execute: Required callback of the work that needs to happen.
|
||||
|
||||
- Parameter success: Optional callback that is fired when all was OK.
|
||||
- Parameter failure: Optional callback that is fired when an `Error` was thrown.
|
||||
- Parameter behaviours: Various behaviours that can be tweaked, but usually best left to the default.
|
||||
The default will set the UI to busy, reload PHP info, update the menu bar,
|
||||
and broadcast to the services view that the list has been updated.
|
||||
*/
|
||||
func asyncExecution(
|
||||
_ execute: @escaping () throws -> Void,
|
||||
@@ -42,9 +48,11 @@ extension MainMenu {
|
||||
if behaviours.contains(.reloadsPhpInstallation) {
|
||||
PhpEnv.shared.isBusy = true
|
||||
}
|
||||
|
||||
if behaviours.contains(.setsBusyUI) {
|
||||
setBusyImage()
|
||||
}
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||
var error: Error? = nil
|
||||
|
||||
@@ -60,13 +68,9 @@ extension MainMenu {
|
||||
}
|
||||
|
||||
if behaviours.contains(.updatesMenuBarContents) {
|
||||
// Refresh the entire menu bar menu's contents
|
||||
updatePhpVersionInStatusBar()
|
||||
} else {
|
||||
// We do still need to refresh the icon based on the busy state
|
||||
if behaviours.contains(.setsBusyUI) {
|
||||
refreshIcon()
|
||||
}
|
||||
} else if behaviours.contains(.setsBusyUI) {
|
||||
refreshIcon()
|
||||
}
|
||||
|
||||
if behaviours.contains(.broadcastServicesUpdate) {
|
||||
|
||||
@@ -160,9 +160,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
style: .warning
|
||||
)
|
||||
} failure: { error in
|
||||
let error = error as! HomebrewPermissionError
|
||||
Alert.notifyAbout(error: error)
|
||||
|
||||
Alert.notify(about: error as! HomebrewPermissionError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user