1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-06 04:40:07 +01:00

Add site isolation option to context menu

This commit is contained in:
2022-03-16 23:30:26 +01:00
parent 7255792910
commit 372011ca08
6 changed files with 56 additions and 3 deletions

View File

@@ -896,7 +896,7 @@ Gw
</prototypeCellViews> </prototypeCellViews>
</tableColumn> </tableColumn>
<tableColumn identifier="ENVIRONMENT" width="110" minWidth="100" maxWidth="150" id="hzb-XI-Out"> <tableColumn identifier="ENVIRONMENT" width="110" minWidth="100" maxWidth="150" id="hzb-XI-Out">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Environment"> <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="center" title="Active">
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableHeaderCell> </tableHeaderCell>

View File

@@ -93,6 +93,8 @@ class ValetSite {
return return
} }
self.isolatedPhpVersion = PhpEnv.shared.cachedPhpInstallations[version] self.isolatedPhpVersion = PhpEnv.shared.cachedPhpInstallations[version]
} else {
self.isolatedPhpVersion = nil
} }
} }

View File

@@ -42,7 +42,7 @@ extension SiteListVC {
) )
} }
tableView.reloadData(forRowIndexes: [rowToReload], columnIndexes: [0]) tableView.reloadData(forRowIndexes: [rowToReload], columnIndexes: [0, 1, 2, 3, 4])
tableView.deselectRow(rowToReload) tableView.deselectRow(rowToReload)
tableView.selectRowIndexes([rowToReload], byExtendingSelection: true) tableView.selectRowIndexes([rowToReload], byExtendingSelection: true)
} }
@@ -77,6 +77,18 @@ extension SiteListVC {
editor.openDirectory(file: selectedSite!.absolutePath) editor.openDirectory(file: selectedSite!.absolutePath)
} }
@objc func isolateSite(sender: PhpMenuItem) {
self.performAction(command: "cd '\(selectedSite!.absolutePath)' && sudo \(Paths.valet) isolate php@\(sender.version) && exit;") {
self.selectedSite!.determineIsolated()
}
}
@objc func removeIsolatedSite() {
self.performAction(command: "cd '\(selectedSite!.absolutePath)' && sudo \(Paths.valet) unisolate && exit;") {
self.selectedSite!.isolatedPhpVersion = nil
}
}
@objc func unlinkSite() { @objc func unlinkSite() {
guard let site = selectedSite else { guard let site = selectedSite else {
return return
@@ -100,4 +112,17 @@ extension SiteListVC {
) )
} }
private func performAction(command: String, beforeCellReload: @escaping () -> Void) {
let rowToReload = tableView.selectedRow
waitAndExecute {
Shell.run(command, requiresPath: true)
} completion: { [self] in
beforeCellReload()
tableView.reloadData(forRowIndexes: [rowToReload], columnIndexes: [0, 1, 2, 3, 4])
tableView.deselectRow(rowToReload)
tableView.selectRowIndexes([rowToReload], byExtendingSelection: true)
}
}
} }

View File

@@ -78,7 +78,29 @@ extension SiteListVC {
} }
private func addIsolate(to menu: NSMenu, with site: ValetSite) { private func addIsolate(to menu: NSMenu, with site: ValetSite) {
// if site.isolatedPhpVersion == nil {
// ISOLATION POSSIBLE
let isolationMenuItem = NSMenuItem(title:"site_list.isolate".localized, action: nil, keyEquivalent: "")
let submenu = NSMenu()
submenu.addItem(withTitle: "Choose a PHP version", action: nil, keyEquivalent: "")
for version in PhpEnv.shared.availablePhpVersions.reversed() {
let item = PhpMenuItem(title: "Always use PHP \(version)", action: #selector(self.isolateSite), keyEquivalent: "")
item.version = version
submenu.addItem(item)
}
menu.setSubmenu(submenu, for: isolationMenuItem)
menu.addItem(isolationMenuItem)
menu.addItem(NSMenuItem.separator())
} else {
// REMOVE ISOLATION POSSIBLE
menu.addItem(
withTitle: "site_list.remove_isolation".localized,
action: #selector(self.removeIsolatedSite),
keyEquivalent: ""
)
menu.addItem(NSMenuItem.separator())
}
} }
private func addToggleSecure(to menu: NSMenu, with site: ValetSite) { private func addToggleSecure(to menu: NSMenu, with site: ValetSite) {

View File

@@ -174,6 +174,7 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
} }
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let mapping: [String: String] = [ let mapping: [String: String] = [
"TLS": "siteListTLSCell", "TLS": "siteListTLSCell",
"DOMAIN": "siteListNameCell", "DOMAIN": "siteListNameCell",

View File

@@ -103,6 +103,9 @@
// SITE LIST ACTIONS // SITE LIST ACTIONS
"site_list.isolate" = "Isolate Domain";
"site_list.remove_isolation" = "Remove Isolation";
"site_list.unlink" = "Unlink Directory"; "site_list.unlink" = "Unlink Directory";
"site_list.secure" = "Secure Domain"; "site_list.secure" = "Secure Domain";
"site_list.unsecure" = "Unsecure Domain"; "site_list.unsecure" = "Unsecure Domain";