From eaf1423fb1c9ff123f9a64f2e0a48824d02a5870 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 9 Dec 2021 19:49:16 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Performance=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Avoid preloading list of sites twice - Avoid loading Valet info twice - Preload list of sites if <= 10 sites linked + parked - Added fallback for missing instructions - Improved description --- PHP Monitor.xcodeproj/project.pbxproj | 8 ++--- phpmon/Domain/Integrations/Valet/Valet.swift | 6 ++++ phpmon/Domain/Menu/MainMenu.swift | 3 +- phpmon/Domain/SiteList/SiteListVC.swift | 37 ++++++++++++-------- phpmon/Localizable.strings | 2 ++ 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 9921cae..22b661c 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -771,7 +771,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 105; + CURRENT_PROJECT_VERSION = 110; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; @@ -780,7 +780,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = "4.1-beta4"; + MARKETING_VERSION = "4.1-beta5"; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -796,7 +796,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 105; + CURRENT_PROJECT_VERSION = 110; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; @@ -805,7 +805,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = "4.1-beta4"; + MARKETING_VERSION = "4.1-beta5"; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/phpmon/Domain/Integrations/Valet/Valet.swift b/phpmon/Domain/Integrations/Valet/Valet.swift index 40e368e..9d4e658 100644 --- a/phpmon/Domain/Integrations/Valet/Valet.swift +++ b/phpmon/Domain/Integrations/Valet/Valet.swift @@ -36,6 +36,12 @@ class Valet { Valet.Configuration.self, from: try! String(contentsOf: file, encoding: .utf8).data(using: .utf8)! ) + + if self.sites.count <= 10 { + // Preload the sites and their drivers + print("Fewer than or 11 sites found, preloading list of sites...") + self.reloadSites() + } } public func reloadSites() { diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 0f59593..e0794e8 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -60,8 +60,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { installation.notifyAboutBrokenPhpFpm() // Attempt to find out more info about Valet - let valet = Valet() - print("PHP Monitor has extracted the version number of Valet: \(valet.version)") + print("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version)") print("PHP Monitor is ready to serve!") // Schedule a request to fetch the PHP version every 60 seconds diff --git a/phpmon/Domain/SiteList/SiteListVC.swift b/phpmon/Domain/SiteList/SiteListVC.swift index 7ce6ad4..c8559d0 100644 --- a/phpmon/Domain/SiteList/SiteListVC.swift +++ b/phpmon/Domain/SiteList/SiteListVC.swift @@ -71,7 +71,13 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource { override func viewDidLoad() { tableView.doubleAction = #selector(self.doubleClicked(sender:)) - reloadSites() + if !Valet.shared.sites.isEmpty { + // Preloaded list + sites = Valet.shared.sites + searchedFor(text: lastSearchedFor) + } else { + reloadSites() + } } // MARK: - Async Operations @@ -308,21 +314,24 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource { if editor.hasBinary() { editor.openDirectory(file: selectedSite!.absolutePath!) } else { - Alert.confirm( - onWindow: self.view.window!, - messageText: "editors.binary_missing.title" - .localized( - editor.pathToBinary - ), - informativeText: editor.missingBinaryInstruction ?? "", - buttonTitle: "editors.alert.try_again".localized, - secondButtonTitle: "editors.alert.cancel".localized, - onFirstButtonPressed: { - self.openWithEditor(sender: sender) - } - ) + presentAlertForMissingEditorBinary(editor, sender) } } + + private func presentAlertForMissingEditorBinary(_ editor: Editor, _ 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 diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index cabbb51..1e1aac1 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -75,6 +75,7 @@ // EDITORS "editors.binary_missing.title" = "`%@` missing"; +"editors.binary_missing.desc" = "The associated binary (`%@`) is missing. Because of this, PHP Monitor cannot open the domain’s folder."; "editors.alert.try_again" = "Try Again"; "editors.alert.cancel" = "Cancel"; @@ -88,6 +89,7 @@ After this is done, PHP Monitor should be able to open the domain’s folder in "PHP Monitor makes use of Visual Studio Code‘s helper binary, `code`, but it seems not to exist on your system. You can fix this by selecting 'Install `code` command in PATH' in Visual Studio Code’s command palette. +(Type `>code` to find it.) After this is done, PHP Monitor should be able to open the domain’s folder in PhpStorm.";