From b041ca37be951155c6414c984c69279d4d443808 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sat, 27 May 2023 11:53:11 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Disable=20Sites=20menu=20item=20?= =?UTF-8?q?when=20Standalone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 10 ++++ phpmon/Domain/App/AppDelegate.swift | 18 ++++++ phpmon/Domain/App/Base.lproj/Main.storyboard | 38 ++++++------ phpmon/Domain/Menu/MainMenu+Startup.swift | 3 + .../PhpManager/FakeBrewFormulaeHandler.swift | 58 +++++++++++++++++++ .../SwiftUI/PhpManager/PhpFormulaeView.swift | 58 +++---------------- 6 files changed, 119 insertions(+), 66 deletions(-) create mode 100644 phpmon/Domain/SwiftUI/PhpManager/FakeBrewFormulaeHandler.swift diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index ed8e4a3..3915b16 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -554,6 +554,10 @@ C485707B28BF458900539B36 /* VersionPopoverView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44264BF2850BD2A007400F1 /* VersionPopoverView.swift */; }; C485707C28BF459500539B36 /* NoWarningsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C708C28AA7F7900E8D498 /* NoWarningsView.swift */; }; C485707D28BF45A200539B36 /* WarningView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4297F7928970D59004C4630 /* WarningView.swift */; }; + C489E0BB2A220A4200323F5E /* FakeBrewFormulaeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C489E0BA2A220A4200323F5E /* FakeBrewFormulaeHandler.swift */; }; + C489E0BC2A220A4200323F5E /* FakeBrewFormulaeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C489E0BA2A220A4200323F5E /* FakeBrewFormulaeHandler.swift */; }; + C489E0BD2A220A4200323F5E /* FakeBrewFormulaeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C489E0BA2A220A4200323F5E /* FakeBrewFormulaeHandler.swift */; }; + C489E0BE2A220A4200323F5E /* FakeBrewFormulaeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C489E0BA2A220A4200323F5E /* FakeBrewFormulaeHandler.swift */; }; C48D0C9325CC804200CC7490 /* XibLoadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C48D0C9225CC804200CC7490 /* XibLoadable.swift */; }; C48D6C70279CD2AC00F26D7E /* VersionNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = C48D6C6F279CD2AC00F26D7E /* VersionNumber.swift */; }; C48D6C71279CD2AC00F26D7E /* VersionNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = C48D6C6F279CD2AC00F26D7E /* VersionNumber.swift */; }; @@ -980,6 +984,7 @@ C47DF1AE299D5A3B0007055D /* LoginItemManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginItemManager.swift; sourceTree = ""; }; C4811D2322D70A4700B5F6B3 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = ""; }; C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = ""; }; + C489E0BA2A220A4200323F5E /* FakeBrewFormulaeHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeBrewFormulaeHandler.swift; sourceTree = ""; }; C48D0C9225CC804200CC7490 /* XibLoadable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XibLoadable.swift; sourceTree = ""; }; C48D6C6F279CD2AC00F26D7E /* VersionNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionNumber.swift; sourceTree = ""; }; C48D6C73279CD3E400F26D7E /* PhpVersionNumberTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhpVersionNumberTest.swift; sourceTree = ""; }; @@ -1405,6 +1410,7 @@ C48DDD0C29C75C9E00D032D9 /* BlockingOverlayView.swift */, C40D72592A018ACC0054A067 /* PhpFormulaeStatus.swift */, C40D725E2A018AE30054A067 /* BrewFormulaUI.swift */, + C489E0BA2A220A4200323F5E /* FakeBrewFormulaeHandler.swift */, ); path = PhpManager; sourceTree = ""; @@ -2282,6 +2288,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C489E0BB2A220A4200323F5E /* FakeBrewFormulaeHandler.swift in Sources */, C41ADCE82970CCC700120423 /* FSNotifier.swift in Sources */, C47699EF28A2F2A30060FEB8 /* WarningManager.swift in Sources */, C490E3BB29BCA375006D2DE6 /* Measurements.swift in Sources */, @@ -2638,6 +2645,7 @@ C471E7FD28F9BACE0021E251 /* HomebrewService.swift in Sources */, C471E7E428F9BAC20021E251 /* Helpers.swift in Sources */, C4CB6E67292C362C002E9027 /* Homebrew.swift in Sources */, + C489E0BD2A220A4200323F5E /* FakeBrewFormulaeHandler.swift in Sources */, C45E2A77291992DA005C7CFD /* FeatureTestCase.swift in Sources */, C471E82028F9BB290021E251 /* NginxConfigurationFile.swift in Sources */, C471E7D428F9BA8F0021E251 /* ActiveFileSystem.swift in Sources */, @@ -2687,6 +2695,7 @@ C4B79EB929CA387F00A483EE /* BrewFormulaeHandler.swift in Sources */, C471E8A428F9BB8F0021E251 /* AppDelegate+Notifications.swift in Sources */, C490E3B329BC9FEA006D2DE6 /* ProgressWindowView.swift in Sources */, + C489E0BE2A220A4200323F5E /* FakeBrewFormulaeHandler.swift in Sources */, C490E3B229BC9FE8006D2DE6 /* ProgressViewSubject.swift in Sources */, C471E8A528F9BB8F0021E251 /* AppDelegate+InterApp.swift in Sources */, C471E8A628F9BB8F0021E251 /* App.swift in Sources */, @@ -2973,6 +2982,7 @@ C4B97B79275CF1B5003F3378 /* App+ActivationPolicy.swift in Sources */, C4E2E86528FC2F1B003B070C /* XCPMApplication.swift in Sources */, C4E49DE828F764050026AC4E /* ActiveCommand.swift in Sources */, + C489E0BC2A220A4200323F5E /* FakeBrewFormulaeHandler.swift in Sources */, C4CE3BBB27B324230086CA49 /* MainMenu+Switcher.swift in Sources */, C4B79ECC29CA475900A483EE /* RemovePhpVersionCommand.swift in Sources */, C4FD87AA29AB9ABD0002D701 /* PhpConfigChecker.swift in Sources */, diff --git a/phpmon/Domain/App/AppDelegate.swift b/phpmon/Domain/App/AppDelegate.swift index 6b4f2cc..ca73add 100644 --- a/phpmon/Domain/App/AppDelegate.swift +++ b/phpmon/Domain/App/AppDelegate.swift @@ -11,6 +11,10 @@ import UserNotifications @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate { + static var instance: AppDelegate { + return NSApplication.shared.delegate as! AppDelegate + } + // MARK: - Variables /** @@ -121,4 +125,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele await menu.startup() } } + + // MARK: - Menu Items + + @IBOutlet weak var menuItemSites: NSMenuItem! + + /** + Ensure relevant menu items in the main menu bar (not the pop-up menu) + are disabled or hidden when needed. + */ + public func configureMenuItems(standalone: Bool) { + if standalone { + menuItemSites.isHidden = true + } + } } diff --git a/phpmon/Domain/App/Base.lproj/Main.storyboard b/phpmon/Domain/App/Base.lproj/Main.storyboard index d7aa2aa..a2302ba 100644 --- a/phpmon/Domain/App/Base.lproj/Main.storyboard +++ b/phpmon/Domain/App/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -34,18 +34,6 @@ - - - - - - - - - - - - @@ -82,12 +70,12 @@ - + - + @@ -297,6 +285,18 @@ + + + + + + + + + + + + @@ -317,7 +317,11 @@ - + + + + + diff --git a/phpmon/Domain/Menu/MainMenu+Startup.swift b/phpmon/Domain/Menu/MainMenu+Startup.swift index cab3f64..8d06353 100644 --- a/phpmon/Domain/Menu/MainMenu+Startup.swift +++ b/phpmon/Domain/Menu/MainMenu+Startup.swift @@ -88,6 +88,9 @@ extension MainMenu { // Load the global hotkey App.shared.loadGlobalHotkey() + // Set up menu items + AppDelegate.instance.configureMenuItems(standalone: !Valet.installed) + if Valet.installed { // Preload all sites await Valet.shared.startPreloadingSites() diff --git a/phpmon/Domain/SwiftUI/PhpManager/FakeBrewFormulaeHandler.swift b/phpmon/Domain/SwiftUI/PhpManager/FakeBrewFormulaeHandler.swift new file mode 100644 index 0000000..759fdd1 --- /dev/null +++ b/phpmon/Domain/SwiftUI/PhpManager/FakeBrewFormulaeHandler.swift @@ -0,0 +1,58 @@ +// +// FakeBrewFormulaeHandler.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 27/05/2023. +// Copyright © 2023 Nico Verbruggen. All rights reserved. +// + +import Foundation + +class FakeBrewFormulaeHandler: HandlesBrewFormulae { + public func loadPhpVersions(loadOutdated: Bool) async -> [BrewFormula] { + return [ + BrewFormula( + name: "php", + displayName: "PHP 8.2", + installedVersion: "8.2.3", + upgradeVersion: "8.2.4" + ), + BrewFormula( + name: "php@8.1", + displayName: "PHP 8.1", + installedVersion: "8.1.17", + upgradeVersion: nil + ), + BrewFormula( + name: "php@8.0", + displayName: "PHP 8.0", + installedVersion: nil, + upgradeVersion: nil + ), + BrewFormula( + name: "php@7.4", + displayName: "PHP 7.4", + installedVersion: nil, + upgradeVersion: nil + ), + BrewFormula( + name: "php@7.3", + displayName: "PHP 7.3", + installedVersion: nil, + upgradeVersion: nil + ), + BrewFormula( + name: "php@7.2", + displayName: "PHP 7.2", + installedVersion: nil, + upgradeVersion: nil + ), + BrewFormula( + name: "php@7.1", + displayName: "PHP 7.1", + installedVersion: nil, + upgradeVersion: nil + ) + ] + } +} diff --git a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift index 7403737..a7088d7 100644 --- a/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift +++ b/phpmon/Domain/SwiftUI/PhpManager/PhpFormulaeView.swift @@ -189,6 +189,15 @@ struct PhpFormulaeView: View { } public func runCommand(_ command: InstallAndUpgradeCommand) async { + if PhpEnvironments.shared.isBusy { + self.presentErrorAlert( + title: "phpman.busy.title".localized, + description: "phpman.busy.desc".localized, + button: "generic.ok".localized + ) + return + } + do { self.setBusyStatus(true) try await command.execute { progress in @@ -349,52 +358,3 @@ struct PhpFormulaeView_Previews: PreviewProvider { ).frame(width: 600, height: 600) } } - -class FakeBrewFormulaeHandler: HandlesBrewFormulae { - public func loadPhpVersions(loadOutdated: Bool) async -> [BrewFormula] { - return [ - BrewFormula( - name: "php", - displayName: "PHP 8.2", - installedVersion: "8.2.3", - upgradeVersion: "8.2.4" - ), - BrewFormula( - name: "php@8.1", - displayName: "PHP 8.1", - installedVersion: "8.1.17", - upgradeVersion: nil - ), - BrewFormula( - name: "php@8.0", - displayName: "PHP 8.0", - installedVersion: nil, - upgradeVersion: nil - ), - BrewFormula( - name: "php@7.4", - displayName: "PHP 7.4", - installedVersion: nil, - upgradeVersion: nil - ), - BrewFormula( - name: "php@7.3", - displayName: "PHP 7.3", - installedVersion: nil, - upgradeVersion: nil - ), - BrewFormula( - name: "php@7.2", - displayName: "PHP 7.2", - installedVersion: nil, - upgradeVersion: nil - ), - BrewFormula( - name: "php@7.1", - displayName: "PHP 7.1", - installedVersion: nil, - upgradeVersion: nil - ) - ] - } -}