mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 12:00:09 +02:00
🏗 Use @MainActor for BetterAlert
This commit is contained in:
@ -10,7 +10,7 @@ import UserNotifications
|
||||
|
||||
class LocalNotification {
|
||||
|
||||
public static func send(title: String, subtitle: String, preference: PreferenceName) {
|
||||
@MainActor public static func send(title: String, subtitle: String, preference: PreferenceName) {
|
||||
if !Preferences.isEnabled(preference) {
|
||||
return
|
||||
}
|
||||
|
@ -56,12 +56,14 @@ class InterApp {
|
||||
if PhpEnv.shared.availablePhpVersions.contains(version) {
|
||||
MainMenu.shared.switchToPhpVersion(version)
|
||||
} else {
|
||||
BetterAlert().withInformation(
|
||||
title: "alert.php_switch_unavailable.title".localized,
|
||||
subtitle: "alert.php_switch_unavailable.subtitle".localized(version)
|
||||
).withPrimary(
|
||||
text: "alert.php_switch_unavailable.ok".localized
|
||||
).show()
|
||||
DispatchQueue.main.async {
|
||||
BetterAlert().withInformation(
|
||||
title: "alert.php_switch_unavailable.title".localized,
|
||||
subtitle: "alert.php_switch_unavailable.subtitle".localized(version)
|
||||
).withPrimary(
|
||||
text: "alert.php_switch_unavailable.ok".localized
|
||||
).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
]}
|
||||
|
@ -25,7 +25,9 @@ class ComposerWindow {
|
||||
|
||||
Paths.shared.detectBinaryPaths()
|
||||
if Paths.composer == nil {
|
||||
presentMissingAlert()
|
||||
DispatchQueue.main.async {
|
||||
self.presentMissingAlert()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -116,7 +118,7 @@ class ComposerWindow {
|
||||
|
||||
// MARK: Alert
|
||||
|
||||
private func presentMissingAlert() {
|
||||
@MainActor private func presentMissingAlert() {
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.composer_missing.title".localized,
|
||||
|
@ -53,13 +53,11 @@ extension MainMenu {
|
||||
Actions.restartPhpFpm()
|
||||
Actions.restartNginx()
|
||||
} success: {
|
||||
DispatchQueue.main.async {
|
||||
LocalNotification.send(
|
||||
title: "notification.services_restarted".localized,
|
||||
subtitle: "notification.services_restarted_desc".localized,
|
||||
preference: .notifyAboutServices
|
||||
)
|
||||
}
|
||||
LocalNotification.send(
|
||||
title: "notification.services_restarted".localized,
|
||||
subtitle: "notification.services_restarted_desc".localized,
|
||||
preference: .notifyAboutServices
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,13 +65,11 @@ extension MainMenu {
|
||||
asyncExecution {
|
||||
Actions.stopValetServices()
|
||||
} success: {
|
||||
DispatchQueue.main.async {
|
||||
LocalNotification.send(
|
||||
title: "notification.services_stopped".localized,
|
||||
subtitle: "notification.services_stopped_desc".localized,
|
||||
preference: .notifyAboutServices
|
||||
)
|
||||
}
|
||||
LocalNotification.send(
|
||||
title: "notification.services_stopped".localized,
|
||||
subtitle: "notification.services_stopped_desc".localized,
|
||||
preference: .notifyAboutServices
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +151,7 @@ extension MainMenu {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func rollbackPreset() {
|
||||
@MainActor @objc func rollbackPreset() {
|
||||
guard let preset = PresetHelper.rollbackPreset else {
|
||||
return
|
||||
}
|
||||
@ -180,7 +176,7 @@ extension MainMenu {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func showPresetHelp() {
|
||||
@MainActor @objc func showPresetHelp() {
|
||||
BetterAlert().withInformation(
|
||||
title: "preset_help_title".localized,
|
||||
subtitle: "preset_help_info".localized,
|
||||
|
@ -36,8 +36,8 @@ extension MainMenu {
|
||||
*/
|
||||
func asyncExecution(
|
||||
_ execute: @escaping () throws -> Void,
|
||||
success: @escaping () -> Void = {},
|
||||
failure: @escaping (Error) -> Void = { _ in },
|
||||
success: @MainActor @escaping () -> Void = {},
|
||||
failure: @MainActor @escaping (Error) -> Void = { _ in },
|
||||
behaviours: [AsyncBehaviour] = [
|
||||
.setsBusyUI,
|
||||
.reloadsPhpInstallation,
|
||||
|
@ -11,7 +11,7 @@ import AppKit
|
||||
|
||||
extension MainMenu {
|
||||
|
||||
@objc func fixMyValet() {
|
||||
@MainActor @objc func fixMyValet() {
|
||||
let previousVersion = PhpEnv.phpInstall.version.short
|
||||
|
||||
if !PhpEnv.shared.availablePhpVersions.contains(PhpEnv.brewPhpVersion) {
|
||||
@ -42,7 +42,7 @@ extension MainMenu {
|
||||
}
|
||||
}
|
||||
|
||||
private func presentAlertForMissingFormula() {
|
||||
@MainActor private func presentAlertForMissingFormula() {
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.php_formula_missing.title".localized,
|
||||
@ -52,7 +52,7 @@ extension MainMenu {
|
||||
.show()
|
||||
}
|
||||
|
||||
private func presentAlertForSameVersion() {
|
||||
@MainActor private func presentAlertForSameVersion() {
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.fix_my_valet_done.title".localized,
|
||||
@ -63,7 +63,7 @@ extension MainMenu {
|
||||
.show()
|
||||
}
|
||||
|
||||
private func presentAlertForDifferentVersion(version: String) {
|
||||
@MainActor private func presentAlertForDifferentVersion(version: String) {
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.fix_my_valet_done.title".localized,
|
||||
|
@ -50,7 +50,7 @@ extension MainMenu {
|
||||
}
|
||||
}
|
||||
|
||||
private func suggestFixMyValet(failed version: String) {
|
||||
@MainActor private func suggestFixMyValet(failed version: String) {
|
||||
let outcome = BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.php_switch_failed.title".localized(version),
|
||||
@ -75,12 +75,14 @@ extension MainMenu {
|
||||
}
|
||||
|
||||
private func notifyAboutVersionChange(to version: String) {
|
||||
LocalNotification.send(
|
||||
title: String(format: "notification.version_changed_title".localized, version),
|
||||
subtitle: String(format: "notification.version_changed_desc".localized, version),
|
||||
preference: .notifyAboutVersionChange
|
||||
)
|
||||
DispatchQueue.main.async {
|
||||
LocalNotification.send(
|
||||
title: String(format: "notification.version_changed_title".localized, version),
|
||||
subtitle: String(format: "notification.version_changed_desc".localized, version),
|
||||
preference: .notifyAboutVersionChange
|
||||
)
|
||||
|
||||
PhpEnv.phpInstall.notifyAboutBrokenPhpFpm()
|
||||
PhpEnv.phpInstall.notifyAboutBrokenPhpFpm()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,14 +102,14 @@ class BetterAlert {
|
||||
/**
|
||||
Shows the modal and does not return anything.
|
||||
*/
|
||||
public func show() {
|
||||
@MainActor public func show() {
|
||||
_ = self.runModal()
|
||||
}
|
||||
|
||||
/**
|
||||
Shows the modal for a particular error.
|
||||
*/
|
||||
public static func show(for error: Error & AlertableError) {
|
||||
@MainActor public static func show(for error: Error & AlertableError) {
|
||||
let key = error.getErrorMessageKey()
|
||||
return BetterAlert().withInformation(
|
||||
title: "\(key).title".localized,
|
||||
|
@ -107,13 +107,13 @@ struct Preset: Codable, Equatable {
|
||||
|
||||
// Show the correct notification
|
||||
if wasRollback {
|
||||
LocalNotification.send(
|
||||
await LocalNotification.send(
|
||||
title: "notification.preset_reverted_title".localized,
|
||||
subtitle: "notification.preset_reverted_desc".localized,
|
||||
preference: .notifyAboutPresets
|
||||
)
|
||||
} else {
|
||||
LocalNotification.send(
|
||||
await LocalNotification.send(
|
||||
title: "notification.preset_applied_title".localized,
|
||||
subtitle: "notification.preset_applied_desc".localized(self.name),
|
||||
preference: .notifyAboutPresets
|
||||
|
Reference in New Issue
Block a user