diff --git a/phpmon/Domain/App/Base.lproj/Main.storyboard b/phpmon/Domain/App/Base.lproj/Main.storyboard
index be2b676..e1013e7 100644
--- a/phpmon/Domain/App/Base.lproj/Main.storyboard
+++ b/phpmon/Domain/App/Base.lproj/Main.storyboard
@@ -492,11 +492,11 @@
-
+
-
+
-
+
diff --git a/phpmon/Domain/App/Startup.swift b/phpmon/Domain/App/Startup.swift
index 87e7ba8..b692e5c 100644
--- a/phpmon/Domain/App/Startup.swift
+++ b/phpmon/Domain/App/Startup.swift
@@ -49,7 +49,7 @@ class Startup {
private func showAlert(for check: EnvironmentCheck) {
DispatchQueue.main.async {
if check.requiresAppRestart {
- _ = BetterAlert.make()
+ BetterAlert()
.withInformation(
title: check.titleText,
subtitle: check.subtitleText,
@@ -57,14 +57,17 @@ class Startup {
)
.withPrimary(text: check.buttonText, action: { _ in
exit(1)
- }).present()
+ }).show()
}
- Alert.notify(
- message: check.titleText,
- info: check.descriptionText,
- style: .critical
- )
+ BetterAlert()
+ .withInformation(
+ title: check.titleText,
+ subtitle: check.subtitleText,
+ description: check.descriptionText
+ )
+ .withPrimary(text: "OK")
+ .show()
}
}
@@ -100,9 +103,8 @@ class Startup {
command: { return !Filesystem.fileExists(Paths.php) },
name: "`\(Paths.php)` exists",
titleText: "startup.errors.php_binary.title".localized,
- descriptionText: "startup.errors.php_binary.desc".localized(
- Paths.php
- )
+ subtitleText: "startup.errors.php_binary.subtitle".localized,
+ descriptionText: "startup.errors.php_binary.desc".localized(Paths.php)
),
EnvironmentCheck(
command: { return !Shell.pipe("ls \(Paths.optPath) | grep php").contains("php") },
diff --git a/phpmon/Domain/Menu/MainMenu+Startup.swift b/phpmon/Domain/Menu/MainMenu+Startup.swift
index 8625ee6..0e048bd 100644
--- a/phpmon/Domain/Menu/MainMenu+Startup.swift
+++ b/phpmon/Domain/Menu/MainMenu+Startup.swift
@@ -102,16 +102,19 @@ extension MainMenu {
*/
private func onEnvironmentFail() {
DispatchQueue.main.async { [self] in
- let close = Alert.present(
- messageText: "alert.cannot_start.title".localized,
- informativeText: "alert.cannot_start.info".localized,
- buttonTitle: "alert.cannot_start.close".localized,
- secondButtonTitle: "alert.cannot_start.retry".localized
- )
- if (close) {
- exit(1)
- }
+ BetterAlert()
+ .withInformation(
+ title: "alert.cannot_start.title".localized,
+ subtitle: "alert.cannot_start.subtitle".localized,
+ description: "alert.cannot_start.description".localized
+ )
+ .withPrimary(text: "alert.cannot_start.retry".localized)
+ .withSecondary(text: "alert.cannot_start.close".localized, action: { vc in
+ vc.close(with: .alertSecondButtonReturn)
+ exit(1)
+ })
+ .show()
Task { await startup() }
}
diff --git a/phpmon/Domain/Notice/BetterAlert.swift b/phpmon/Domain/Notice/BetterAlert.swift
index 40f3a59..3fa6e11 100644
--- a/phpmon/Domain/Notice/BetterAlert.swift
+++ b/phpmon/Domain/Notice/BetterAlert.swift
@@ -17,15 +17,16 @@ class BetterAlert {
return self.windowController.contentViewController as! BetterAlertVC
}
- public static func make() -> BetterAlert {
+ init() {
let storyboard = NSStoryboard(name: "Main" , bundle : nil)
- let notice = BetterAlert()
- notice.windowController = storyboard.instantiateController(
+ self.windowController = storyboard.instantiateController(
withIdentifier: "noticeWindow"
) as? NSWindowController
-
- return notice
+ }
+
+ public static func make() -> BetterAlert {
+ return BetterAlert()
}
public func withPrimary(
@@ -74,9 +75,25 @@ class BetterAlert {
return self
}
- public func present() -> NSApplication.ModalResponse {
+ /**
+ Shows the modal and returns a ModalResponse.
+ If you wish to simply show the alert and disregard the outcome, use `show`.
+ */
+ public func runModal() -> NSApplication.ModalResponse {
NSApp.activate(ignoringOtherApps: true)
windowController.window?.makeKeyAndOrderFront(nil)
return NSApplication.shared.runModal(for: windowController.window!)
}
+
+ /** Shows the modal and returns true if the user pressed the primary button. */
+ public func didSelectPrimary() -> Bool {
+ return self.runModal() == .alertFirstButtonReturn
+ }
+
+ /**
+ Shows the modal and does not return anything.
+ */
+ public func show() {
+ _ = self.runModal()
+ }
}
diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings
index f1ab414..dab3bc4 100644
--- a/phpmon/Localizable.strings
+++ b/phpmon/Localizable.strings
@@ -234,9 +234,10 @@ problem manually, using your own Terminal app (this just shows you the output)."
"alert.php_fpm_broken.info" = "PHP Monitor has determined that there are issues with your PHP-FPM config: it's not pointing to the Valet socket. This will result in 502 Bad Gateway if you visit websites linked via Valet.\n\nYou can usually fix this by running\n`valet install`, which updates your\n PHP-FPM configuration.";
// PHP Monitor Cannot Start
-"alert.cannot_start.title" = "PHP Monitor cannot start";
-"alert.cannot_start.info" = "The issue you were just notified about is keeping PHP Monitor from functioning correctly. Please fix the issue and restart PHP Monitor. After clicking on OK, PHP Monitor will close.\n\nIf you have fixed the issue (or don't remember what the exact issue is) you can click on Retry, which will have PHP Monitor retry the startup checks.";
-"alert.cannot_start.close" = "Close";
+"alert.cannot_start.title" = "PHP Monitor cannot start due to a configuration problem";
+"alert.cannot_start.subtitle" = "The issue you were just notified about is keeping PHP Monitor from functioning correctly.";
+"alert.cannot_start.description" = "You might not need to quit PHP Monitor and restart it. If you have fixed the issue (or don't remember what the exact issue is) you can click on Retry, which will have PHP Monitor retry the startup checks.";
+"alert.cannot_start.close" = "Quit";
"alert.cannot_start.retry" = "Retry";
// PHP alias issue
@@ -262,7 +263,9 @@ You can do this by running `composer global update` in your terminal. After that
/// 1. PHP binary not found
"startup.errors.php_binary.title" = "PHP is not correctly installed";
-"startup.errors.php_binary.desc" = "You must install PHP via brew. Try running `which php` in Terminal, it should return `%@`. The app will not work correctly until you resolve this issue. (Usually `brew link php` resolves this issue.)";
+"startup.errors.php_binary.subtitle" = "You must install PHP via Homebrew. The app will not work correctly until you resolve this issue.";
+"startup.errors.php_binary.desc" = "Usually running `brew link php` in your Terminal will resolve this issue.\n\nTo diagnose what is wrong, you can try running `which php` in your Terminal, it should return `%@`.";
+
/// 2. PHP not found in /usr/local/opt or /opt/homebrew/opt
"startup.errors.php_opt.title" = "PHP is not correctly installed";