mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
👌 Avoid using sender.tag
This commit is contained in:
@ -25,6 +25,7 @@
|
|||||||
C476FF9822B0DD830098105B /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C476FF9722B0DD830098105B /* Alert.swift */; };
|
C476FF9822B0DD830098105B /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C476FF9722B0DD830098105B /* Alert.swift */; };
|
||||||
C4811D2422D70A4700B5F6B3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2322D70A4700B5F6B3 /* App.swift */; };
|
C4811D2422D70A4700B5F6B3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2322D70A4700B5F6B3 /* App.swift */; };
|
||||||
C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; };
|
C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; };
|
||||||
|
C486EFFC2586931100A02B2C /* PhpMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C486EFFB2586931100A02B2C /* PhpMenuItem.swift */; };
|
||||||
C4D8016622B1584700C6DA1B /* Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D8016522B1584700C6DA1B /* Startup.swift */; };
|
C4D8016622B1584700C6DA1B /* Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D8016522B1584700C6DA1B /* Startup.swift */; };
|
||||||
C4EE188422D3386B00E126E5 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4EE188322D3386B00E126E5 /* Constants.swift */; };
|
C4EE188422D3386B00E126E5 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4EE188322D3386B00E126E5 /* Constants.swift */; };
|
||||||
C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8C0A322D4F12C002EFE61 /* DateExtension.swift */; };
|
C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8C0A322D4F12C002EFE61 /* DateExtension.swift */; };
|
||||||
@ -52,6 +53,7 @@
|
|||||||
C476FF9722B0DD830098105B /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; };
|
C476FF9722B0DD830098105B /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; };
|
||||||
C4811D2322D70A4700B5F6B3 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
|
C4811D2322D70A4700B5F6B3 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
|
||||||
C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = "<group>"; };
|
C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = "<group>"; };
|
||||||
|
C486EFFB2586931100A02B2C /* PhpMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpMenuItem.swift; sourceTree = "<group>"; };
|
||||||
C4D8016522B1584700C6DA1B /* Startup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Startup.swift; sourceTree = "<group>"; };
|
C4D8016522B1584700C6DA1B /* Startup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Startup.swift; sourceTree = "<group>"; };
|
||||||
C4E713562570150F00007428 /* SECURITY.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = SECURITY.md; sourceTree = "<group>"; };
|
C4E713562570150F00007428 /* SECURITY.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = SECURITY.md; sourceTree = "<group>"; };
|
||||||
C4E713572570151400007428 /* docs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = docs; sourceTree = "<group>"; };
|
C4E713572570151400007428 /* docs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = docs; sourceTree = "<group>"; };
|
||||||
@ -139,6 +141,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
C47331A1247093B7009A0597 /* StatusMenu.swift */,
|
C47331A1247093B7009A0597 /* StatusMenu.swift */,
|
||||||
|
C486EFFB2586931100A02B2C /* PhpMenuItem.swift */,
|
||||||
);
|
);
|
||||||
path = Menu;
|
path = Menu;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -268,6 +271,7 @@
|
|||||||
C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */,
|
C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */,
|
||||||
C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */,
|
C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */,
|
||||||
C41C1B4B22B019FF00E7CF16 /* PhpVersion.swift in Sources */,
|
C41C1B4B22B019FF00E7CF16 /* PhpVersion.swift in Sources */,
|
||||||
|
C486EFFC2586931100A02B2C /* PhpMenuItem.swift in Sources */,
|
||||||
C476FF9822B0DD830098105B /* Alert.swift in Sources */,
|
C476FF9822B0DD830098105B /* Alert.swift in Sources */,
|
||||||
C474B00624C0E98C00066A22 /* LocalNotification.swift in Sources */,
|
C474B00624C0E98C00066A22 /* LocalNotification.swift in Sources */,
|
||||||
C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */,
|
C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */,
|
||||||
|
15
phpmon/Classes/Menu/PhpMenuItem.swift
Normal file
15
phpmon/Classes/Menu/PhpMenuItem.swift
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// PhpMenuItem.swift
|
||||||
|
// PHP Monitor
|
||||||
|
//
|
||||||
|
// Created by Nico Verbruggen on 13/12/2020.
|
||||||
|
// Copyright © 2020 Nico Verbruggen. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
class PhpMenuItem: NSMenuItem {
|
||||||
|
|
||||||
|
var version: String = ""
|
||||||
|
|
||||||
|
}
|
@ -36,8 +36,8 @@ class StatusMenu : NSMenu {
|
|||||||
let version = App.shared.availablePhpVersions[index]
|
let version = App.shared.availablePhpVersions[index]
|
||||||
let action = #selector(MainMenu.switchToPhpVersion(sender:))
|
let action = #selector(MainMenu.switchToPhpVersion(sender:))
|
||||||
let brew = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
let brew = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
||||||
let menuItem = NSMenuItem(title: "\("mi_php_switch".localized) \(version) (\(brew))", action: (version == App.shared.currentVersion?.short) ? nil : action, keyEquivalent: "\(shortcutKey)")
|
let menuItem = PhpMenuItem(title: "\("mi_php_switch".localized) \(version) (\(brew))", action: (version == App.shared.currentVersion?.short) ? nil : action, keyEquivalent: "\(shortcutKey)")
|
||||||
menuItem.tag = index
|
menuItem.version = version
|
||||||
shortcutKey = shortcutKey + 1
|
shortcutKey = shortcutKey + 1
|
||||||
self.addItem(menuItem)
|
self.addItem(menuItem)
|
||||||
}
|
}
|
||||||
|
@ -202,6 +202,7 @@ class MainMenu: NSObject, NSWindowDelegate {
|
|||||||
self.waitAndExecute({
|
self.waitAndExecute({
|
||||||
try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8)
|
try! "<?php phpinfo();".write(toFile: "/tmp/phpmon_phpinfo.php", atomically: true, encoding: .utf8)
|
||||||
Shell.user.run("/usr/local/bin/php-cgi -q /tmp/phpmon_phpinfo.php > /tmp/phpmon_phpinfo.html")
|
Shell.user.run("/usr/local/bin/php-cgi -q /tmp/phpmon_phpinfo.php > /tmp/phpmon_phpinfo.html")
|
||||||
|
}, {
|
||||||
NSWorkspace.shared.open(URL(string: "file:///private/tmp/phpmon_phpinfo.html")!)
|
NSWorkspace.shared.open(URL(string: "file:///private/tmp/phpmon_phpinfo.html")!)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -236,11 +237,9 @@ class MainMenu: NSObject, NSWindowDelegate {
|
|||||||
Actions.openValetConfigFolder()
|
Actions.openValetConfigFolder()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func switchToPhpVersion(sender: AnyObject) {
|
@objc public func switchToPhpVersion(sender: PhpMenuItem) {
|
||||||
|
print("Switching to: PHP \(sender.version)")
|
||||||
self.setBusyImage()
|
self.setBusyImage()
|
||||||
// TODO: A wise man once said: using tags is not good. Fix this.
|
|
||||||
let index = sender.tag!
|
|
||||||
let version = App.shared.availablePhpVersions[index]
|
|
||||||
App.shared.busy = true
|
App.shared.busy = true
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
// Update the PHP version in the status bar
|
// Update the PHP version in the status bar
|
||||||
@ -249,7 +248,7 @@ class MainMenu: NSObject, NSWindowDelegate {
|
|||||||
self.update()
|
self.update()
|
||||||
// Switch the PHP version
|
// Switch the PHP version
|
||||||
Actions.switchToPhpVersion(
|
Actions.switchToPhpVersion(
|
||||||
version: version,
|
version: sender.version,
|
||||||
availableVersions: App.shared.availablePhpVersions
|
availableVersions: App.shared.availablePhpVersions
|
||||||
)
|
)
|
||||||
// Mark as no longer busy
|
// Mark as no longer busy
|
||||||
@ -260,8 +259,8 @@ class MainMenu: NSObject, NSWindowDelegate {
|
|||||||
self.update()
|
self.update()
|
||||||
// Send a notification that the switch has been completed
|
// Send a notification that the switch has been completed
|
||||||
LocalNotification.send(
|
LocalNotification.send(
|
||||||
title: String(format: "notification.version_changed_title".localized, version),
|
title: String(format: "notification.version_changed_title".localized, sender.version),
|
||||||
subtitle: String(format: "notification.version_changed_desc".localized, version)
|
subtitle: String(format: "notification.version_changed_desc".localized, sender.version)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user