From ffa22eea25ddbda518908cf1ac8428b0114b2fd8 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sun, 6 Feb 2022 17:56:16 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Cleanup,=20ensure=20all=20tests?= =?UTF-8?q?=20pass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 6 ++++-- phpmon/Domain/Helpers/Alert.swift | 9 ++++++++- phpmon/Domain/Menu/MainMenu+Async.swift | 24 ++++++++++++++---------- phpmon/Domain/Menu/MainMenu.swift | 4 +--- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 695fdcb..7617b19 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -184,6 +184,7 @@ C4F30B09278E1A0E00755FCE /* CustomPrefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4C3ED4227834C5200AB15D8 /* CustomPrefs.swift */; }; C4F30B0A278E1A1A00755FCE /* ComposerJson.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D89BC52783C99400A02B68 /* ComposerJson.swift */; }; C4F30B0B278E203C00755FCE /* MainMenu+Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4C3ED402783497000AB15D8 /* MainMenu+Startup.swift */; }; + C4F319C927B034A500AFF46F /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DEB7D327A5D60B00834718 /* Stats.swift */; }; C4F7809C25D80344000DBC97 /* CommandTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F7809B25D80344000DBC97 /* CommandTest.swift */; }; C4F780A825D80AE8000DBC97 /* php.ini in Resources */ = {isa = PBXBuildFile; fileRef = C4F780A725D80AE8000DBC97 /* php.ini */; }; C4F780AE25D80B37000DBC97 /* ExtensionParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F780AD25D80B37000DBC97 /* ExtensionParserTest.swift */; }; @@ -1011,6 +1012,7 @@ C43A8A2425D9D20D00591B77 /* BrewJsonParserTest.swift in Sources */, C4F780CA25D80B75000DBC97 /* HomebrewPackage.swift in Sources */, C4C8E81C276F54E5003AC782 /* PhpConfigWatcher.swift in Sources */, + C4F319C927B034A500AFF46F /* Stats.swift in Sources */, C4F30B04278E16BA00755FCE /* HomebrewService.swift in Sources */, C4AF9F7B2754499000D44ED0 /* Valet.swift in Sources */, C4F780C025D80B6E000DBC97 /* Startup.swift in Sources */, @@ -1250,7 +1252,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 590; + CURRENT_PROJECT_VERSION = 600; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; @@ -1275,7 +1277,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 590; + CURRENT_PROJECT_VERSION = 600; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; diff --git a/phpmon/Domain/Helpers/Alert.swift b/phpmon/Domain/Helpers/Alert.swift index 2fc552a..25327a7 100644 --- a/phpmon/Domain/Helpers/Alert.swift +++ b/phpmon/Domain/Helpers/Alert.swift @@ -51,6 +51,9 @@ class Alert { } } + /** + Notify the user about something by showing an alert. + */ public static func notify(message: String, info: String, style: NSAlert.Style = .informational) { _ = present( messageText: message, @@ -61,7 +64,11 @@ class Alert { ) } - public static func notifyAbout(error: Error&AlertableError) { + /** + 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, diff --git a/phpmon/Domain/Menu/MainMenu+Async.swift b/phpmon/Domain/Menu/MainMenu+Async.swift index 9933b13..a3f2094 100644 --- a/phpmon/Domain/Menu/MainMenu+Async.swift +++ b/phpmon/Domain/Menu/MainMenu+Async.swift @@ -20,13 +20,19 @@ extension MainMenu { } /** - Attempts asynchronous execution of a callback that may throw an Error. + Attempts asynchronous execution of a callback that may throw an `Error`. While the callback is being executed, the UI will be marked as busy. - - Parameter execute: Callback of the work that needs to happen. - - Parameter success: Callback that is fired when all was OK. - - Parameter failure: Callback that is fired when an Error was thrown. + (Preferably, if an `Error` is thrown, it should also be an `AlertableError`, + which will make presenting errors easier.) + + - Parameter execute: Required callback of the work that needs to happen. + + - Parameter success: Optional callback that is fired when all was OK. + - Parameter failure: Optional callback that is fired when an `Error` was thrown. - Parameter behaviours: Various behaviours that can be tweaked, but usually best left to the default. + The default will set the UI to busy, reload PHP info, update the menu bar, + and broadcast to the services view that the list has been updated. */ func asyncExecution( _ execute: @escaping () throws -> Void, @@ -42,9 +48,11 @@ extension MainMenu { if behaviours.contains(.reloadsPhpInstallation) { PhpEnv.shared.isBusy = true } + if behaviours.contains(.setsBusyUI) { setBusyImage() } + DispatchQueue.global(qos: .userInitiated).async { [unowned self] in var error: Error? = nil @@ -60,13 +68,9 @@ extension MainMenu { } if behaviours.contains(.updatesMenuBarContents) { - // Refresh the entire menu bar menu's contents updatePhpVersionInStatusBar() - } else { - // We do still need to refresh the icon based on the busy state - if behaviours.contains(.setsBusyUI) { - refreshIcon() - } + } else if behaviours.contains(.setsBusyUI) { + refreshIcon() } if behaviours.contains(.broadcastServicesUpdate) { diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 8125eb1..a3e86a9 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -160,9 +160,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { style: .warning ) } failure: { error in - let error = error as! HomebrewPermissionError - Alert.notifyAbout(error: error) - + Alert.notify(about: error as! HomebrewPermissionError) } }