From 7f320897be32124115c2d6b954773c9053ccff59 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 4 Jan 2022 00:20:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Make=20user-supplied=20apps=20av?= =?UTF-8?q?ailable=20(#73)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++++++ phpmon/Domain/Helpers/Application.swift | 2 +- phpmon/Domain/Menu/MainMenu+Startup.swift | 8 +++++++- phpmon/Domain/Preferences/Preferences.swift | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4064038..2fa7932 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,16 @@ The supported apps are: PhpStorm, Visual Studio Code, Sublime Text, Sublime M All of these apps should just be detected correctly, no matter their location on your system. If you can open it using `open -a "appname"`, the app should be detected and work. If you have renamed the app, there might be an issue getting it detected. To see which files are checked to determine availability, see [this file](./phpmon/Domain/Helpers/Application.swift). + +You can add your own apps by creating and editing a `~/.phpmon.conf.json` file, with the following entry: + + +{ + "scan_apps": ["Xcode", "Kraken"] +} + + +You can put as many apps as you'd like in the `scan_apps` array, and PHP Monitor will check for the existence of these apps. You do not need to set the full path, just the name of the app should work. Not all apps support opening a folder, though, so your success might vary.
diff --git a/phpmon/Domain/Helpers/Application.swift b/phpmon/Domain/Helpers/Application.swift index 6617a01..6cb2bfe 100644 --- a/phpmon/Domain/Helpers/Application.swift +++ b/phpmon/Domain/Helpers/Application.swift @@ -14,7 +14,7 @@ import Foundation class Application { enum AppType { - case editor, browser, git_gui, terminal + case editor, browser, git_gui, terminal, user_supplied } /// Name of the app. Used for display purposes and to determine `name.app` exists. diff --git a/phpmon/Domain/Menu/MainMenu+Startup.swift b/phpmon/Domain/Menu/MainMenu+Startup.swift index 8dd7494..573684a 100644 --- a/phpmon/Domain/Menu/MainMenu+Startup.swift +++ b/phpmon/Domain/Menu/MainMenu+Startup.swift @@ -51,9 +51,15 @@ extension MainMenu { Log.info("Setting up watchers...") App.shared.handlePhpConfigWatcher() + // Detect applications (preset + custom) Log.info("Detecting applications...") - // Attempt to load list of applications App.shared.detectedApplications = Application.detectPresetApplications() + let customApps = Preferences.custom.scanApps.map { appName in + return Application(appName, .user_supplied) + }.filter { app in + return app.isInstalled() + } + App.shared.detectedApplications.append(contentsOf: customApps) let appNames = App.shared.detectedApplications.map { app in return app.name } diff --git a/phpmon/Domain/Preferences/Preferences.swift b/phpmon/Domain/Preferences/Preferences.swift index 94f6c83..18e69fd 100644 --- a/phpmon/Domain/Preferences/Preferences.swift +++ b/phpmon/Domain/Preferences/Preferences.swift @@ -76,6 +76,10 @@ class Preferences { return Self.shared.cachedPreferences } + static var custom: CustomPrefs { + return Self.shared.customPreferences + } + /** Determine whether a particular preference is enabled. - Important: Requires the preference to have a corresponding boolean value, or a fatal error will be thrown.