mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
👌 Various alerts updated
This commit is contained in:
@ -7,34 +7,8 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
#warning("This deprecated class should be removed at the earliest convenience once no code relies on it.")
|
||||
|
||||
@available(*, deprecated, message: "Use the BetterAlert API instead")
|
||||
class Alert {
|
||||
|
||||
public static func present(
|
||||
messageText: String,
|
||||
informativeText: String,
|
||||
buttonTitle: String = "OK",
|
||||
secondButtonTitle: String = "",
|
||||
style: NSAlert.Style = .informational
|
||||
) -> Bool {
|
||||
|
||||
if !Thread.isMainThread {
|
||||
fatalError("You should always present alerts on the main thread!")
|
||||
}
|
||||
|
||||
let alert = NSAlert.init()
|
||||
alert.alertStyle = style
|
||||
alert.messageText = messageText
|
||||
alert.informativeText = informativeText
|
||||
alert.addButton(withTitle: buttonTitle)
|
||||
if (!secondButtonTitle.isEmpty) {
|
||||
alert.addButton(withTitle: secondButtonTitle)
|
||||
}
|
||||
return alert.runModal() == .alertFirstButtonReturn
|
||||
}
|
||||
|
||||
public static func confirm(
|
||||
onWindow window: NSWindow,
|
||||
messageText: String,
|
||||
@ -63,31 +37,4 @@ class Alert {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Notify the user about something by showing an alert.
|
||||
*/
|
||||
public static func notify(message: String, info: String, button: String = "OK", style: NSAlert.Style = .informational) {
|
||||
_ = present(
|
||||
messageText: message,
|
||||
informativeText: info,
|
||||
buttonTitle: button,
|
||||
secondButtonTitle: "",
|
||||
style: style
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
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,
|
||||
informativeText: "\(key).description".localized,
|
||||
buttonTitle: "OK",
|
||||
secondButtonTitle: "",
|
||||
style: .critical
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,13 @@ class Valet {
|
||||
let version = version
|
||||
Log.warn("Valet version \(version!) is too old! (recommended: \(Constants.MinimumRecommendedValetVersion))")
|
||||
DispatchQueue.main.async {
|
||||
Alert.notify(message: "alert.min_valet_version.title".localized, info: "alert.min_valet_version.info".localized(version!, Constants.MinimumRecommendedValetVersion))
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.min_valet_version.title".localized,
|
||||
subtitle:"alert.min_valet_version.info".localized(version!, Constants.MinimumRecommendedValetVersion)
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
}
|
||||
} else {
|
||||
Log.info("Valet version \(version!) is recent enough, OK (recommended: \(Constants.MinimumRecommendedValetVersion))")
|
||||
|
@ -16,10 +16,14 @@ extension MainMenu {
|
||||
*/
|
||||
func updateGlobalDependencies(notify: Bool, completion: @escaping (Bool) -> Void) {
|
||||
if !Filesystem.fileExists("/usr/local/bin/composer") {
|
||||
Alert.notify(
|
||||
message: "alert.composer_missing.title".localized,
|
||||
info: "alert.composer_missing.info".localized
|
||||
)
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.composer_missing.title".localized,
|
||||
subtitle: "alert.composer_missing.info".localized
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,13 @@ extension MainMenu {
|
||||
|
||||
if HomebrewDiagnostics.hasAliasConflict() {
|
||||
DispatchQueue.main.async {
|
||||
Alert.notify(
|
||||
message: "alert.php_alias_conflict.title".localized,
|
||||
info: "alert.php_alias_conflict.info".localized,
|
||||
style: .critical
|
||||
)
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.php_alias_conflict.title".localized,
|
||||
subtitle: "alert.php_alias_conflict.info".localized
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,29 +170,30 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
|
||||
// MARK: - Actions
|
||||
|
||||
@objc func fixHomebrewPermissions() {
|
||||
if !Alert.present(
|
||||
messageText: "alert.fix_homebrew_permissions.title".localized,
|
||||
informativeText: "alert.fix_homebrew_permissions.info".localized,
|
||||
buttonTitle: "alert.fix_homebrew_permissions.ok".localized,
|
||||
secondButtonTitle: "alert.fix_homebrew_permissions.cancel".localized,
|
||||
style: .warning
|
||||
) {
|
||||
if BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.fix_homebrew_permissions.title".localized,
|
||||
subtitle: "alert.fix_homebrew_permissions.info".localized
|
||||
)
|
||||
.withPrimary(text: "alert.fix_homebrew_permissions.ok".localized)
|
||||
.withSecondary(text: "alert.fix_homebrew_permissions.cancel".localized)
|
||||
.didSelectPrimary() {
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
asyncExecution {
|
||||
try Actions.fixHomebrewPermissions()
|
||||
} success: {
|
||||
Alert.notify(
|
||||
message: "alert.fix_homebrew_permissions_done.title".localized,
|
||||
info: "alert.fix_homebrew_permissions_done.info".localized,
|
||||
style: .warning
|
||||
)
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.fix_homebrew_permissions_done.title".localized,
|
||||
subtitle: "alert.fix_homebrew_permissions_done.info".localized
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
} failure: { error in
|
||||
await Alert.notify(about: error as! HomebrewPermissionError)
|
||||
BetterAlert.show(for: error as! HomebrewPermissionError)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@objc func restartPhpFpm() {
|
||||
|
@ -105,4 +105,15 @@ class BetterAlert {
|
||||
public func show() {
|
||||
_ = self.runModal()
|
||||
}
|
||||
|
||||
/**
|
||||
Shows the modal for a particular error.
|
||||
*/
|
||||
public static func show(for error: Error & AlertableError) {
|
||||
let key = error.getErrorMessageKey()
|
||||
return BetterAlert().withInformation(
|
||||
title: "\(key).title".localized,
|
||||
subtitle: "\(key).description".localized
|
||||
).withPrimary(text: "OK").show()
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,13 @@ extension ActivePhpInstallation {
|
||||
public func notifyAboutBrokenPhpFpm() {
|
||||
if !self.checkPhpFpmStatus() {
|
||||
DispatchQueue.main.async {
|
||||
Alert.notify(
|
||||
message: "alert.php_fpm_broken.title".localized,
|
||||
info: "alert.php_fpm_broken.info".localized,
|
||||
style: .critical
|
||||
)
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "alert.php_fpm_broken.title".localized,
|
||||
subtitle: "alert.php_fpm_broken.info".localized
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,13 @@ extension SiteListVC {
|
||||
} completion: { [self] in
|
||||
selectedSite.determineSecured(Valet.shared.config.tld)
|
||||
if selectedSite.secured == originalSecureStatus {
|
||||
Alert.notify(
|
||||
message: "site_list.alerts_status_not_changed.title".localized,
|
||||
info: "site_list.alerts_status_not_changed.desc".localized(command)
|
||||
)
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "site_list.alerts_status_not_changed.title".localized,
|
||||
subtitle: "site_list.alerts_status_not_changed.desc".localized(command)
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
} else {
|
||||
let newState = selectedSite.secured ? "secured" : "unsecured"
|
||||
LocalNotification.send(
|
||||
@ -51,10 +54,13 @@ extension SiteListVC {
|
||||
if url != nil {
|
||||
NSWorkspace.shared.open(url!)
|
||||
} else {
|
||||
_ = Alert.present(
|
||||
messageText: "site_list.alert.invalid_folder_name".localized,
|
||||
informativeText: "site_list.alert.invalid_folder_name_desc".localized
|
||||
)
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
title: "site_list.alert.invalid_folder_name".localized,
|
||||
subtitle: "site_list.alert.invalid_folder_name_desc".localized
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user