diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 7367a73..bf15bdf 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ C42295DD2358D02000E263B2 /* Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42295DC2358D02000E263B2 /* Command.swift */; }; C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46FA23E246C358E00944F05 /* StringExtension.swift */; }; C473319F2470923A009A0597 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C473319E2470923A009A0597 /* Localizable.strings */; }; + C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47331A1247093B7009A0597 /* StatusMenu.swift */; }; C476FF9822B0DD830098105B /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C476FF9722B0DD830098105B /* Alert.swift */; }; C4811D2422D70A4700B5F6B3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2322D70A4700B5F6B3 /* App.swift */; }; C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; }; @@ -39,6 +40,7 @@ C42295DC2358D02000E263B2 /* Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Command.swift; sourceTree = ""; }; C46FA23E246C358E00944F05 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; C473319E2470923A009A0597 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = ""; }; + C47331A1247093B7009A0597 /* StatusMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusMenu.swift; sourceTree = ""; }; C476FF9722B0DD830098105B /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.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 = ""; }; @@ -96,6 +98,7 @@ C41E181722CB61EB0072CF09 /* Classes */ = { isa = PBXGroup; children = ( + C47331A0247093AC009A0597 /* Menu */, C4811D2722D70D8E00B5F6B3 /* Commands */, C4811D2822D70D9C00B5F6B3 /* Helpers */, ); @@ -110,6 +113,14 @@ path = "View Controllers"; sourceTree = ""; }; + C47331A0247093AC009A0597 /* Menu */ = { + isa = PBXGroup; + children = ( + C47331A1247093B7009A0597 /* StatusMenu.swift */, + ); + path = Menu; + sourceTree = ""; + }; C4811D2622D70CEF00B5F6B3 /* Singletons */ = { isa = PBXGroup; children = ( @@ -231,6 +242,7 @@ C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */, C41C1B4B22B019FF00E7CF16 /* PhpVersion.swift in Sources */, C476FF9822B0DD830098105B /* Alert.swift in Sources */, + C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */, C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */, C4EE188422D3386B00E126E5 /* Constants.swift in Sources */, ); diff --git a/phpmon/Classes/Menu/StatusMenu.swift b/phpmon/Classes/Menu/StatusMenu.swift new file mode 100644 index 0000000..d49e66f --- /dev/null +++ b/phpmon/Classes/Menu/StatusMenu.swift @@ -0,0 +1,88 @@ +// +// MainMenuBuilder.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 16/05/2020. +// Copyright © 2020 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +class StatusMenu : NSMenu { + + public func addPhpVersionMenuItems() + { + var string = "We are not sure what version of PHP you are running." + if (App.shared.currentVersion != nil) { + if (!App.shared.currentVersion!.error) { + string = "You are running PHP \(App.shared.currentVersion!.long)" + self.addItem(NSMenuItem(title: string, action: nil, keyEquivalent: "")) + } else { + // in case of an error show the error message + self.addItem(NSMenuItem(title: "Oof! It appears your PHP installation is broken...", action: nil, keyEquivalent: "")) + self.addItem(NSMenuItem(title: "Try running `php -v` in your terminal.", action: nil, keyEquivalent: "")) + self.addItem(NSMenuItem(title: "You could also try switching to another version.", action: nil, keyEquivalent: "")) + self.addItem(NSMenuItem(title: "Running `brew reinstall php` (or for the equivalent version) might help.", action: nil, keyEquivalent: "")) + } + } + } + + public func addPhpActionMenuItems() + { + if (App.shared.availablePhpVersions.count > 0 && !App.shared.busy) { + var shortcutKey = 1 + for index in (0.. 0 && !App.shared.busy) { - var shortcutKey = 1 - for index in (0.. Void, _ completion: @escaping () -> Void = {}) { @@ -147,7 +99,7 @@ class MainMenu: NSObject, NSWindowDelegate { } } - // MARK: - Callable via Obj-C (#selector) + // MARK: - Actions & Menu Manipulation @objc func updatePhpVersionInStatusBar() { App.shared.currentVersion = PhpVersion() @@ -245,6 +197,12 @@ class MainMenu: NSObject, NSWindowDelegate { NSApplication.shared.orderFrontStandardAboutPanel() } + @objc public func terminateApp() { + NSApplication.shared.terminate(nil) + } + + // MARK: - Cleanup when window closes + func windowWillClose(_ notification: Notification) { App.shared.windowController = nil Shell.user.delegate = nil