1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 20:10:08 +02:00

👌 Improve BetterAlert performance notices

This commit is contained in:
2022-02-17 19:19:02 +01:00
parent d06f92051d
commit 921ecd99d6
7 changed files with 46 additions and 17 deletions

View File

@ -1162,6 +1162,7 @@
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 620; CURRENT_PROJECT_VERSION = 620;
DEBUG = YES;
DEVELOPMENT_TEAM = 8M54J5J787; DEVELOPMENT_TEAM = 8M54J5J787;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = phpmon/Info.plist; INFOPLIST_FILE = phpmon/Info.plist;
@ -1187,6 +1188,7 @@
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 620; CURRENT_PROJECT_VERSION = 620;
DEBUG = NO;
DEVELOPMENT_TEAM = 8M54J5J787; DEVELOPMENT_TEAM = 8M54J5J787;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = phpmon/Info.plist; INFOPLIST_FILE = phpmon/Info.plist;

View File

@ -7,6 +7,7 @@
import Cocoa import Cocoa
@available(*, deprecated, message: "Use BetterAlert API instead for 5.1 and above")
class Alert { class Alert {
public static func present( public static func present(

View File

@ -64,6 +64,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
*/ */
override init() { override init() {
logger.verbosity = .info logger.verbosity = .info
#if DEBUG
logger.verbosity = .performance
#endif
Log.separator(as: .info) Log.separator(as: .info)
Log.info("PHP MONITOR by Nico Verbruggen") Log.info("PHP MONITOR by Nico Verbruggen")
Log.info("Version \(App.version)") Log.info("Version \(App.version)")

View File

@ -53,11 +53,14 @@ extension MainMenu {
} }
@MainActor private func suggestFixMyValet(failed version: String) { @MainActor private func suggestFixMyValet(failed version: String) {
let outcome = Alert.present( let outcome = BetterAlert()
messageText: "alert.php_switch_failed.title".localized(version), .withInformation(
informativeText: "alert.php_switch_failed.info".localized(version), title: "alert.php_switch_failed.title".localized(version),
buttonTitle: "alert.php_switch_failed.confirm".localized, subtitle: "alert.php_switch_failed.info".localized(version)
secondButtonTitle: "alert.php_switch_failed.cancel".localized, style: .informational) )
.withPrimary(text: "alert.php_switch_failed.confirm".localized)
.withSecondary(text: "alert.php_switch_failed.cancel".localized)
.didSelectPrimary()
if outcome { if outcome {
MainMenu.shared.fixMyValet() MainMenu.shared.fixMyValet()
} }

View File

@ -263,17 +263,28 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
@objc func fixMyValet() { @objc func fixMyValet() {
if !PhpEnv.shared.availablePhpVersions.contains(PhpEnv.brewPhpVersion) { if !PhpEnv.shared.availablePhpVersions.contains(PhpEnv.brewPhpVersion) {
Alert.notify(message: "alert.php_formula_missing.title".localized, info: "alert.php_formula_missing.info".localized, style: .warning) BetterAlert()
.withInformation(
title: "alert.php_formula_missing.title".localized,
subtitle: "alert.php_formula_missing.info".localized
)
.withPrimary(text: "OK")
.show()
return return
} }
if !Alert.present(
messageText: "alert.fix_my_valet.title".localized,
informativeText: "alert.fix_my_valet.info".localized(PhpEnv.brewPhpVersion), if !BetterAlert()
buttonTitle: "alert.fix_my_valet.ok".localized, .withInformation(
secondButtonTitle: "alert.fix_my_valet.cancel".localized, title: "alert.fix_my_valet.title".localized,
style: .warning subtitle: "alert.fix_my_valet.info".localized(PhpEnv.brewPhpVersion)
) { )
.withPrimary(text: "alert.fix_my_valet.ok".localized)
.withSecondary(text: "alert.fix_my_valet.cancel".localized)
.didSelectPrimary()
{
Log.info("The user has chosen to abort Fix My Valet") Log.info("The user has chosen to abort Fix My Valet")
return return
} }
@ -281,10 +292,14 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
asyncExecution { asyncExecution {
Actions.fixMyValet() Actions.fixMyValet()
} success: { } success: {
Alert.notify( BetterAlert()
message: "alert.fix_my_valet_done.title".localized, .withInformation(
info: "alert.fix_my_valet_done.info".localized title: "alert.fix_my_valet_done.title".localized,
subtitle: "alert.fix_my_valet_done.subtitle".localized,
description: "alert.fix_my_valet_done.desc".localized
) )
.withPrimary(text: "alert.fix_my_valet.ok".localized)
.show()
} }
} }

View File

@ -65,4 +65,8 @@ class BetterAlertVC: NSViewController {
NSApplication.shared.stopModal(withCode: code) NSApplication.shared.stopModal(withCode: code)
} }
deinit {
Log.perf("A BetterAlert has been deinitialized.")
}
} }

View File

@ -218,7 +218,8 @@ problem manually, using your own Terminal app (this just shows you the output)."
// Fix My Valet Done // Fix My Valet Done
"alert.fix_my_valet_done.title" = "Fix My Valet has completed its operations."; "alert.fix_my_valet_done.title" = "Fix My Valet has completed its operations.";
"alert.fix_my_valet_done.info" = "All appropriate services have been stopped and the correct ones restarted, and the latest version of PHP should now be active. You can now try switching to another version of PHP.\n\nIf visiting sites still does not work, you may try running `valet install` again, this can fix a 502 issue (Bad Gateway).\n\nIf Valet is broken and you cannot run `valet install`, you may need to run `composer global update`. Please consult the FAQ on GitHub if you have further issues."; "alert.fix_my_valet_done.subtitle" = "All appropriate services have been stopped and the correct ones restarted, and the latest version of PHP should now be active. You can now try switching to another version of PHP.";
"alert.fix_my_valet_done.desc" = "If visiting sites still does not work, you may try running `valet install` again, this can fix a 502 issue (Bad Gateway).\n\nIf Valet is broken and you cannot run `valet install`, you may need to run `composer global update`. Please consult the FAQ on GitHub if you have further issues.";
// Restore Homebrew Permissions // Restore Homebrew Permissions
"alert.fix_homebrew_permissions.title" = "About \"Restore Homebrew Permissions\""; "alert.fix_homebrew_permissions.title" = "About \"Restore Homebrew Permissions\"";