From 4e5b178e3643049cf3655308d87bb23cb5ac43eb Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 12 Aug 2022 20:50:27 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20WIP:=20Tweaks=20to=20PHP=20Docto?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcschemes/PHP Monitor.xcscheme | 5 ++ phpmon/Domain/Menu/StatusMenu.swift | 2 +- .../SwiftUI/Warning/WarningListView.swift | 46 ++++++++++++----- .../Domain/SwiftUI/Warning/WarningView.swift | 49 ++++++++++--------- phpmon/Domain/Warnings/Warning.swift | 12 ++--- phpmon/Domain/Warnings/WarningManager.swift | 34 ++++++++----- .../Warnings/WarningsWindowController.swift | 4 +- phpmon/Localizable.strings | 14 +++--- 8 files changed, 105 insertions(+), 61 deletions(-) diff --git a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor.xcscheme b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor.xcscheme index 6d711af..b6917c2 100644 --- a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor.xcscheme +++ b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor.xcscheme @@ -68,6 +68,11 @@ + + Bool let name: String - let titleText: String - let descriptionText: String + let title: String + let paragraphs: [String] let url: String? init( command: @escaping () async -> Bool, name: String, - titleText: String, - descriptionText: String, + title: String, + paragraphs: [String], url: String? ) { self.command = command self.name = name - self.titleText = titleText - self.descriptionText = descriptionText + self.title = title + self.paragraphs = paragraphs self.url = url } diff --git a/phpmon/Domain/Warnings/WarningManager.swift b/phpmon/Domain/Warnings/WarningManager.swift index 92260a0..1365fcc 100644 --- a/phpmon/Domain/Warnings/WarningManager.swift +++ b/phpmon/Domain/Warnings/WarningManager.swift @@ -13,25 +13,31 @@ class WarningManager { static var shared = WarningManager() + init() { + if isRunningSwiftUIPreview { + self.warnings = self.evaluations + } + } + public let evaluations: [Warning] = [ - Warning( - command: { - !FileManager.default.isWritableFile(atPath: "/usr/local/bin/") - }, - name: "`/usr/local/bin` not writable", - titleText: "warnings.helper_permissions.title", - descriptionText: "warnings.helper_permissions.description", - url: nil - ), Warning( command: { return Shell.pipe("sysctl -n sysctl.proc_translated") .trimmingCharacters(in: .whitespacesAndNewlines) == "1" }, name: "Running PHP Monitor with Rosetta on M1", - titleText: "warnings.arm_compatibility.title", - descriptionText: "warnings.arm_compatibility.description", + title: "warnings.arm_compatibility.title", + paragraphs: ["warnings.arm_compatibility.description"], url: "https://github.com/nicoverbruggen/phpmon/wiki/PHP-Monitor-and-Apple-Silicon" + ), + Warning( + command: { + !FileManager.default.isWritableFile(atPath: "/usr/local/bin/") + }, + name: "`/usr/local/bin` not writable", + title: "warnings.helper_permissions.title", + paragraphs: ["warnings.helper_permissions.description", "warnings.helper_permissions.unavailable"], + url: "https://github.com/nicoverbruggen/phpmon/wiki/PHP-Monitor-helper-binaries" ) ] @@ -50,6 +56,7 @@ class WarningManager { */ func checkEnvironment() async { self.warnings = [] + for check in self.evaluations { if await check.applies() { Log.info("[WARNING] \(check.name)") @@ -57,6 +64,11 @@ class WarningManager { continue } } + + // For debugging purposes, we may wish to see all possible evaluations listed + if ProcessInfo.processInfo.environment["EXTREME_DOCTOR_MODE"] != nil { + self.warnings = self.evaluations + } } } diff --git a/phpmon/Domain/Warnings/WarningsWindowController.swift b/phpmon/Domain/Warnings/WarningsWindowController.swift index 65b1c25..4fda741 100644 --- a/phpmon/Domain/Warnings/WarningsWindowController.swift +++ b/phpmon/Domain/Warnings/WarningsWindowController.swift @@ -22,12 +22,12 @@ class WarningsWindowController: PMWindowController { windowController.window = NSWindow() guard let window = windowController.window else { return } - window.title = "warnings.title".localized + window.title = "" window.styleMask = [.titled, .closable, .miniaturizable] window.titlebarAppearsTransparent = true window.delegate = delegate ?? windowController window.contentView = NSHostingView(rootView: WarningListView()) - window.setContentSize(NSSize(width: 600, height: 300)) + window.setContentSize(NSSize(width: 600, height: 480)) App.shared.warningsWindowController = windowController } diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index f36d415..841c6cf 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -55,8 +55,7 @@ "mi_detected_extensions" = "Detected Extensions"; "mi_no_extensions_detected" = "No additional extensions detected."; -"mi_warning" = "⚠️ %i Warning"; -"mi_warnings" = "⚠️ %i Warnings..."; +"mi_warnings" = "(%i) PHP Doctor..."; "mi_valet" = "Laravel Valet"; "mi_domain_list" = "View Domains List..."; @@ -509,12 +508,15 @@ If you are seeing this message but are confused why this folder has gone missing // WARNINGS -"warnings.title" = "Warnings"; +"warnings.title" = "PHP Doctor"; +"warnings.description" = "**PHP Doctor** will suggest improvements to your active system configuration."; +"warnings.disclaimer" = "You may choose to hide all recommendations from the PHP Monitor menu in Preferences, but it is recommended that you deal with all actionable items."; -"warnings.helper_permissions.title" = "Helpers could not be written!"; -"warnings.helper_permissions.description" = "The helper files in `/usr/local/bin` could not be written because PHP Monitor does not have permission to write there."; +"warnings.helper_permissions.title" = "PHP Monitor’s helpers are currently unavailable."; +"warnings.helper_permissions.description" = "PHP Monitor comes with various helper binaries. Using these binaries allows you to easily invoke a specific version of PHP without switching the linked PHP version."; +"warnings.helper_permissions.unavailable" = "However, these helpers are currently *unavailable* because PHP Monitor could not create the required symlinks (alternatively, you could add PHP Monitor's helper directory to your `PATH` variable to make this warning go away as well)."; -"warnings.arm_compatibility.title" = "You are running PHP Monitor using Rosetta"; +"warnings.arm_compatibility.title" = "You are running PHP Monitor using Rosetta on Apple Silicon, which means your PHP environment is also running via Rosetta."; "warnings.arm_compatibility.description" = "You appear to be running an ARM-compatible version of macOS, but you are currently running PHP Monitor using Rosetta. While this will work correctly, it is recommended that you use the native version of Homebrew."; // ONBOARDING