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

👌 Improve initial alert

This commit is contained in:
2022-02-17 09:59:50 +01:00
parent bc27a4d25a
commit 115863f1ee
5 changed files with 57 additions and 32 deletions

View File

@ -492,11 +492,11 @@
<scene sceneID="y9E-bB-wIG"> <scene sceneID="y9E-bB-wIG">
<objects> <objects>
<viewController storyboardIdentifier="noticeVC" id="hkw-9V-NxP" customClass="BetterAlertVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController"> <viewController storyboardIdentifier="noticeVC" id="hkw-9V-NxP" customClass="BetterAlertVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" misplaced="YES" id="UPH-hV-Naz"> <view key="view" id="UPH-hV-Naz">
<rect key="frame" x="0.0" y="0.0" width="520" height="212"/> <rect key="frame" x="0.0" y="0.0" width="520" height="212"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<visualEffectView blendingMode="behindWindow" material="underWindowBackground" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="JVG-5w-fPd"> <visualEffectView blendingMode="behindWindow" material="popover" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="JVG-5w-fPd">
<rect key="frame" x="0.0" y="0.0" width="520" height="212"/> <rect key="frame" x="0.0" y="0.0" width="520" height="212"/>
</visualEffectView> </visualEffectView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TCp-nS-HN2"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TCp-nS-HN2">
@ -628,7 +628,7 @@ DQ
</viewController> </viewController>
<customObject id="5Ts-EZ-bJh" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> <customObject id="5Ts-EZ-bJh" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="38" y="1624.5"/> <point key="canvasLocation" x="38" y="1624"/>
</scene> </scene>
<!--Add SiteVC--> <!--Add SiteVC-->
<scene sceneID="6JC-H6-u4K"> <scene sceneID="6JC-H6-u4K">

View File

@ -49,7 +49,7 @@ class Startup {
private func showAlert(for check: EnvironmentCheck) { private func showAlert(for check: EnvironmentCheck) {
DispatchQueue.main.async { DispatchQueue.main.async {
if check.requiresAppRestart { if check.requiresAppRestart {
_ = BetterAlert.make() BetterAlert()
.withInformation( .withInformation(
title: check.titleText, title: check.titleText,
subtitle: check.subtitleText, subtitle: check.subtitleText,
@ -57,14 +57,17 @@ class Startup {
) )
.withPrimary(text: check.buttonText, action: { _ in .withPrimary(text: check.buttonText, action: { _ in
exit(1) exit(1)
}).present() }).show()
} }
Alert.notify( BetterAlert()
message: check.titleText, .withInformation(
info: check.descriptionText, title: check.titleText,
style: .critical subtitle: check.subtitleText,
) description: check.descriptionText
)
.withPrimary(text: "OK")
.show()
} }
} }
@ -100,9 +103,8 @@ class Startup {
command: { return !Filesystem.fileExists(Paths.php) }, command: { return !Filesystem.fileExists(Paths.php) },
name: "`\(Paths.php)` exists", name: "`\(Paths.php)` exists",
titleText: "startup.errors.php_binary.title".localized, titleText: "startup.errors.php_binary.title".localized,
descriptionText: "startup.errors.php_binary.desc".localized( subtitleText: "startup.errors.php_binary.subtitle".localized,
Paths.php descriptionText: "startup.errors.php_binary.desc".localized(Paths.php)
)
), ),
EnvironmentCheck( EnvironmentCheck(
command: { return !Shell.pipe("ls \(Paths.optPath) | grep php").contains("php") }, command: { return !Shell.pipe("ls \(Paths.optPath) | grep php").contains("php") },

View File

@ -102,16 +102,19 @@ extension MainMenu {
*/ */
private func onEnvironmentFail() { private func onEnvironmentFail() {
DispatchQueue.main.async { [self] in 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) { BetterAlert()
exit(1) .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() } Task { await startup() }
} }

View File

@ -17,15 +17,16 @@ class BetterAlert {
return self.windowController.contentViewController as! BetterAlertVC return self.windowController.contentViewController as! BetterAlertVC
} }
public static func make() -> BetterAlert { init() {
let storyboard = NSStoryboard(name: "Main" , bundle : nil) let storyboard = NSStoryboard(name: "Main" , bundle : nil)
let notice = BetterAlert() self.windowController = storyboard.instantiateController(
notice.windowController = storyboard.instantiateController(
withIdentifier: "noticeWindow" withIdentifier: "noticeWindow"
) as? NSWindowController ) as? NSWindowController
}
return notice
public static func make() -> BetterAlert {
return BetterAlert()
} }
public func withPrimary( public func withPrimary(
@ -74,9 +75,25 @@ class BetterAlert {
return self 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) NSApp.activate(ignoringOtherApps: true)
windowController.window?.makeKeyAndOrderFront(nil) windowController.window?.makeKeyAndOrderFront(nil)
return NSApplication.shared.runModal(for: windowController.window!) 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()
}
} }

View File

@ -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."; "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 // PHP Monitor Cannot Start
"alert.cannot_start.title" = "PHP Monitor cannot start"; "alert.cannot_start.title" = "PHP Monitor cannot start due to a configuration problem";
"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.subtitle" = "The issue you were just notified about is keeping PHP Monitor from functioning correctly.";
"alert.cannot_start.close" = "Close"; "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"; "alert.cannot_start.retry" = "Retry";
// PHP alias issue // 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 /// 1. PHP binary not found
"startup.errors.php_binary.title" = "PHP is not correctly installed"; "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 /// 2. PHP not found in /usr/local/opt or /opt/homebrew/opt
"startup.errors.php_opt.title" = "PHP is not correctly installed"; "startup.errors.php_opt.title" = "PHP is not correctly installed";