1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-09 21:20:07 +01:00

♻️ Change app detection, detect apps upfront

This commit is contained in:
2021-12-10 17:10:36 +01:00
parent b6b5a94bbd
commit a9f140fabc
9 changed files with 135 additions and 174 deletions

View File

@@ -41,7 +41,9 @@ class SiteListCell: NSTableCellView
// Show the green or red lock based on whether the site was secured
imageViewLock.image = NSImage(named: site.secured ? "Lock" : "LockUnlocked")
imageViewLock.contentTintColor = site.secured ? NSColor.systemGreen : NSColor.systemRed
imageViewLock.contentTintColor = site.secured ?
NSColor.init(red: 63/255, green: 195/255, blue: 128/255, alpha: 1.0) // green
: NSColor.init(red: 246/255, green: 71/255, blue: 71/255, alpha: 1.0) // red
// Show the current driver
labelDriver.stringValue = site.driver ?? "???"

View File

@@ -23,7 +23,9 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
var sites: [Valet.Site] = []
/// Array that contains various apps that might open a particular site directory.
var editors: [Application] = Application.detectPresetApplications()
var applications: [Application] {
return App.shared.detectedApplications
}
/// String that was last searched for. Empty by default.
var lastSearchedFor = ""
@@ -283,11 +285,11 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
keyEquivalent: "L"
)
if (editors.count > 0) {
if (applications.count > 0) {
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "site_list.detected_apps".localized, action: nil, keyEquivalent: "")
for (index, editor) in editors.enumerated() {
for (index, editor) in applications.enumerated() {
let editorMenuItem = EditorMenuItem(
title: "Open with \(editor.name)",
action: #selector(self.openWithEditor(sender:)),
@@ -296,10 +298,9 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
editorMenuItem.editor = editor
menu.addItem(editorMenuItem)
}
menu.addItem(NSMenuItem.separator())
}
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: "site_list.system_apps".localized, action: nil, keyEquivalent: "")
menu.addItem(
withTitle: "site_list.open_in_finder".localized,
@@ -322,29 +323,8 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
@objc func openWithEditor(sender: EditorMenuItem) {
guard let editor = sender.editor else { return }
if editor.hasBinary() {
editor.openDirectory(file: selectedSite!.absolutePath!)
} else {
presentAlertForMissingEditorBinary(editor, sender)
}
editor.openDirectory(file: selectedSite!.absolutePath!)
}
private func presentAlertForMissingEditorBinary(_ editor: Application, _ sender: EditorMenuItem) {
Alert.confirm(
onWindow: self.view.window!,
messageText: "editors.binary_missing.title".localized(editor.pathToBinary),
informativeText:
editor.missingBinaryInstruction
?? "editors.binary_missing.desc".localized(editor.pathToBinary),
buttonTitle: "editors.alert.try_again".localized,
secondButtonTitle: "editors.alert.cancel".localized,
onFirstButtonPressed: {
self.openWithEditor(sender: sender)
}
)
}
// MARK: - Deinitialization
deinit {