diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index a19d4d5..861747b 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -9,10 +9,24 @@ /* Begin PBXBuildFile section */ 5420395926135DC100FB00FA /* PrefsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395826135DC100FB00FA /* PrefsVC.swift */; }; 5420395F2613607600FB00FA /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395E2613607600FB00FA /* Preferences.swift */; }; + 54AB03262763858F00A29D5F /* Timer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54AB03252763858F00A29D5F /* Timer.swift */; }; + 54AB03272763858F00A29D5F /* Timer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54AB03252763858F00A29D5F /* Timer.swift */; }; + 54B48B5F275F66AE006D90C5 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B48B5E275F66AE006D90C5 /* Application.swift */; }; + 54B48B60275F66AE006D90C5 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B48B5E275F66AE006D90C5 /* Application.swift */; }; 54EAC806262F212B0092D14E /* GlobalKeybindPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41CD0282628D8EE0065BBED /* GlobalKeybindPreference.swift */; }; + 54FCFD26276C883F004CE748 /* CheckboxPreferenceView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54FCFD25276C883F004CE748 /* CheckboxPreferenceView.xib */; }; + 54FCFD27276C883F004CE748 /* CheckboxPreferenceView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54FCFD25276C883F004CE748 /* CheckboxPreferenceView.xib */; }; + 54FCFD2A276C8AA4004CE748 /* CheckboxPreferenceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54FCFD29276C8AA4004CE748 /* CheckboxPreferenceView.swift */; }; + 54FCFD2B276C8AA4004CE748 /* CheckboxPreferenceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54FCFD29276C8AA4004CE748 /* CheckboxPreferenceView.swift */; }; + 54FCFD2D276C8D67004CE748 /* HotkeyPreferenceView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54FCFD2C276C8D67004CE748 /* HotkeyPreferenceView.xib */; }; + 54FCFD2E276C8D67004CE748 /* HotkeyPreferenceView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54FCFD2C276C8D67004CE748 /* HotkeyPreferenceView.xib */; }; + 54FCFD30276C8DA4004CE748 /* HotkeyPreferenceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54FCFD2F276C8DA4004CE748 /* HotkeyPreferenceView.swift */; }; + 54FCFD31276C8DA4004CE748 /* HotkeyPreferenceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54FCFD2F276C8DA4004CE748 /* HotkeyPreferenceView.swift */; }; C405A4D024B9B9140062FAFA /* InternetAccessPolicy.strings in Resources */ = {isa = PBXBuildFile; fileRef = C405A4CE24B9B9130062FAFA /* InternetAccessPolicy.strings */; }; C405A4D124B9B9140062FAFA /* InternetAccessPolicy.plist in Resources */ = {isa = PBXBuildFile; fileRef = C405A4CF24B9B9140062FAFA /* InternetAccessPolicy.plist */; }; C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */; }; + C4188989275FE8CB001EF227 /* Filesystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4188988275FE8CB001EF227 /* Filesystem.swift */; }; + C418898A275FE8CB001EF227 /* Filesystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4188988275FE8CB001EF227 /* Filesystem.swift */; }; C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */; }; C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3A22B0098000E7CF16 /* Assets.xcassets */; }; C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3C22B0098000E7CF16 /* Main.storyboard */; }; @@ -21,13 +35,23 @@ C41C1B4B22B019FF00E7CF16 /* ActivePhpInstallation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4A22B019FF00E7CF16 /* ActivePhpInstallation.swift */; }; C41C1B4D22B0215A00E7CF16 /* Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4C22B0215A00E7CF16 /* Actions.swift */; }; C41CD0292628D8EE0065BBED /* GlobalKeybindPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41CD0282628D8EE0065BBED /* GlobalKeybindPreference.swift */; }; + C41E871A2763D42300161EE0 /* SiteListVC+ContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41E87192763D42300161EE0 /* SiteListVC+ContextMenu.swift */; }; + C41E871B2763D42300161EE0 /* SiteListVC+ContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41E87192763D42300161EE0 /* SiteListVC+ContextMenu.swift */; }; C42295DD2358D02000E263B2 /* Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42295DC2358D02000E263B2 /* Command.swift */; }; C4232EE52612526500158FC6 /* Credits.html in Resources */ = {isa = PBXBuildFile; fileRef = C4232EE42612526500158FC6 /* Credits.html */; }; C42759672627662800093CAE /* NSMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42759662627662800093CAE /* NSMenuExtension.swift */; }; C42759682627662800093CAE /* NSMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42759662627662800093CAE /* NSMenuExtension.swift */; }; + C43603A0275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */; }; + C43603A1275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */; }; C43A8A1A25D9CD1000591B77 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = C43A8A1925D9CD1000591B77 /* Utility.swift */; }; C43A8A2025D9D1D700591B77 /* brew.json in Resources */ = {isa = PBXBuildFile; fileRef = C43A8A1F25D9D1D700591B77 /* brew.json */; }; C43A8A2425D9D20D00591B77 /* BrewJsonParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C43A8A2325D9D20D00591B77 /* BrewJsonParserTest.swift */; }; + C464ADAC275A7A3F003FCD53 /* SiteListWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAB275A7A3F003FCD53 /* SiteListWC.swift */; }; + C464ADAD275A7A3F003FCD53 /* SiteListWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAB275A7A3F003FCD53 /* SiteListWC.swift */; }; + C464ADAF275A7A69003FCD53 /* SiteListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAE275A7A69003FCD53 /* SiteListVC.swift */; }; + C464ADB0275A7A6A003FCD53 /* SiteListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAE275A7A69003FCD53 /* SiteListVC.swift */; }; + C464ADB2275A87CA003FCD53 /* SiteListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADB1275A87CA003FCD53 /* SiteListCell.swift */; }; + C464ADB3275A87CA003FCD53 /* SiteListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADB1275A87CA003FCD53 /* SiteListCell.swift */; }; C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46FA23E246C358E00944F05 /* StringExtension.swift */; }; C473319F2470923A009A0597 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C473319E2470923A009A0597 /* Localizable.strings */; }; C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47331A1247093B7009A0597 /* StatusMenu.swift */; }; @@ -47,6 +71,23 @@ C4998F0B2617633900B2526E /* PrefsWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4998F092617633900B2526E /* PrefsWC.swift */; }; C49EAB46259FC305007F6C3B /* Paths.swift in Sources */ = {isa = PBXBuildFile; fileRef = C49EAB45259FC305007F6C3B /* Paths.swift */; }; C4ACA38F25C754C100060C66 /* PhpExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4ACA38E25C754C100060C66 /* PhpExtension.swift */; }; + C4AF9F71275445FF00D44ED0 /* valet-config.json in Resources */ = {isa = PBXBuildFile; fileRef = C4AF9F70275445FF00D44ED0 /* valet-config.json */; }; + C4AF9F72275445FF00D44ED0 /* valet-config.json in Resources */ = {isa = PBXBuildFile; fileRef = C4AF9F70275445FF00D44ED0 /* valet-config.json */; }; + C4AF9F78275447F100D44ED0 /* ValetConfigParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AF9F76275447F100D44ED0 /* ValetConfigParserTest.swift */; }; + C4AF9F7A2754499000D44ED0 /* Valet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AF9F792754499000D44ED0 /* Valet.swift */; }; + C4AF9F7B2754499000D44ED0 /* Valet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AF9F792754499000D44ED0 /* Valet.swift */; }; + C4AF9F7D275454A900D44ED0 /* ValetTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AF9F7C275454A900D44ED0 /* ValetTest.swift */; }; + C4B5635E276AB09000F12CCB /* VersionExtractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B5635D276AB09000F12CCB /* VersionExtractor.swift */; }; + C4B5635F276AB09000F12CCB /* VersionExtractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B5635D276AB09000F12CCB /* VersionExtractor.swift */; }; + C4B56362276AB0A500F12CCB /* VersionExtractorTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B56360276AB0A500F12CCB /* VersionExtractorTest.swift */; }; + C4B97B75275CF08C003F3378 /* AppDelegate+MenuOutlets.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B97B74275CF08C003F3378 /* AppDelegate+MenuOutlets.swift */; }; + C4B97B76275CF08C003F3378 /* AppDelegate+MenuOutlets.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B97B74275CF08C003F3378 /* AppDelegate+MenuOutlets.swift */; }; + C4B97B78275CF1B5003F3378 /* App+ActivationPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B97B77275CF1B5003F3378 /* App+ActivationPolicy.swift */; }; + C4B97B79275CF1B5003F3378 /* App+ActivationPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B97B77275CF1B5003F3378 /* App+ActivationPolicy.swift */; }; + C4B97B7B275CF20A003F3378 /* App+GlobalHotkey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B97B7A275CF20A003F3378 /* App+GlobalHotkey.swift */; }; + C4B97B7C275CF20A003F3378 /* App+GlobalHotkey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B97B7A275CF20A003F3378 /* App+GlobalHotkey.swift */; }; + C4CCBA6C275C567B008C7055 /* PMWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CCBA6B275C567B008C7055 /* PMWindowController.swift */; }; + C4CCBA6D275C567B008C7055 /* PMWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CCBA6B275C567B008C7055 /* PMWindowController.swift */; }; C4D8016622B1584700C6DA1B /* Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D8016522B1584700C6DA1B /* Startup.swift */; }; C4EE188422D3386B00E126E5 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4EE188322D3386B00E126E5 /* Constants.swift */; }; C4F2E4372752F0870020E974 /* HomebrewDiagnostics.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F2E4362752F0870020E974 /* HomebrewDiagnostics.swift */; }; @@ -94,9 +135,16 @@ /* Begin PBXFileReference section */ 5420395826135DC100FB00FA /* PrefsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefsVC.swift; sourceTree = ""; }; 5420395E2613607600FB00FA /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; + 54AB03252763858F00A29D5F /* Timer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Timer.swift; sourceTree = ""; }; + 54B48B5E275F66AE006D90C5 /* Application.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = ""; }; + 54FCFD25276C883F004CE748 /* CheckboxPreferenceView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CheckboxPreferenceView.xib; sourceTree = ""; }; + 54FCFD29276C8AA4004CE748 /* CheckboxPreferenceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxPreferenceView.swift; sourceTree = ""; }; + 54FCFD2C276C8D67004CE748 /* HotkeyPreferenceView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HotkeyPreferenceView.xib; sourceTree = ""; }; + 54FCFD2F276C8DA4004CE748 /* HotkeyPreferenceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HotkeyPreferenceView.swift; sourceTree = ""; }; C405A4CE24B9B9130062FAFA /* InternetAccessPolicy.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = InternetAccessPolicy.strings; sourceTree = ""; }; C405A4CF24B9B9140062FAFA /* InternetAccessPolicy.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = InternetAccessPolicy.plist; sourceTree = ""; }; C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomebrewPackage.swift; sourceTree = ""; }; + C4188988275FE8CB001EF227 /* Filesystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filesystem.swift; sourceTree = ""; }; C41C1B3322B0097F00E7CF16 /* PHP Monitor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PHP Monitor.app"; sourceTree = BUILT_PRODUCTS_DIR; }; C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; C41C1B3A22B0098000E7CF16 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -108,12 +156,17 @@ C41C1B4A22B019FF00E7CF16 /* ActivePhpInstallation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivePhpInstallation.swift; sourceTree = ""; }; C41C1B4C22B0215A00E7CF16 /* Actions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Actions.swift; sourceTree = ""; }; C41CD0282628D8EE0065BBED /* GlobalKeybindPreference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalKeybindPreference.swift; sourceTree = ""; }; + C41E87192763D42300161EE0 /* SiteListVC+ContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SiteListVC+ContextMenu.swift"; sourceTree = ""; }; C42295DC2358D02000E263B2 /* Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Command.swift; sourceTree = ""; }; C4232EE42612526500158FC6 /* Credits.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = Credits.html; sourceTree = ""; }; C42759662627662800093CAE /* NSMenuExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSMenuExtension.swift; sourceTree = ""; }; + C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Notifications.swift"; sourceTree = ""; }; C43A8A1925D9CD1000591B77 /* Utility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utility.swift; sourceTree = ""; }; C43A8A1F25D9D1D700591B77 /* brew.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = brew.json; sourceTree = ""; }; C43A8A2325D9D20D00591B77 /* BrewJsonParserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrewJsonParserTest.swift; sourceTree = ""; }; + C464ADAB275A7A3F003FCD53 /* SiteListWC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteListWC.swift; sourceTree = ""; }; + C464ADAE275A7A69003FCD53 /* SiteListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteListVC.swift; sourceTree = ""; }; + C464ADB1275A87CA003FCD53 /* SiteListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteListCell.swift; sourceTree = ""; }; C46FA23E246C358E00944F05 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; C473319E2470923A009A0597 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = ""; }; C47331A1247093B7009A0597 /* StatusMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusMenu.swift; sourceTree = ""; }; @@ -129,6 +182,16 @@ C4998F092617633900B2526E /* PrefsWC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefsWC.swift; sourceTree = ""; }; C49EAB45259FC305007F6C3B /* Paths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Paths.swift; sourceTree = ""; }; C4ACA38E25C754C100060C66 /* PhpExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpExtension.swift; sourceTree = ""; }; + C4AF9F70275445FF00D44ED0 /* valet-config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "valet-config.json"; sourceTree = ""; }; + C4AF9F76275447F100D44ED0 /* ValetConfigParserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValetConfigParserTest.swift; sourceTree = ""; }; + C4AF9F792754499000D44ED0 /* Valet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Valet.swift; sourceTree = ""; }; + C4AF9F7C275454A900D44ED0 /* ValetTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValetTest.swift; sourceTree = ""; }; + C4B5635D276AB09000F12CCB /* VersionExtractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionExtractor.swift; sourceTree = ""; }; + C4B56360276AB0A500F12CCB /* VersionExtractorTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionExtractorTest.swift; sourceTree = ""; }; + C4B97B74275CF08C003F3378 /* AppDelegate+MenuOutlets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+MenuOutlets.swift"; sourceTree = ""; }; + C4B97B77275CF1B5003F3378 /* App+ActivationPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "App+ActivationPolicy.swift"; sourceTree = ""; }; + C4B97B7A275CF20A003F3378 /* App+GlobalHotkey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "App+GlobalHotkey.swift"; sourceTree = ""; }; + C4CCBA6B275C567B008C7055 /* PMWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PMWindowController.swift; sourceTree = ""; }; C4D8016522B1584700C6DA1B /* Startup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Startup.swift; sourceTree = ""; }; C4E713562570150F00007428 /* SECURITY.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = SECURITY.md; sourceTree = ""; }; C4E713572570151400007428 /* docs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = docs; sourceTree = ""; }; @@ -172,6 +235,7 @@ 5420395826135DC100FB00FA /* PrefsVC.swift */, 5420395E2613607600FB00FA /* Preferences.swift */, C41CD0272628D8E20065BBED /* Keybinds */, + 54FCFD28276C88C0004CE748 /* Views */, ); path = Preferences; sourceTree = ""; @@ -186,6 +250,17 @@ path = PHP; sourceTree = ""; }; + 54FCFD28276C88C0004CE748 /* Views */ = { + isa = PBXGroup; + children = ( + 54FCFD25276C883F004CE748 /* CheckboxPreferenceView.xib */, + 54FCFD29276C8AA4004CE748 /* CheckboxPreferenceView.swift */, + 54FCFD2C276C8D67004CE748 /* HotkeyPreferenceView.xib */, + 54FCFD2F276C8DA4004CE748 /* HotkeyPreferenceView.swift */, + ); + path = Views; + sourceTree = ""; + }; C405A4CD24B9B9070062FAFA /* IAP */ = { isa = PBXGroup; children = ( @@ -220,7 +295,6 @@ C41C1B3522B0097F00E7CF16 /* phpmon */ = { isa = PBXGroup; children = ( - C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */, C4EE188322D3386B00E126E5 /* Constants.swift */, C41E181722CB61EB0072CF09 /* Domain */, C41C1B3F22B0098000E7CF16 /* Info.plist */, @@ -244,10 +318,12 @@ C41E181722CB61EB0072CF09 /* Domain */ = { isa = PBXGroup; children = ( + C4AF9F6B275445D300D44ED0 /* Integrations */, C4B13B1D25C4915000548C3A /* Core */, 54B20EDF263AA22C00D3250E /* PHP */, C4F7808A25D7F918000DBC97 /* Terminal */, C47331A0247093AC009A0597 /* Menu */, + C464ADAA275A7A25003FCD53 /* SiteList */, 5420395726135DB800FB00FA /* Preferences */, C4811D2822D70D9C00B5F6B3 /* Helpers */, C4F8C0A222D4F100002EFE61 /* Extensions */, @@ -255,6 +331,17 @@ path = Domain; sourceTree = ""; }; + C464ADAA275A7A25003FCD53 /* SiteList */ = { + isa = PBXGroup; + children = ( + C464ADAB275A7A3F003FCD53 /* SiteListWC.swift */, + C464ADAE275A7A69003FCD53 /* SiteListVC.swift */, + C41E87192763D42300161EE0 /* SiteListVC+ContextMenu.swift */, + C464ADB1275A87CA003FCD53 /* SiteListCell.swift */, + ); + path = SiteList; + sourceTree = ""; + }; C47331A0247093AC009A0597 /* Menu */ = { isa = PBXGroup; children = ( @@ -272,19 +359,53 @@ isa = PBXGroup; children = ( C476FF9722B0DD830098105B /* Alert.swift */, - C41C1B4822B00A9800E7CF16 /* MenuBarImageGenerator.swift */, + 54B48B5E275F66AE006D90C5 /* Application.swift */, + C4188988275FE8CB001EF227 /* Filesystem.swift */, C474B00524C0E98C00066A22 /* LocalNotification.swift */, + C41C1B4822B00A9800E7CF16 /* MenuBarImageGenerator.swift */, + C4CCBA6B275C567B008C7055 /* PMWindowController.swift */, + 54AB03252763858F00A29D5F /* Timer.swift */, + C4B5635D276AB09000F12CCB /* VersionExtractor.swift */, + ); + path = Helpers; + sourceTree = ""; + }; + C4AF9F6A275445C900D44ED0 /* Valet */ = { + isa = PBXGroup; + children = ( + C4AF9F792754499000D44ED0 /* Valet.swift */, + ); + path = Valet; + sourceTree = ""; + }; + C4AF9F6B275445D300D44ED0 /* Integrations */ = { + isa = PBXGroup; + children = ( + C4AF9F6C275445D900D44ED0 /* Homebrew */, + C4AF9F6A275445C900D44ED0 /* Valet */, + ); + path = Integrations; + sourceTree = ""; + }; + C4AF9F6C275445D900D44ED0 /* Homebrew */ = { + isa = PBXGroup; + children = ( C4F2E4362752F0870020E974 /* HomebrewDiagnostics.swift */, C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */, ); - path = Helpers; + path = Homebrew; sourceTree = ""; }; C4B13B1D25C4915000548C3A /* Core */ = { isa = PBXGroup; children = ( C41C1B3C22B0098000E7CF16 /* Main.storyboard */, + C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */, + C4B97B74275CF08C003F3378 /* AppDelegate+MenuOutlets.swift */, + C436039F275E67610028EFC6 /* AppDelegate+Notifications.swift */, C4811D2322D70A4700B5F6B3 /* App.swift */, + C4B97B77275CF1B5003F3378 /* App+ActivationPolicy.swift */, + C4B97B7A275CF20A003F3378 /* App+GlobalHotkey.swift */, C4D8016522B1584700C6DA1B /* Startup.swift */, C41C1B4C22B0215A00E7CF16 /* Actions.swift */, ); @@ -294,6 +415,7 @@ C4F7807A25D7F84B000DBC97 /* phpmon-tests */ = { isa = PBXGroup; children = ( + C4AF9F70275445FF00D44ED0 /* valet-config.json */, C43A8A1F25D9D1D700591B77 /* brew.json */, C4F780A725D80AE8000DBC97 /* php.ini */, C4F7807D25D7F84B000DBC97 /* Info.plist */, @@ -302,6 +424,9 @@ C43A8A2325D9D20D00591B77 /* BrewJsonParserTest.swift */, C4FBFC512616485F00CDB8E1 /* PhpVersionDetectionTest.swift */, C43A8A1925D9CD1000591B77 /* Utility.swift */, + C4AF9F76275447F100D44ED0 /* ValetConfigParserTest.swift */, + C4AF9F7C275454A900D44ED0 /* ValetTest.swift */, + C4B56360276AB0A500F12CCB /* VersionExtractorTest.swift */, ); path = "phpmon-tests"; sourceTree = ""; @@ -416,10 +541,13 @@ files = ( C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */, C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */, + C4AF9F71275445FF00D44ED0 /* valet-config.json in Resources */, C48D0C9025CC7FD000CC7490 /* StatsView.xib in Resources */, C405A4D124B9B9140062FAFA /* InternetAccessPolicy.plist in Resources */, C4232EE52612526500158FC6 /* Credits.html in Resources */, + 54FCFD26276C883F004CE748 /* CheckboxPreferenceView.xib in Resources */, C473319F2470923A009A0597 /* Localizable.strings in Resources */, + 54FCFD2D276C8D67004CE748 /* HotkeyPreferenceView.xib in Resources */, C405A4D024B9B9140062FAFA /* InternetAccessPolicy.strings in Resources */, C48D0C9A25CC888B00CC7490 /* HeaderView.xib in Resources */, ); @@ -429,8 +557,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 54FCFD27276C883F004CE748 /* CheckboxPreferenceView.xib in Resources */, + 54FCFD2E276C8D67004CE748 /* HotkeyPreferenceView.xib in Resources */, C4F780A825D80AE8000DBC97 /* php.ini in Resources */, C43A8A2025D9D1D700591B77 /* brew.json in Resources */, + C4AF9F72275445FF00D44ED0 /* valet-config.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -445,29 +576,45 @@ C4D8016622B1584700C6DA1B /* Startup.swift in Sources */, C4998F0A2617633900B2526E /* PrefsWC.swift in Sources */, C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */, + C4AF9F7A2754499000D44ED0 /* Valet.swift in Sources */, 5420395926135DC100FB00FA /* PrefsVC.swift in Sources */, + C43603A0275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */, + 54FCFD30276C8DA4004CE748 /* HotkeyPreferenceView.swift in Sources */, C41C1B4722B009A400E7CF16 /* Shell.swift in Sources */, C4F2E43A2752F7D00020E974 /* PhpInstallation.swift in Sources */, C41C1B4D22B0215A00E7CF16 /* Actions.swift in Sources */, + C41E871A2763D42300161EE0 /* SiteListVC+ContextMenu.swift in Sources */, C48D0CA325CC992000CC7490 /* StatsView.swift in Sources */, C4F2E4372752F0870020E974 /* HomebrewDiagnostics.swift in Sources */, + C4CCBA6C275C567B008C7055 /* PMWindowController.swift in Sources */, C41CD0292628D8EE0065BBED /* GlobalKeybindPreference.swift in Sources */, C42295DD2358D02000E263B2 /* Command.swift in Sources */, + 54B48B5F275F66AE006D90C5 /* Application.swift in Sources */, + C4B97B78275CF1B5003F3378 /* App+ActivationPolicy.swift in Sources */, C4811D2422D70A4700B5F6B3 /* App.swift in Sources */, C41C1B4922B00A9800E7CF16 /* MenuBarImageGenerator.swift in Sources */, 5420395F2613607600FB00FA /* Preferences.swift in Sources */, C48D0C9325CC804200CC7490 /* XibLoadable.swift in Sources */, + 54FCFD2A276C8AA4004CE748 /* CheckboxPreferenceView.swift in Sources */, C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */, C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */, + 54AB03262763858F00A29D5F /* Timer.swift in Sources */, C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */, C42759672627662800093CAE /* NSMenuExtension.swift in Sources */, + C464ADAF275A7A69003FCD53 /* SiteListVC.swift in Sources */, C41C1B4B22B019FF00E7CF16 /* ActivePhpInstallation.swift in Sources */, C49EAB46259FC305007F6C3B /* Paths.swift in Sources */, + C4188989275FE8CB001EF227 /* Filesystem.swift in Sources */, + C4B97B7B275CF20A003F3378 /* App+GlobalHotkey.swift in Sources */, C476FF9822B0DD830098105B /* Alert.swift in Sources */, C474B00624C0E98C00066A22 /* LocalNotification.swift in Sources */, C48D0C9625CC80B100CC7490 /* HeaderView.swift in Sources */, + C4B5635E276AB09000F12CCB /* VersionExtractor.swift in Sources */, C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */, C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */, + C4B97B75275CF08C003F3378 /* AppDelegate+MenuOutlets.swift in Sources */, + C464ADAC275A7A3F003FCD53 /* SiteListWC.swift in Sources */, + C464ADB2275A87CA003FCD53 /* SiteListCell.swift in Sources */, C4EE188422D3386B00E126E5 /* Constants.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -478,6 +625,9 @@ files = ( 54EAC806262F212B0092D14E /* GlobalKeybindPreference.swift in Sources */, C4F780C425D80B75000DBC97 /* MainMenu.swift in Sources */, + 54AB03272763858F00A29D5F /* Timer.swift in Sources */, + 54FCFD2B276C8AA4004CE748 /* CheckboxPreferenceView.swift in Sources */, + 54B48B60275F66AE006D90C5 /* Application.swift in Sources */, C4F780C825D80B75000DBC97 /* DateExtension.swift in Sources */, C4F780CC25D80B75000DBC97 /* ActivePhpInstallation.swift in Sources */, C4F780B125D80B4D000DBC97 /* PhpExtension.swift in Sources */, @@ -485,27 +635,43 @@ C4FBFC532616485F00CDB8E1 /* PhpVersionDetectionTest.swift in Sources */, C43A8A2425D9D20D00591B77 /* BrewJsonParserTest.swift in Sources */, C4F780CA25D80B75000DBC97 /* HomebrewPackage.swift in Sources */, + C4AF9F7B2754499000D44ED0 /* Valet.swift in Sources */, C4F780C025D80B6E000DBC97 /* Startup.swift in Sources */, + C4CCBA6D275C567B008C7055 /* PMWindowController.swift in Sources */, + C4B5635F276AB09000F12CCB /* VersionExtractor.swift in Sources */, C4F2E4382752F08D0020E974 /* HomebrewDiagnostics.swift in Sources */, C4F780AE25D80B37000DBC97 /* ExtensionParserTest.swift in Sources */, C4F780C725D80B75000DBC97 /* StatusMenu.swift in Sources */, + C43603A1275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */, C42759682627662800093CAE /* NSMenuExtension.swift in Sources */, + C4B97B76275CF08C003F3378 /* AppDelegate+MenuOutlets.swift in Sources */, C4F780CD25D80B75000DBC97 /* Alert.swift in Sources */, C481F79726164A78004FBCFF /* PrefsVC.swift in Sources */, + C41E871B2763D42300161EE0 /* SiteListVC+ContextMenu.swift in Sources */, + C464ADB3275A87CA003FCD53 /* SiteListCell.swift in Sources */, + C4AF9F78275447F100D44ED0 /* ValetConfigParserTest.swift in Sources */, + C4B97B7C275CF20A003F3378 /* App+GlobalHotkey.swift in Sources */, + C4B97B79275CF1B5003F3378 /* App+ActivationPolicy.swift in Sources */, C4F7809C25D80344000DBC97 /* CommandTest.swift in Sources */, C4F780BA25D80B62000DBC97 /* AppDelegate.swift in Sources */, + 54FCFD31276C8DA4004CE748 /* HotkeyPreferenceView.swift in Sources */, C4998F0B2617633900B2526E /* PrefsWC.swift in Sources */, C4F780A225D804AA000DBC97 /* Paths.swift in Sources */, C4F2E43B27530F750020E974 /* PhpInstallation.swift in Sources */, C4F780BD25D80B65000DBC97 /* Constants.swift in Sources */, C4F780C325D80B75000DBC97 /* HeaderView.swift in Sources */, C4F7809625D7FBF8000DBC97 /* Shell.swift in Sources */, + C4AF9F7D275454A900D44ED0 /* ValetTest.swift in Sources */, + C4B56362276AB0A500F12CCB /* VersionExtractorTest.swift in Sources */, C4F780C525D80B75000DBC97 /* MenuBarImageGenerator.swift in Sources */, C4F780B725D80B5D000DBC97 /* App.swift in Sources */, C4F780C925D80B75000DBC97 /* StringExtension.swift in Sources */, C481F79A26164A7C004FBCFF /* Preferences.swift in Sources */, + C464ADAD275A7A3F003FCD53 /* SiteListWC.swift in Sources */, C4F780CB25D80B75000DBC97 /* StatsView.swift in Sources */, + C464ADB0275A7A6A003FCD53 /* SiteListVC.swift in Sources */, C43A8A1A25D9CD1000591B77 /* Utility.swift in Sources */, + C418898A275FE8CB001EF227 /* Filesystem.swift in Sources */, C4F780C625D80B75000DBC97 /* XibLoadable.swift in Sources */, C4F7809F25D8037C000DBC97 /* Command.swift in Sources */, C4F780B425D80B51000DBC97 /* Actions.swift in Sources */, @@ -586,7 +752,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -642,7 +808,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = macosx; @@ -659,7 +825,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 81; + CURRENT_PROJECT_VERSION = 135; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; @@ -667,7 +833,8 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 4.0.1; + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 4.1; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -683,7 +850,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 81; + CURRENT_PROJECT_VERSION = 135; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; @@ -691,7 +858,8 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 4.0.1; + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 4.1; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -712,7 +880,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = "com.nicoverbruggen.phpmon-tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -733,7 +901,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = "com.nicoverbruggen.phpmon-tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/README.md b/README.md index fb26eb8..6829a23 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ **PHP Monitor** (or phpmon) is a lightweight macOS utility app that runs on your Mac and displays the active PHP version in your status bar. It's tightly integrated with [Laravel Valet](https://github.com/laravel/valet), so you need to have it set up before you can use this. -phpmon screenshot (menu bar app) +phpmon screenshot (menu bar app) Screenshot: A menu showing all of the functionality of PHP Monitor. @@ -21,12 +21,12 @@ PHP Monitor also gives you quick access to various useful functionality (like ac PHP Monitor is a universal application that runs on Apple Silicon **and** Intel-based Macs. -* macOS 10.14 Mojave or higher (works on macOS 11 Big Sur and macOS 12 Monterey) +* macOS 11 Big Sur or higher (supports macOS 12 Monterey) * Homebrew is installed in `/usr/local/homebrew` or `/opt/homebrew` * The brew formula `php` has to be installed (which version is detected) -* Laravel Valet 2.13 or higher +* Laravel Valet 2.16.2 or higher (older versions might be compatible but are not supported) -_You may need to update your Valet installation to keep everything working if a major version update of PHP has been released._ +_You may need to update your Valet installation to keep everything working if a major version update of PHP has been released. You can do this by running `composer global update && valet install`._ ## 🚀 How to install @@ -231,18 +231,30 @@ PHP Monitor itself doesn't do any network requests. Feel free to check the sourc
-After running PHP Monitor, Homebrew sometimes has issues with `brew upgrade`! +How do I get various applications to show up in the domain list's right-click menu? -This is a security feature of Brew. When you start a service as an administrator, the root user becomes the owner of relevant binaries. +When you select and right-click on a domain, you can open these directories with various applications. This can help speed up your workflow. However, for these apps to show up, they must be detected first. -You will need to manually clean up those folders yourself using `rm -rf` (or by manually removing those folders via Finder). +The supported apps are: PhpStorm, Visual Studio Code, Sublime Text, Sublime Merge, iTerm. + +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). +
+ +
+After running PHP Monitor, Homebrew sometimes has issues with `brew upgrade` or `brew cleanup`! + +This is a security feature of Homebrew. When you start a service as an administrator, the root user becomes the owner of relevant binaries. You will need to manually clean up those folders yourself using `rm -rf` (or by manually removing those folders via Finder). + +**Update**: If you are using the Valet switcher (currently not available in the latest stable build) you will not encounter this issue. For more information on this, see [this issue](https://github.com/nicoverbruggen/phpmon/issues/17) and also [this issue about switching to Valet's switcher](https://github.com/nicoverbruggen/phpmon/issues/34).
The app has crashed! -Please get in touch and open an issue. PHP Monitor shouldn't crash :) +Please get in touch and open an issue. PHP Monitor shouldn't crash... (unless you are actually removing PHP *while* the app is running, that’s considered normal behaviour!)
@@ -283,16 +295,7 @@ In order to save power, this only happens once every 60 seconds. This utility will detect which PHP versions you have installed via Homebrew, and then allows you to switch between them. -This means: - -- You have at least the latest version of PHP installed (`php`) -- You have installed Laravel Valet (`which valet` returns `/usr/local/bin/valet`) -- You ran `valet trust`, which means Valet commands can be run without using sudo - -The utility runs the following commands: - -- Unlink all detected PHP versions & stop the respective `php@X.X` services -- Link the desired version of PHP, and start the associated service +The switcher will disable all PHP-FPM services not belonging to the version you wish to use, and link the desired version of PHP. Then, it'll restart your desired PHP version's FPM process. This all happens in parallel, so this should be much faster than Valet’s switcher. ### Want to know more? diff --git a/SECURITY.md b/SECURITY.md index af0009a..c0a3e75 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,17 +2,25 @@ ## Supported versions -Generally speaking, only the latest version of **PHP Monitor** is supported: +Generally speaking, only the latest version of **PHP Monitor** is supported, except during transition periods (for example, when particular system requirements go up): -| Version | Apple silicon | Supported | Supported macOS | Deployment Target | Detected PHP Versions | -| ------- | ------------- | ------------------ | ----- | ----- | ----- | -| 4.0 | ✅ Universal binary | ✅ | Big Sur (11.0) and Monterey (12.0) | macOS 10.14+ | PHP 5.6—PHP 8.2 | -| 3.5 | ✅ Universal binary | ❌ | Big Sur (11.0) and Monterey (12.0) | macOS 10.14+ | PHP 5.6—PHP 8.2 | -| 3.0—3.4 | ✅ Universal binary | ❌ | Big Sur (11.0) | macOS 10.14+ | PHP 5.6—PHP 8.1 | -| 2.6 | ✅ Universal binary | ❌ | Big Sur (11.0) | macOS 10.14+ | PHP 5.6—PHP 8.0 | -| 2.5 | ✴️ Universal binary
`/usr/local/homebrew` installations only | ❌ | Big Sur (11.0)
Catalina (10.15) | macOS 10.14+ | not applicable | -| 2.4 | ✴️ Universal binary
`/usr/local/homebrew` installations only | ❌ | Big Sur (11.0)
Catalina (10.15) | macOS 10.14+ | not applicable | -| < 2.4 | ❌ Intel binary
`/usr/local/homebrew` installations only | ❌ | Catalina (10.15) | macOS 10.14+ | not applicable | +| Version | Apple silicon | Supported | Supported macOS | Deployment Target | Detected PHP Versions | Minimum Required Valet Version | +| ------- | ------------- | ------------------ | ----- | ----- | ----- | ---- +| 4.1 | ✅ Universal binary | ✅ Yes | Big Sur (11.0) and Monterey (12.0) | macOS 11+ | PHP 5.6—PHP 8.2 | 2.16.2 | + +## Legacy versions + +These versions of PHP Monitor are no longer supported, but if you’re using an older computer with an older version of Homebrew, Valet or macOS, you might want to use one of these versions. + +| Version | Apple silicon | Supported | Supported macOS | Deployment Target | Detected PHP Versions | Minimum Required Valet Version | +| ------- | ------------- | ------------------ | ----- | ----- | ----- | ---- +| 4.0 | ✅ Universal binary | ❌ | Big Sur (11.0) and Monterey (12.0) | macOS 10.14+ | PHP 5.6—PHP 8.2 | 2.13 | +| 3.5 | ✅ Universal binary | ❌ | Big Sur (11.0) and Monterey (12.0) | macOS 10.14+ | PHP 5.6—PHP 8.2 | 2.13 | +| 3.0—3.4 | ✅ Universal binary | ❌ | Big Sur (11.0) | macOS 10.14+ | PHP 5.6—PHP 8.1 | 2.13 | +| 2.6 | ✅ Universal binary | ❌ | Big Sur (11.0) | macOS 10.14+ | PHP 5.6—PHP 8.0 | 2.13 | +| 2.5 | ✴️ Universal binary
`/usr/local/homebrew` installations only | ❌ | Big Sur (11.0)
Catalina (10.15) | macOS 10.14+ | not applicable | not applicable | +| 2.4 | ✴️ Universal binary
`/usr/local/homebrew` installations only | ❌ | Big Sur (11.0)
Catalina (10.15) | macOS 10.14+ | not applicable | not applicable | +| < 2.4 | ❌ Intel binary
`/usr/local/homebrew` installations only | ❌ | Catalina (10.15) | macOS 10.14+ | not applicable | not applicable | ## Reporting a vulnerability diff --git a/docs/screenshot34.png b/docs/screenshot34.png deleted file mode 100644 index dd71242..0000000 Binary files a/docs/screenshot34.png and /dev/null differ diff --git a/docs/screenshot41.jpg b/docs/screenshot41.jpg new file mode 100644 index 0000000..0912a1f Binary files /dev/null and b/docs/screenshot41.jpg differ diff --git a/phpmon-tests/ValetConfigParserTest.swift b/phpmon-tests/ValetConfigParserTest.swift new file mode 100644 index 0000000..c0a61e5 --- /dev/null +++ b/phpmon-tests/ValetConfigParserTest.swift @@ -0,0 +1,38 @@ +// +// ValetConfigParserTest.swift +// phpmon-tests +// +// Created by Nico Verbruggen on 29/11/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import XCTest + +class ValetConfigParserTest: XCTestCase { + + static var jsonConfigFileUrl: URL { + return Bundle(for: Self.self).url( + forResource: "valet-config", + withExtension: "json" + )! + } + + func testCanLoadConfigFile() throws { + let json = try? String( + contentsOf: Self.jsonConfigFileUrl, + encoding: .utf8 + ) + let config = try! JSONDecoder().decode( + Valet.Configuration.self, + from: json!.data(using: .utf8)! + ) + + XCTAssertEqual(config.tld, "test") + XCTAssertEqual(config.paths, [ + "/Users/username/.config/valet/Sites", + "/Users/username/Sites" + ]) + XCTAssertEqual(config.loopback, "127.0.0.1") + } + +} diff --git a/phpmon-tests/ValetTest.swift b/phpmon-tests/ValetTest.swift new file mode 100644 index 0000000..6d5b31d --- /dev/null +++ b/phpmon-tests/ValetTest.swift @@ -0,0 +1,18 @@ +// +// ValetTest.swift +// phpmon-tests +// +// Created by Nico Verbruggen on 29/11/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import XCTest + +class ValetTest: XCTestCase { + + func testDetermineValetVersion() { + let version = Actions.valet("--version") + XCTAssert(version.contains("Laravel Valet 2.")) + } + +} diff --git a/phpmon-tests/VersionExtractorTest.swift b/phpmon-tests/VersionExtractorTest.swift new file mode 100644 index 0000000..38a7f28 --- /dev/null +++ b/phpmon-tests/VersionExtractorTest.swift @@ -0,0 +1,25 @@ +// +// VersionExtractorTest.swift +// phpmon-tests +// +// Created by Nico Verbruggen on 16/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import XCTest + +class VersionExtractorTest: XCTestCase { + + func testExtractVersion() { + XCTAssertEqual(VersionExtractor.from("Laravel Valet 2.17.1"), "2.17.1") + XCTAssertEqual(VersionExtractor.from("Laravel Valet 2.0"), "2.0") + } + + func testVersionComparison() { + XCTAssertEqual("2.0".versionCompare("2.1"), .orderedAscending) + XCTAssertEqual("2.1".versionCompare("2.0"), .orderedDescending) + XCTAssertEqual("2.0".versionCompare("2.0"), .orderedSame) + XCTAssertEqual("2.17.0".versionCompare("2.17.1"), .orderedAscending) + } + +} diff --git a/phpmon-tests/valet-config.json b/phpmon-tests/valet-config.json new file mode 100644 index 0000000..713f006 --- /dev/null +++ b/phpmon-tests/valet-config.json @@ -0,0 +1,8 @@ +{ + "tld": "test", + "paths": [ + "/Users/username/.config/valet/Sites", + "/Users/username/Sites" + ], + "loopback": "127.0.0.1" +} diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/Contents.json b/phpmon/Assets.xcassets/AppIconBeta.appiconset/Contents.json new file mode 100644 index 0000000..64dc11e --- /dev/null +++ b/phpmon/Assets.xcassets/AppIconBeta.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "filename" : "icon_16x16.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "filename" : "icon_16x16@2x.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "filename" : "icon_32x32.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "filename" : "icon_32x32@2x.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "filename" : "icon_128x128.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "filename" : "icon_128x128@2x.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "filename" : "icon_256x256.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "filename" : "icon_256x256@2x.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "filename" : "icon_512x512.png", + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "filename" : "icon_512x512@2x.png", + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_128x128.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_128x128.png new file mode 100644 index 0000000..67950a5 Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_128x128.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_128x128@2x.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_128x128@2x.png new file mode 100644 index 0000000..bca82db Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_128x128@2x.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_16x16.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_16x16.png new file mode 100644 index 0000000..f0eb45e Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_16x16.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_16x16@2x.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_16x16@2x.png new file mode 100644 index 0000000..7727960 Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_16x16@2x.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_256x256.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_256x256.png new file mode 100644 index 0000000..bca82db Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_256x256.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_256x256@2x.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_256x256@2x.png new file mode 100644 index 0000000..3c25ee2 Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_256x256@2x.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_32x32.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_32x32.png new file mode 100644 index 0000000..7727960 Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_32x32.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_32x32@2x.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_32x32@2x.png new file mode 100644 index 0000000..4708c68 Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_32x32@2x.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_512x512.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_512x512.png new file mode 100644 index 0000000..3c25ee2 Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_512x512.png differ diff --git a/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_512x512@2x.png b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_512x512@2x.png new file mode 100644 index 0000000..ade05f1 Binary files /dev/null and b/phpmon/Assets.xcassets/AppIconBeta.appiconset/icon_512x512@2x.png differ diff --git a/phpmon/Assets.xcassets/IconLinked.imageset/Contents.json b/phpmon/Assets.xcassets/IconLinked.imageset/Contents.json new file mode 100644 index 0000000..6cb3d9a --- /dev/null +++ b/phpmon/Assets.xcassets/IconLinked.imageset/Contents.json @@ -0,0 +1,24 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "link.svg", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/phpmon/Assets.xcassets/IconLinked.imageset/link.svg b/phpmon/Assets.xcassets/IconLinked.imageset/link.svg new file mode 100644 index 0000000..f0fdbf4 --- /dev/null +++ b/phpmon/Assets.xcassets/IconLinked.imageset/link.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/phpmon/Assets.xcassets/IconParked.imageset/Contents.json b/phpmon/Assets.xcassets/IconParked.imageset/Contents.json new file mode 100644 index 0000000..24b6de7 --- /dev/null +++ b/phpmon/Assets.xcassets/IconParked.imageset/Contents.json @@ -0,0 +1,24 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "car-alt.svg", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/phpmon/Assets.xcassets/IconParked.imageset/car-alt.svg b/phpmon/Assets.xcassets/IconParked.imageset/car-alt.svg new file mode 100644 index 0000000..90a786e --- /dev/null +++ b/phpmon/Assets.xcassets/IconParked.imageset/car-alt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/phpmon/Assets.xcassets/Lock.imageset/Contents.json b/phpmon/Assets.xcassets/Lock.imageset/Contents.json new file mode 100644 index 0000000..d874efc --- /dev/null +++ b/phpmon/Assets.xcassets/Lock.imageset/Contents.json @@ -0,0 +1,24 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Locked.svg", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/phpmon/Assets.xcassets/Lock.imageset/Locked.svg b/phpmon/Assets.xcassets/Lock.imageset/Locked.svg new file mode 100644 index 0000000..60564f5 --- /dev/null +++ b/phpmon/Assets.xcassets/Lock.imageset/Locked.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/phpmon/Assets.xcassets/LockUnlocked.imageset/Contents.json b/phpmon/Assets.xcassets/LockUnlocked.imageset/Contents.json new file mode 100644 index 0000000..956848a --- /dev/null +++ b/phpmon/Assets.xcassets/LockUnlocked.imageset/Contents.json @@ -0,0 +1,24 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Unlocked.svg", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/phpmon/Assets.xcassets/LockUnlocked.imageset/Unlocked.svg b/phpmon/Assets.xcassets/LockUnlocked.imageset/Unlocked.svg new file mode 100644 index 0000000..69e0af7 --- /dev/null +++ b/phpmon/Assets.xcassets/LockUnlocked.imageset/Unlocked.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/phpmon/Assets.xcassets/StatusBarIconStatic.imageset/phpmon@2x.png b/phpmon/Assets.xcassets/StatusBarIconStatic.imageset/phpmon@2x.png index 76e40b3..9defc15 100644 Binary files a/phpmon/Assets.xcassets/StatusBarIconStatic.imageset/phpmon@2x.png and b/phpmon/Assets.xcassets/StatusBarIconStatic.imageset/phpmon@2x.png differ diff --git a/phpmon/Assets.xcassets/StatusBarPHP.imageset/Contents.json b/phpmon/Assets.xcassets/StatusBarPHP.imageset/Contents.json new file mode 100644 index 0000000..effdb9c --- /dev/null +++ b/phpmon/Assets.xcassets/StatusBarPHP.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "php@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/phpmon/Assets.xcassets/StatusBarPHP.imageset/php@2x.png b/phpmon/Assets.xcassets/StatusBarPHP.imageset/php@2x.png new file mode 100644 index 0000000..497b4a8 Binary files /dev/null and b/phpmon/Assets.xcassets/StatusBarPHP.imageset/php@2x.png differ diff --git a/phpmon/Constants.swift b/phpmon/Constants.swift index 483da6a..50f5c27 100644 --- a/phpmon/Constants.swift +++ b/phpmon/Constants.swift @@ -15,6 +15,16 @@ class Constants { */ static let LatestStablePhpVersion = "8.1" + /** + The minimum version of Valet that is recommended. + If the installed version is older, a notification will be shown + every time the app launches (with a recommendation to upgrade). + + The minimum requirement is currently synced to PHP 8.1 compatibility. + See also: https://github.com/laravel/valet/releases/tag/v2.16.2 + */ + static let MinimumRecommendedValetVersion = "2.16.2" + /** * The PHP versions supported by this application. * Versions that do not appear in this array are omitted from the list. diff --git a/phpmon/Domain/Core/Actions.swift b/phpmon/Domain/Core/Actions.swift index 00cc313..5bbc098 100644 --- a/phpmon/Domain/Core/Actions.swift +++ b/phpmon/Domain/Core/Actions.swift @@ -23,7 +23,7 @@ class Actions { let phpAlias = App.shared.brewPhpVersion // Avoid inserting a duplicate - if (!versionsOnly.contains(phpAlias)) { + if (!versionsOnly.contains(phpAlias) && Shell.fileExists("\(Paths.optPath)/php/bin/php")) { versionsOnly.append(phpAlias); } @@ -102,6 +102,19 @@ class Actions { brew("services stop dnsmasq", sudo: true) } + /** + Kindly asks Valet to switch to a specific PHP version. + */ + public static func switchToPhpVersionUsingValet( + version: String, + availableVersions: [String], + completed: @escaping () -> Void + ) { + print("Switching to \(version) using Valet") + print(valet("use php@\(version)")) + completed() + } + /** Switching to a new PHP version involves: - unlinking the current version @@ -178,9 +191,14 @@ class Actions { // MARK: - Quick Fix /** - Detects all currently available PHP versions, and unlinks each and every one of them. - After this, the brew services are also stopped, the latest PHP version is linked, and php + nginx are restarted. - If this does not solve the issue, the user may need to install additional extensions and/or run `composer global update`. + Detects all currently available PHP versions, + and unlinks each and every one of them. + + After this, the brew services are also stopped, + the latest PHP version is linked, and php + nginx are restarted. + + If this does not solve the issue, the user may need to install additional + extensions and/or run `composer global update`. */ public static func fixMyPhp() { @@ -203,6 +221,14 @@ class Actions { // MARK: Common Shell Commands + /** + Runs a `valet` command. + */ + public static func valet(_ command: String) -> String + { + return Shell.pipe("sudo \(Paths.valet) \(command)", requiresPath: true) + } + /** Runs a `brew` command. Can run as superuser. */ @@ -220,7 +246,8 @@ class Actions { let e_original = original.replacingOccurrences(of: "/", with: "\\/") let e_replacement = replacement.replacingOccurrences(of: "/", with: "\\/") - // Check if gsed exists; it is able to follow symlinks, which we want to do to toggle the extension + // Check if gsed exists; it is able to follow symlinks, + // which we want to do to toggle the extension if Shell.fileExists("\(Paths.binPath)/gsed") { Shell.run("\(Paths.binPath)/gsed -i --follow-symlinks 's/\(e_original)/\(e_replacement)/g' \(file)") } else { diff --git a/phpmon/Domain/Core/App+ActivationPolicy.swift b/phpmon/Domain/Core/App+ActivationPolicy.swift new file mode 100644 index 0000000..f031301 --- /dev/null +++ b/phpmon/Domain/Core/App+ActivationPolicy.swift @@ -0,0 +1,44 @@ +// +// App+ActivationPolicy.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 05/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Cocoa +import Foundation + +extension App { + + // MARK: - Application State + + /** + Registers a window as currently open. + */ + public func register(window name: String) { + if !openWindows.contains(name) { + openWindows.append(name) + } + updateActivationPolicy() + } + + /** + Removes a window, assuming it was closed. + */ + public func remove(window name: String) { + openWindows.removeAll { window in + window == name + } + updateActivationPolicy() + } + + /** + If there are any open windows, the app will be a regular app. + If there are no windows open, the app will be an accessory (toolbar) app. + */ + public func updateActivationPolicy() { + NSApp.setActivationPolicy(openWindows.count > 0 ? .regular : .accessory) + } + +} diff --git a/phpmon/Domain/Core/App+GlobalHotkey.swift b/phpmon/Domain/Core/App+GlobalHotkey.swift new file mode 100644 index 0000000..8f4f54c --- /dev/null +++ b/phpmon/Domain/Core/App+GlobalHotkey.swift @@ -0,0 +1,55 @@ +// +// App+GlobalHotkey.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 05/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import HotKey +import Cocoa + +extension App { + + // MARK: - Methods + + /** + On startup, the preferences should be loaded from the .plist, + and we'll enable the shortcut if it is set. + */ + func loadGlobalHotkey() { + // Make sure we can retrieve the hotkey from preferences + guard let hotkey = Preferences.preferences[.globalHotkey] as? String else { + print("No global hotkey was saved in preferences. None set.") + return + } + + // Make sure we can parse the JSON into the desired format + guard let keybindPref = GlobalKeybindPreference.fromJson(hotkey) else { + print("No global hotkey loaded, could not be parsed!") + shortcutHotkey = nil + return + } + + shortcutHotkey = HotKey(keyCombo: KeyCombo( + carbonKeyCode: keybindPref.keyCode, + carbonModifiers: keybindPref.carbonFlags + )) + } + + /** + Sets up the action that needs to occur when the shortcut key is pressed + (opens the menu). + */ + func setupGlobalHotkeyListener() { + guard let hotkey = shortcutHotkey else { + return + } + + hotkey.keyDownHandler = { + MainMenu.shared.statusItem.button?.performClick(nil) + NSApplication.shared.activate(ignoringOtherApps: true) + } + } + +} diff --git a/phpmon/Domain/Core/App.swift b/phpmon/Domain/Core/App.swift index 49069e7..73ec015 100644 --- a/phpmon/Domain/Core/App.swift +++ b/phpmon/Domain/Core/App.swift @@ -10,10 +10,16 @@ import HotKey class App { + // MARK: Static Vars + + /** The static app instance. Accessible at any time. */ static let shared = App() - init() { - loadGlobalHotkey() + /** Retrieve the version number from the main info dictionary, Info.plist. */ + static var version: String { + let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String + let build = Bundle.main.infoDictionary?["CFBundleVersion"] as! String + return "\(version) (\(build))" } /** Information about the currently linked PHP installation. */ @@ -26,42 +32,36 @@ class App { return App.shared.busy } + // MARK: Variables + /** The list of preferences that are currently active. */ var preferences: [PreferenceName: Bool]! - /** - The window controller of the currently active window. - */ - var windowController: NSWindowController? = nil + /** The window controller of the currently active preferences window. */ + var preferencesWindowController: PrefsWC? = nil - /** - Whether the application is busy switching versions. - */ + /** The window controller of the currently active site list window. */ + var siteListWindowController: SiteListWC? = nil + + /** Whether the application is busy switching versions. */ var busy: Bool = false - /** - The currently active installation of PHP. - */ + /** The currently active installation of PHP. */ var currentInstall: ActivePhpInstallation? = nil - /** - All available versions of PHP. - */ - var availablePhpVersions : [String] = [] + /** All available versions of PHP. */ + var availablePhpVersions: [String] = [] - /** - Cached information about the PHP installations; contains only the full version number at this point. - */ - var cachedPhpInstallations : [String: PhpInstallation] = [:] + /** Cached information about the PHP installations. */ + var cachedPhpInstallations: [String: PhpInstallation] = [:] - /** - The timer that will periodically fetch the PHP version that is currently active. - */ + /** List of detected (installed) applications that PHP Monitor can work with. */ + var detectedApplications: [Application] = [] + + /** Timer that will periodically reload info about the user's PHP installation. */ var timer: Timer? - /** - Information we were able to discern from the Homebrew info command (as JSON). - */ + /** Information we were able to discern from the Homebrew info command (as JSON). */ var brewPhpPackage: HomebrewPackage! = nil { didSet { brewPhpVersion = brewPhpPackage!.version @@ -79,52 +79,27 @@ class App { */ var brewPhpVersion: String = Constants.LatestStablePhpVersion + // MARK: - Global Hotkey + /** The shortcut the user has requested. */ var shortcutHotkey: HotKey? = nil { didSet { - self.setupGlobalHotkeyListener() + setupGlobalHotkeyListener() } } - // MARK: - Methods + // MARK: - Activation Policy /** - On startup, the preferences should be loaded from the .plist, and we'll enable the shortcut if it is set. + Variable that keeps track of which windows are currently open. + (Please note that window controllers remain open in memory once opened.) + + When this list is updated, the app activation policy is re-evaluated. + The app activation policy dictates how the app runs + (as a normal app or as a toolbar app). */ - private func loadGlobalHotkey() { - // Make sure we can retrieve the hotkey from preferences; if we cannot, no hotkey is set - guard let hotkey = Preferences.preferences[.globalHotkey] as? String else { - print("No global hotkey loaded") - return - } - - // Make sure we can parse the JSON into the desired format; if we cannot, no hotkey is set - guard let keybindPref = GlobalKeybindPreference.fromJson(hotkey) else { - print("No global hotkey loaded, could not be parsed!") - self.shortcutHotkey = nil - return - } - - self.shortcutHotkey = HotKey(keyCombo: KeyCombo( - carbonKeyCode: keybindPref.keyCode, - carbonModifiers: keybindPref.carbonFlags - )) - } - - /** - Sets up the action that needs to occur when the shortcut key is pressed (open the menu). - */ - private func setupGlobalHotkeyListener() { - guard let hotkey = self.shortcutHotkey else { - return - } - - hotkey.keyDownHandler = { - MainMenu.shared.statusItem.button?.performClick(nil) - NSApplication.shared.activate(ignoringOtherApps: true) - } - } + var openWindows: [String] = [] } diff --git a/phpmon/Domain/Core/AppDelegate+MenuOutlets.swift b/phpmon/Domain/Core/AppDelegate+MenuOutlets.swift new file mode 100644 index 0000000..3d13d92 --- /dev/null +++ b/phpmon/Domain/Core/AppDelegate+MenuOutlets.swift @@ -0,0 +1,40 @@ +// +// AppDelegate+MenuOutlets.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 05/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation + +/** + Any outlets connected to the app's main menu (not the menu that shows when the icon in + the menu bar is clicked, but the regular app's main menu) are configured here. + + Default interactions like copy/paste, select all, close window etc. are wired up by + default in the storyboard and do not need to be manually added. + + Extra functionality (like the menu item to reload the list of sites) does, however. + + - Note: This menu is only displayed when the app is NOT running in accessory mode. + For more information about this, please see the ActivationPolicy-related extension. + */ +extension AppDelegate { + + // MARK: - Menu Interactions + + @IBAction func reloadSiteListPressed(_ sender: Any) { + let vc = App.shared.siteListWindowController? + .window?.contentViewController as? SiteListVC + + if vc != nil { + // If the view exists, directly reload the list of sites + vc!.reloadSites() + } else { + // If the view does not exist, reload the cached data that was populated when the app initially launched. + Valet.shared.reloadSites() + } + } + +} diff --git a/phpmon/Domain/Core/AppDelegate+Notifications.swift b/phpmon/Domain/Core/AppDelegate+Notifications.swift new file mode 100644 index 0000000..3feff20 --- /dev/null +++ b/phpmon/Domain/Core/AppDelegate+Notifications.swift @@ -0,0 +1,42 @@ +// +// AppDelegate+Notifications.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 06/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation +import UserNotifications + +extension AppDelegate { + + // MARK: - Notifications + + public func setupNotifications() { + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.delegate = self + notificationCenter.requestAuthorization(options: [.alert], completionHandler: { granted, error in + if !granted { + print("PHP Monitor does not have permission to show notifications.") + } + if let error = error { + print("PHP Monitor encounted an error determining notification permissions:") + print(error) + } + }) + } + + /** + Ensure that the application displays notifications even when the app is active. + */ + func userNotificationCenter( + _ center: UNUserNotificationCenter, + willPresent notification: UNNotification, + withCompletionHandler completionHandler: + @escaping (UNNotificationPresentationOptions) -> Void + ) { + completionHandler([.banner]) + } + +} diff --git a/phpmon/AppDelegate.swift b/phpmon/Domain/Core/AppDelegate.swift similarity index 66% rename from phpmon/AppDelegate.swift rename to phpmon/Domain/Core/AppDelegate.swift index d0d3839..a963b6e 100644 --- a/phpmon/AppDelegate.swift +++ b/phpmon/Domain/Core/AppDelegate.swift @@ -9,7 +9,7 @@ import Cocoa import UserNotifications @NSApplicationMain -class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate { +class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate { // MARK: - Variables @@ -38,16 +38,27 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele */ let paths: Paths + /** + The Valet singleton that determines all information + about Valet and its current configuration. + */ + let valet: Valet + // MARK: - Initializer /** When the application initializes, create all singletons. */ override init() { + print("==================================") + print("PHP MONITOR by Nico Verbruggen") + print("Version \(App.version)") + print("==================================") self.sharedShell = Shell.user self.state = App.shared self.menu = MainMenu.shared self.paths = Paths.shared + self.valet = Valet.shared super.init() } @@ -55,27 +66,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele /** When the application has finished launching, we'll want to set up - the user notification center delegate, and kickoff the menu + the user notification center permissions, and kickoff the menu startup procedure. */ func applicationDidFinishLaunching(_ aNotification: Notification) { - NSUserNotificationCenter.default.delegate = self - self.menu.startup() - } - - // MARK: - NSUserNotificationCenterDelegate - - /** - When a notification is sent, the delegate of the notification center - is asked whether the notification should be presented or not. Since - the user can now disable notifications per application since macOS - Catalina, any and all notifications should be displayed. - */ - func userNotificationCenter( - _ center: NSUserNotificationCenter, - shouldPresent notification: NSUserNotification - ) -> Bool { - return true + // Make sure notifications will work + setupNotifications() + // Make sure the menu performs its initial checks + menu.startup() } } diff --git a/phpmon/Domain/Core/Base.lproj/Main.storyboard b/phpmon/Domain/Core/Base.lproj/Main.storyboard index 5d786e3..3182914 100644 --- a/phpmon/Domain/Core/Base.lproj/Main.storyboard +++ b/phpmon/Domain/Core/Base.lproj/Main.storyboard @@ -1,8 +1,10 @@ - + - + + + @@ -31,6 +33,249 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -49,11 +294,11 @@ - + - + @@ -68,6 +313,10 @@ + + + + @@ -84,205 +333,252 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpmon/Domain/Core/Startup.swift b/phpmon/Domain/Core/Startup.swift index 42ebfa7..b42c8ab 100644 --- a/phpmon/Domain/Core/Startup.swift +++ b/phpmon/Domain/Core/Startup.swift @@ -26,7 +26,7 @@ class Startup { performEnvironmentCheck( !Shell.fileExists("\(Paths.binPath)/php"), messageText: "startup.errors.php_binary.title".localized, - informativeText: "startup.errors.php_binary_desc".localized, + informativeText: "startup.errors.php_binary.desc".localized, breaking: true ) diff --git a/phpmon/Domain/Extensions/StringExtension.swift b/phpmon/Domain/Extensions/StringExtension.swift index 778eebb..78fec16 100644 --- a/phpmon/Domain/Extensions/StringExtension.swift +++ b/phpmon/Domain/Extensions/StringExtension.swift @@ -12,6 +12,10 @@ extension String { return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "") } + func localized(_ args: CVarArg...) -> String { + String(format: self.localized, arguments: args) + } + func countInstances(of stringToFind: String) -> Int { if (stringToFind.isEmpty) { return 0 @@ -34,4 +38,37 @@ extension String { return String(self[start ..< end]) } + // Code taken from: https://sarunw.com/posts/how-to-compare-two-app-version-strings-in-swift/ + /* + <1> We split the version by period (.). + <2> Then, we find the difference of digit that we will zero pad. + <3> If there are no differences, we don't need to do anything and use simple .compare. + <4> We populate an array of missing zero. + <5> We add zero pad array to a version with a fewer period and zero. + <6> We user array components to build back our versions from components and compare them. + This time it will have the same period and number of digit. + */ + func versionCompare(_ otherVersion: String) -> ComparisonResult { + let versionDelimiter = "." + + var versionComponents = self.components(separatedBy: versionDelimiter) // <1> + var otherVersionComponents = otherVersion.components(separatedBy: versionDelimiter) + + let zeroDiff = versionComponents.count - otherVersionComponents.count // <2> + + if zeroDiff == 0 { // <3> + // Same format, compare normally + return self.compare(otherVersion, options: .numeric) + } else { + let zeros = Array(repeating: "0", count: abs(zeroDiff)) // <4> + if zeroDiff > 0 { + otherVersionComponents.append(contentsOf: zeros) // <5> + } else { + versionComponents.append(contentsOf: zeros) + } + return versionComponents.joined(separator: versionDelimiter) + .compare(otherVersionComponents.joined(separator: versionDelimiter), options: .numeric) // <6> + } + } + } diff --git a/phpmon/Domain/Helpers/Alert.swift b/phpmon/Domain/Helpers/Alert.swift index 735abad..d59c2f2 100644 --- a/phpmon/Domain/Helpers/Alert.swift +++ b/phpmon/Domain/Helpers/Alert.swift @@ -27,8 +27,38 @@ class Alert { return alert.runModal() == .alertFirstButtonReturn } + public static func confirm( + onWindow window: NSWindow, + messageText: String, + informativeText: String, + buttonTitle: String = "OK", + secondButtonTitle: String = "Cancel", + style: NSAlert.Style = .warning, + onFirstButtonPressed: @escaping (() -> Void) + ) { + let alert = NSAlert.init() + alert.alertStyle = style + alert.messageText = messageText + alert.informativeText = informativeText + alert.addButton(withTitle: buttonTitle) + if (!secondButtonTitle.isEmpty) { + alert.addButton(withTitle: secondButtonTitle) + } + alert.beginSheetModal(for: window) { response in + if response == .alertFirstButtonReturn { + onFirstButtonPressed() + } + } + } + public static func notify(message: String, info: String, style: NSAlert.Style = .informational) { - _ = self.present(messageText: message, informativeText: info, buttonTitle: "OK", secondButtonTitle: "", style: style) + _ = present( + messageText: message, + informativeText: info, + buttonTitle: "OK", + secondButtonTitle: "", + style: style + ) } } diff --git a/phpmon/Domain/Helpers/Application.swift b/phpmon/Domain/Helpers/Application.swift new file mode 100644 index 0000000..6bd64f1 --- /dev/null +++ b/phpmon/Domain/Helpers/Application.swift @@ -0,0 +1,64 @@ +// +// Editor.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 07/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation + +/// An application that is capable of opening a particular directory (usually of a PHP project). +/// In most cases this is going to be a code editor, but it could also be another application +/// that supports opening those directories, like a visual Git client or a terminal app. +class Application { + + enum AppType { + case editor, browser, git_gui, terminal + } + + /// Name of the app. Used for display purposes and to determine `name.app` exists. + let name: String + + /// Application type. Depending on the type, a different action might occur. + let type: AppType + + /// Initializer. Used to detect a specific app of a specific type. + init(_ name: String, _ type: AppType) { + self.name = name + self.type = type + } + + /** + Attempt to open a specific directory in the app of choice. + (This will open the app if it isn't open yet.) + */ + @objc public func openDirectory(file: String) { + return Shell.run("/usr/bin/open -a \"\(name)\" \(file)") + } + + /** Checks if the app is installed. */ + func isInstalled() -> Bool { + // If this script does not complain, the app exists! + return Shell.user.execute( + "/usr/bin/open -Ra \"\(name)\"", + requiresPath: false, + waitUntilExit: true + ).task.terminationStatus == 0 + } + + /** + Detect which apps are available to open a specific directory. + */ + static public func detectPresetApplications() -> [Application] { + return [ + Application("PhpStorm", .editor), + Application("Visual Studio Code", .editor), + Application("Sublime Text", .editor), + Application("Sublime Merge", .git_gui), + Application("iTerm", .terminal) + ].filter { + return $0.isInstalled() + } + } +} diff --git a/phpmon/Domain/Helpers/Filesystem.swift b/phpmon/Domain/Helpers/Filesystem.swift new file mode 100644 index 0000000..808f05e --- /dev/null +++ b/phpmon/Domain/Helpers/Filesystem.swift @@ -0,0 +1,23 @@ +// +// FileSystem.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 07/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +class Filesystem { + + /** + Checks if a file exists at the provided path. + Uses `FileManager`. + */ + public static func fileExists(_ path: String) -> Bool { + return FileManager.default.fileExists( + atPath: path.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)") + ) + } + +} diff --git a/phpmon/Domain/Helpers/LocalNotification.swift b/phpmon/Domain/Helpers/LocalNotification.swift index c279840..8bf0da2 100644 --- a/phpmon/Domain/Helpers/LocalNotification.swift +++ b/phpmon/Domain/Helpers/LocalNotification.swift @@ -6,14 +6,28 @@ // import Foundation +import UserNotifications class LocalNotification { public static func send(title: String, subtitle: String) { - let notification = NSUserNotification() - notification.title = title - notification.subtitle = subtitle - NSUserNotificationCenter.default.deliver(notification) + let content = UNMutableNotificationContent() + content.title = title + content.body = subtitle + + let uuidString = UUID().uuidString + let request = UNNotificationRequest( + identifier: uuidString, + content: content, + trigger: nil + ) + + let notificationCenter = UNUserNotificationCenter.current() + notificationCenter.add(request) { (error) in + if error != nil { + print(error!) + } + } } } diff --git a/phpmon/Domain/Helpers/MenuBarImageGenerator.swift b/phpmon/Domain/Helpers/MenuBarImageGenerator.swift index 814d6d8..ee95f99 100644 --- a/phpmon/Domain/Helpers/MenuBarImageGenerator.swift +++ b/phpmon/Domain/Helpers/MenuBarImageGenerator.swift @@ -41,6 +41,7 @@ class MenuBarImageGenerator { let textRect = CGRect(x: padding, y: 0.5, width: image.size.width, height: image.size.height) let targetImage: NSImage = NSImage(size: image.size) + let rep: NSBitmapImageRep = NSBitmapImageRep( bitmapDataPlanes: nil, pixelsWide: Int(image.size.width), @@ -56,7 +57,7 @@ class MenuBarImageGenerator { targetImage.addRepresentation(rep) targetImage.lockFocus() - + image.draw(in: imageRect) text.draw(in: textRect, withAttributes: textFontAttributes) @@ -64,4 +65,34 @@ class MenuBarImageGenerator { return targetImage } + public static func textToImageWithIcon(text: String) -> NSImage { + let textImage = self.textToImage(text: text) + let iconImage = NSImage(named: "StatusBarPHP")! + let iconWidthSize = iconImage.size.width + let divider = iconWidthSize + + let imageRect = CGRect( + x: 0, + y: 0, + width: textImage.size.width + divider, + height: textImage.size.height + ) + + let image: NSImage = NSImage(size: imageRect.size) + image.lockFocus() + + let difference = imageRect.size.width - textImage.size.width + + textImage.draw(in: imageRect, from: NSRect( + x: -difference, + y: 0, width: textImage.size.width + difference, + height: textImage.size.height + ), operation: .overlay, fraction: 1) + + iconImage.draw(in: imageRect, from: NSRect(x: 0, y: 0, width: imageRect.size.width * 1.6, height: imageRect.size.height * 2.0), operation: .overlay, fraction: 1) + + image.unlockFocus() + return image + } + } diff --git a/phpmon/Domain/Helpers/PMWindowController.swift b/phpmon/Domain/Helpers/PMWindowController.swift new file mode 100644 index 0000000..3165a36 --- /dev/null +++ b/phpmon/Domain/Helpers/PMWindowController.swift @@ -0,0 +1,48 @@ +// +// PMWindowController.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 05/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +/** + This window class keeps track of which windows are currently visible, and reports this info back to the App class. + For more information, check the `windows` property on `App`. + + - Note: This class does make a simple assumption: each window controller corresponds to a single view. + */ +class PMWindowController: NSWindowController, NSWindowDelegate { + + public var windowName: String { + fatalError("Please specify a window name") + } + + override func showWindow(_ sender: Any?) { + super.showWindow(sender) + App.shared.register(window: windowName) + } + + public func positionWindowInTopLeftCorner() { + guard let frame = NSScreen.main?.frame else { return } + guard let window = self.window else { return } + + window.setFrame(NSRect( + x: frame.size.width - window.frame.size.width - 20, + y: frame.size.height - window.frame.size.height - 40, + width: window.frame.width, + height: window.frame.height + ), display: true) + } + + func windowWillClose(_ notification: Notification) { + App.shared.remove(window: windowName) + } + + deinit { + print("Window controller '\(windowName)' was deinitialized") + } + +} diff --git a/phpmon/Domain/Helpers/Timer.swift b/phpmon/Domain/Helpers/Timer.swift new file mode 100644 index 0000000..f3b2ce3 --- /dev/null +++ b/phpmon/Domain/Helpers/Timer.swift @@ -0,0 +1,32 @@ +// +// BenchmarkTimer.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 10/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation + +class BenchmarkTimer { + let startTime: CFAbsoluteTime + var endTime: CFAbsoluteTime? + + init() { + startTime = CFAbsoluteTimeGetCurrent() + } + + func stop() -> CFAbsoluteTime { + endTime = CFAbsoluteTimeGetCurrent() + + return duration! + } + + var duration: CFAbsoluteTime? { + if let endTime = endTime { + return endTime - startTime + } else { + return nil + } + } +} diff --git a/phpmon/Domain/Helpers/VersionExtractor.swift b/phpmon/Domain/Helpers/VersionExtractor.swift new file mode 100644 index 0000000..81bb05b --- /dev/null +++ b/phpmon/Domain/Helpers/VersionExtractor.swift @@ -0,0 +1,37 @@ +// +// VersionExtractor.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 16/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation + +class VersionExtractor { + + public static func from(_ string: String) -> String? { + let regex = try! NSRegularExpression( + pattern: #"Laravel Valet (?(\d+)(.)(\d+)((.)(\d+))?)"#, + options: [] + ) + + let match = regex.matches( + in: string, + options: [], + range: NSMakeRange(0, string.count) + ).first + + guard let match = match else { + return nil + } + + let range = Range( + match.range(withName: "version"), + in: string + )! + + return String(string[range]) + } + +} diff --git a/phpmon/Domain/Helpers/HomebrewDiagnostics.swift b/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift similarity index 96% rename from phpmon/Domain/Helpers/HomebrewDiagnostics.swift rename to phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift index 7c14556..fd327a8 100644 --- a/phpmon/Domain/Helpers/HomebrewDiagnostics.swift +++ b/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift @@ -18,8 +18,8 @@ class HomebrewDiagnostics { var errors: [HomebrewDiagnostics.Errors] = [] init() { - if self.determineAliasConflicts() { - self.errors.append(.aliasConflict) + if determineAliasConflicts() { + errors.append(.aliasConflict) } } diff --git a/phpmon/Domain/Helpers/HomebrewPackage.swift b/phpmon/Domain/Integrations/Homebrew/HomebrewPackage.swift similarity index 86% rename from phpmon/Domain/Helpers/HomebrewPackage.swift rename to phpmon/Domain/Integrations/Homebrew/HomebrewPackage.swift index 3b2ea9b..062e153 100644 --- a/phpmon/Domain/Helpers/HomebrewPackage.swift +++ b/phpmon/Domain/Integrations/Homebrew/HomebrewPackage.swift @@ -16,7 +16,8 @@ struct HomebrewPackage: Decodable { let linked_keg: String? public var version: String { - return aliases.first!.replacingOccurrences(of: "php@", with: "") + return aliases.first! + .replacingOccurrences(of: "php@", with: "") } } diff --git a/phpmon/Domain/Integrations/Valet/Valet.swift b/phpmon/Domain/Integrations/Valet/Valet.swift new file mode 100644 index 0000000..0759406 --- /dev/null +++ b/phpmon/Domain/Integrations/Valet/Valet.swift @@ -0,0 +1,168 @@ +// +// Valet.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 29/11/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation + +class Valet { + + static let shared = Valet() + + /// The version of Valet that was detected. + var version: String + + /// The Valet configuration file. + var config: Valet.Configuration + + /// A cached list of sites that were detected after analyzing the paths set up for Valet. + var sites: [Site] = [] + + init() { + version = VersionExtractor.from(Actions.valet("--version")) + ?? "UNKNOWN" + + let file = FileManager.default.homeDirectoryForCurrentUser + .appendingPathComponent(".config/valet/config.json") + + config = try! JSONDecoder().decode( + Valet.Configuration.self, + from: try! String(contentsOf: file, encoding: .utf8).data(using: .utf8)! + ) + + self.sites = [] + } + + public func startPreloadingSites() { + 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() { + resolvePaths(tld: config.tld) + } + + public func validateVersion() -> Void { + if version == "UNKNOWN" { + return print("The Valet version could not be extracted... that does not bode well.") + } + + if version.versionCompare(Constants.MinimumRecommendedValetVersion) == .orderedAscending { + let version = version + print("Valet version \(version) is too old! (recommended: \(Constants.MinimumRecommendedValetVersion))") + DispatchQueue.main.async { + Alert.notify(message: "alert.min_valet_version.title".localized, info: "alert.min_valet_version.info".localized(version, Constants.MinimumRecommendedValetVersion)) + } + } else { + print("Valet version \(version) is recent enough, OK (recommended: \(Constants.MinimumRecommendedValetVersion))") + } + } + + private func resolvePaths(tld: String) { + sites = [] + + for path in config.paths { + let entries = try! FileManager.default.contentsOfDirectory(atPath: path) + for entry in entries { + resolvePath(entry, forPath: path, tld: tld) + } + } + } + + private func resolvePath(_ entry: String, forPath path: String, tld: String) { + let siteDir = path + "/" + entry + + // See if the file is a symlink, if so, resolve it + let attrs = try! FileManager.default.attributesOfItem(atPath: siteDir) + + // We can also determine whether the thing at the path is a directory, too + let type = attrs[FileAttributeKey.type] as! FileAttributeType + + if type == FileAttributeType.typeSymbolicLink { + sites.append(Site(aliasPath: siteDir, tld: tld)) + } else if type == FileAttributeType.typeDirectory { + sites.append(Site(absolutePath: siteDir, tld: tld)) + } + } + + // MARK: - Structs + + class Site { + /// Name of the site. Does not include the TLD. + var name: String! + + /// The absolute path to the directory that is served. + var absolutePath: String! + + /// Location of the alias. If set, this is a linked domain. + var aliasPath: String? + + /// Whether the site has been secured. + var secured: Bool! + + /// What driver is currently in use. If not detected, defaults to nil. + var driver: String? = nil + + init() {} + + convenience init(absolutePath: String, tld: String) { + self.init() + self.absolutePath = absolutePath + self.name = URL(string: absolutePath)!.lastPathComponent + self.aliasPath = nil + determineSecured(tld) + determineDriver() + } + + convenience init(aliasPath: String, tld: String) { + self.init() + self.absolutePath = try! FileManager.default.destinationOfSymbolicLink(atPath: aliasPath) + self.name = URL(string: aliasPath)!.lastPathComponent + self.aliasPath = aliasPath + determineSecured(tld) + determineDriver() + } + + public func determineSecured(_ tld: String) { + secured = Shell.fileExists("~/.config/valet/Certificates/\(self.name!).\(tld).key") + } + + public func determineDriver() { + let driver = Shell.pipe("cd \(absolutePath!) && valet which", requiresPath: true) + if driver.contains("This site is served by") { + self.driver = driver + // TODO: Use a regular expression to retrieve the driver instead? + .replacingOccurrences(of: "This site is served by [", with: "") + .replacingOccurrences(of: "ValetDriver].\n", with: "") + } else { + self.driver = nil + } + } + } + + struct Configuration: Decodable { + /// Top level domain suffix. Usually "test" but can be set to something else. + /// - Important: Does not include the actual dot. ("test", not ".test"!) + let tld: String + + /// The paths that need to be checked. + let paths: [String] + + /// The loopback address. + let loopback: String + + /// The default site that is served if the domain is not found. Optional. + let defaultSite: String? + + private enum CodingKeys: String, CodingKey { + case tld, paths, loopback, defaultSite = "default" + } + } + +} diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index e73f86b..0a6936c 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -55,9 +55,28 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { updatePhpVersionInStatusBar() + print("Determining broken PHP-FPM...") + // Attempt to find out if PHP-FPM is broken let installation = App.phpInstall! installation.notifyAboutBrokenPhpFpm() + print("Detecting applications...") + // Attempt to load list of applications + App.shared.detectedApplications = Application.detectPresetApplications() + let appNames = App.shared.detectedApplications.map { app in + return app.name + } + print("Detected applications: \(appNames)") + + // Load the global hotkey + App.shared.loadGlobalHotkey() + + // Attempt to find out more info about Valet + print("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version)") + Valet.shared.validateVersion() + Valet.shared.startPreloadingSites() + print("PHP Monitor is ready to serve!") + // Schedule a request to fetch the PHP version every 60 seconds DispatchQueue.main.async { [self] in App.shared.timer = Timer.scheduledTimer( @@ -107,6 +126,14 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { menu.addPhpActionMenuItems() menu.addItem(NSMenuItem.separator()) + // Add Valet interactions + menu.addValetMenuItems() + menu.addItem(NSMenuItem.separator()) + + // Add services + menu.addServicesMenuItems() + menu.addItem(NSMenuItem.separator()) + // Add information about services & actions menu.addPhpConfigurationMenuItems() menu.addItem(NSMenuItem.separator()) @@ -131,7 +158,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { */ func setStatusBarImage(version: String) { setStatusBar( - image: MenuBarImageGenerator.textToImage(text: version) + image: MenuBarImageGenerator.textToImageWithIcon(text: version) ) } @@ -349,12 +376,24 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { } } - // Switch the PHP version - Actions.switchToPhpVersion( - version: sender.version, - availableVersions: App.shared.availablePhpVersions, - completed: completion - ) + /* DISABLED UNTIL VALET SWITCHING IS OK (see #34) + if Preferences.preferences[.useInternalSwitcher] as! Bool == false { + // 1. Default switcher using Valet + // Will cause less issues, but is slower + Actions.switchToPhpVersionUsingValet( + version: sender.version, + availableVersions: App.shared.availablePhpVersions, + completed: completion + ) + } else { */ + // 2. Custom switcher (internal) + // Will cause more issues with Homebrew and is faster + Actions.switchToPhpVersion( + version: sender.version, + availableVersions: App.shared.availablePhpVersions, + completed: completion + ) + /* } */ } } @@ -367,6 +406,10 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { PrefsVC.show() } + @objc func openSiteList() { + SiteListVC.show() + } + @objc func terminateApp() { NSApplication.shared.terminate(nil) } diff --git a/phpmon/Domain/Menu/StatusMenu.swift b/phpmon/Domain/Menu/StatusMenu.swift index f76fd25..5f4662c 100644 --- a/phpmon/Domain/Menu/StatusMenu.swift +++ b/phpmon/Domain/Menu/StatusMenu.swift @@ -36,35 +36,9 @@ class StatusMenu : NSMenu { self.addSwitchToPhpMenuItems() self.addItem(NSMenuItem.separator()) - self.addServicesMenuItems() } - private func addSwitchToPhpMenuItems() { - var shortcutKey = 1 - for index in (0.. 0 { - self.extensions.append(contentsOf: extensions) + let exts = PhpExtension.load(from: URL(fileURLWithPath: iniFilePath)) + if exts.count > 0 { + extensions.append(contentsOf: exts) } } } @@ -100,8 +101,10 @@ class ActivePhpInstallation { * 10000: an integer = amount of bytes * 1K, 1M, 1G = shorthand for kilobytes, megabytes and gigabytes - If none of these notations are used, the _fallback_ value is used. We'll show an emoji to indicate something has gone wrong here. - To clarify, B gets appended to valid values. As a result, "5M" (valid) becomes "5MB", and "5MB" (invalid) becomes ⚠️. + If none of these notations are used, the _fallback_ value is used. + We'll show an emoji to indicate something has gone wrong here. + To clarify, B gets appended to valid values. + As a result, "5M" (valid) becomes "5MB", and "5MB" (invalid) becomes ⚠️. - Parameter key: The key of the `ini` value that needs to be retrieved. For example, you can use `memory_limit`. */ @@ -158,14 +161,24 @@ class ActivePhpInstallation { } // MARK: - Structs - + + /** + Struct containing information about the version number of the current PHP installation. + Also includes information about whether the install is considered "broken" or not. + If an error was found in the terminal output, `error` is set to `true` and the installation + can be considered broken. (The app will display this as well.) + */ struct Version { var short = "???" var long = "???" var error = false } - struct Configuration { + /** + Struct containing information about the limits of the current PHP installation. + Includes: memory limit, max upload size and max post size. + */ + struct Limits { var memory_limit = "???" var upload_max_filesize = "???" var post_max_size = "???" diff --git a/phpmon/Domain/PHP/PhpInstallation.swift b/phpmon/Domain/PHP/PhpInstallation.swift index 7c69403..02577e2 100644 --- a/phpmon/Domain/PHP/PhpInstallation.swift +++ b/phpmon/Domain/PHP/PhpInstallation.swift @@ -1,5 +1,5 @@ // -// BrewPhpInstallation.swift +// PhpInstallation.swift // PHP Monitor // // Created by Nico Verbruggen on 28/11/2021. @@ -11,8 +11,11 @@ import Foundation class PhpInstallation { var longVersion: String - var homebrewInfo: HomebrewPackage? + /** + In order to determine details about a PHP installation, we’ll simply run `php-config --version` + in the relevant directory. + */ init(_ version: String) { let phpConfigExecutablePath = "\(Paths.optPath)/php@\(version)/bin/php-config" self.longVersion = version @@ -22,19 +25,6 @@ class PhpInstallation { arguments: ["--version"] ) } - - let info = Shell.pipe("\(Paths.brew) info php@\(version) --json") - - do { - let data = try JSONDecoder().decode( - [HomebrewPackage].self, - from: info.data(using: .utf8)! - ) - self.homebrewInfo = data.first! - } catch { - print("There was an issue parsing Homebrew info for PHP \(version)") - self.homebrewInfo = nil - } } } diff --git a/phpmon/Domain/Preferences/Preferences.swift b/phpmon/Domain/Preferences/Preferences.swift index 72b94d8..4cb9efc 100644 --- a/phpmon/Domain/Preferences/Preferences.swift +++ b/phpmon/Domain/Preferences/Preferences.swift @@ -13,6 +13,7 @@ enum PreferenceName: String { case shouldDisplayDynamicIcon = "use_dynamic_icon" case fullPhpVersionDynamicIcon = "full_php_in_menu_bar" case autoServiceRestartAfterExtensionToggle = "auto_restart_after_extension_toggle" + case useInternalSwitcher = "use_phpmon_switcher" case globalHotkey = "global_hotkey" } @@ -26,7 +27,7 @@ class Preferences { public init() { Preferences.handleFirstTimeLaunch() - self.cachedPreferences = Self.cache() + cachedPreferences = Self.cache() } // MARK: - First Time Run @@ -45,7 +46,8 @@ class Preferences { UserDefaults.standard.register(defaults: [ PreferenceName.shouldDisplayDynamicIcon.rawValue: true, PreferenceName.fullPhpVersionDynamicIcon.rawValue: false, - PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true + PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true, + PreferenceName.useInternalSwitcher.rawValue: false ]) if UserDefaults.standard.bool(forKey: PreferenceName.wasLaunchedBefore.rawValue) { @@ -70,6 +72,7 @@ class Preferences { .shouldDisplayDynamicIcon: UserDefaults.standard.bool(forKey: PreferenceName.shouldDisplayDynamicIcon.rawValue) as Any, .fullPhpVersionDynamicIcon: UserDefaults.standard.bool(forKey: PreferenceName.fullPhpVersionDynamicIcon.rawValue) as Any, .autoServiceRestartAfterExtensionToggle: UserDefaults.standard.bool(forKey: PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue) as Any, + .useInternalSwitcher: UserDefaults.standard.bool(forKey: PreferenceName.useInternalSwitcher.rawValue) as Any, // Part 2: Always Strings .globalHotkey: UserDefaults.standard.string(forKey: PreferenceName.globalHotkey.rawValue) as Any, diff --git a/phpmon/Domain/Preferences/PrefsVC.swift b/phpmon/Domain/Preferences/PrefsVC.swift index da11b8a..ee3208d 100644 --- a/phpmon/Domain/Preferences/PrefsVC.swift +++ b/phpmon/Domain/Preferences/PrefsVC.swift @@ -12,215 +12,94 @@ import Carbon class PrefsVC: NSViewController { - // Labels on the left - @IBOutlet weak var leftLabelDynamicIcon: NSTextField! - @IBOutlet weak var leftLabelServices: NSTextField! - @IBOutlet weak var leftLabelGlobalShortcut: NSTextField! + // MARK: - Window Identifier - // Dynamic icon - @IBOutlet weak var buttonDynamicIcon: NSButton! - @IBOutlet weak var labelDynamicIcon: NSTextField! - - // Full PHP version - @IBOutlet weak var buttonDisplayFullPhpVersion: NSButton! - @IBOutlet weak var labelDisplayFullPhpVersion: NSTextField! - - // Auto-restart services - @IBOutlet weak var buttonAutoRestartServices: NSButton! - @IBOutlet weak var labelAutoRestartServices: NSTextField! - - // Shortcut - @IBOutlet weak var buttonSetShortcut: NSButton! - @IBOutlet weak var buttonClearShortcut: NSButton! - @IBOutlet weak var labelShortcut: NSTextField! - - // Close button (bottom right) - @IBOutlet weak var buttonClose: NSButton! + @IBOutlet weak var stackView: NSStackView! // MARK: - Display + public static func create(delegate: NSWindowDelegate?) { + let storyboard = NSStoryboard(name: "Main" , bundle : nil) + + let windowController = storyboard.instantiateController( + withIdentifier: "preferencesWindow" + ) as! PrefsWC + + windowController.window!.title = "prefs.title".localized + windowController.window!.subtitle = "prefs.subtitle".localized + windowController.window!.delegate = delegate + windowController.window!.styleMask = [.titled, .closable, .miniaturizable] + windowController.window!.delegate = windowController + windowController.positionWindowInTopLeftCorner() + + App.shared.preferencesWindowController = windowController + } + public static func show(delegate: NSWindowDelegate? = nil) { - if (App.shared.windowController == nil) { - let vc = NSStoryboard(name: "Main", bundle: nil) - .instantiateController(withIdentifier: "preferences") as! PrefsVC - let window = NSWindow(contentViewController: vc) - - window.title = "prefs.title".localized - window.delegate = delegate - window.styleMask = [.titled, .closable] - - App.shared.windowController = PrefsWC(window: window) + if (App.shared.preferencesWindowController == nil) { + Self.create(delegate: delegate) } - App.shared.windowController!.showWindow(self) + App.shared.preferencesWindowController!.showWindow(self) NSApp.activate(ignoringOtherApps: true) } // MARK: - Lifecycle - override func viewWillAppear() { - loadLocalization() - loadDynamicIconFromPreferences() - loadFullPhpVersionFromPreferences() - loadGlobalKeybindFromPreferences() + override func viewDidLoad() { + [ + CheckboxPreferenceView.make( + sectionText: "prefs.dynamic_icon".localized, + descriptionText: "prefs.dynamic_icon_desc".localized, + checkboxText: "prefs.dynamic_icon_title".localized, + preference: .shouldDisplayDynamicIcon, + action: { + MainMenu.shared.refreshIcon() + } + ), + CheckboxPreferenceView.make( + sectionText: "", + descriptionText: "prefs.display_full_php_version_desc".localized, + checkboxText: "prefs.display_full_php_version".localized, + preference: .fullPhpVersionDynamicIcon, + action: { + MainMenu.shared.refreshIcon() + MainMenu.shared.update() + } + ), + CheckboxPreferenceView.make( + sectionText: "prefs.services".localized, + descriptionText: "prefs.auto_restart_services_desc".localized, + checkboxText: "prefs.auto_restart_services_title".localized, + preference: .autoServiceRestartAfterExtensionToggle, + action: {} + ), + /* DISABLED UNTIL VALET SWITCHING IS OK (see #34) + CheckboxPreferenceView.make( + sectionText: "", + descriptionText: "prefs.use_internal_switcher_desc".localized, + checkboxText: "prefs.use_internal_switcher".localized, + preference: .useInternalSwitcher, + action: {} + ), */ + HotkeyPreferenceView.make( + sectionText: "prefs.global_shortcut".localized, + descriptionText: "prefs.shortcut_desc".localized, + self + ) + ].forEach({ self.stackView.addArrangedSubview($0) }) } + // MARK: - Listening for hotkey dleegate + + var listeningForHotkeyView: HotkeyPreferenceView? = nil + override func viewWillDisappear() { - if self.listeningForGlobalHotkey { - listeningForGlobalHotkey = false + if listeningForHotkeyView !== nil { + listeningForHotkeyView = nil } } - - private func loadLocalization() { - // Dynamic icon - leftLabelDynamicIcon.stringValue = "prefs.dynamic_icon".localized - labelDynamicIcon.stringValue = "prefs.dynamic_icon_desc".localized - buttonDynamicIcon.title = "prefs.dynamic_icon_title".localized - - // Full PHP version - buttonDisplayFullPhpVersion.title = "prefs.display_full_php_version".localized - labelDisplayFullPhpVersion.stringValue = "prefs.display_full_php_version_desc".localized - - // Services - leftLabelServices.stringValue = "prefs.services".localized - buttonAutoRestartServices.title = "prefs.auto_restart_services_title".localized - labelAutoRestartServices.stringValue = "prefs_auto_restart_services_desc".localized - - // Global Shortcut - leftLabelGlobalShortcut.stringValue = "prefs.global_shortcut".localized - labelShortcut.stringValue = "prefs.shortcut_desc".localized - buttonSetShortcut.title = "prefs.shortcut_set".localized - buttonClearShortcut.title = "prefs.shortcut_clear".localized - - // Close button - buttonClose.title = "prefs.close".localized - } - - // MARK: - Loading Preferences - - func loadDynamicIconFromPreferences() { - let shouldDisplay = Preferences.preferences[.shouldDisplayDynamicIcon] as! Bool == true - self.buttonDynamicIcon.state = shouldDisplay ? .on : .off - } - - func loadFullPhpVersionFromPreferences() { - let shouldDisplay = Preferences.preferences[.fullPhpVersionDynamicIcon] as! Bool == true - self.buttonDisplayFullPhpVersion.state = shouldDisplay ? .on : .off - } - - func loadAutoRestartServicesFromPreferences() { - let shouldDisplay = Preferences.preferences[.autoServiceRestartAfterExtensionToggle] as! Bool == true - self.buttonAutoRestartServices.state = shouldDisplay ? .on : .off - } - - // MARK: - Actions - - @IBAction func toggledDynamicIcon(_ sender: Any) { - Preferences.update(.shouldDisplayDynamicIcon, value: buttonDynamicIcon.state == .on) - MainMenu.shared.refreshIcon() - } - - @IBAction func toggledFullPhpVersion(_ sender: Any) { - Preferences.update(.fullPhpVersionDynamicIcon, value: buttonDisplayFullPhpVersion.state == .on) - MainMenu.shared.refreshIcon() - MainMenu.shared.update() - } - - @IBAction func toggledAutoRestartServices(_ sender: Any) { - Preferences.update(.autoServiceRestartAfterExtensionToggle, value: buttonAutoRestartServices.state == .on) - } - - // MARK: - Shortcut Preference - // Adapted from: https://dev.to/mitchartemis/creating-a-global-configurable-shortcut-for-macos-apps-in-swift-25e9 - - var listeningForGlobalHotkey = false { - didSet { - if listeningForGlobalHotkey { - DispatchQueue.main.async { [weak self] in - self?.buttonSetShortcut.highlight(true) - self?.buttonSetShortcut.title = "prefs.shortcut_listening".localized - } - } else { - DispatchQueue.main.async { [weak self] in - self?.buttonSetShortcut.highlight(false) - self?.loadGlobalKeybindFromPreferences() - } - } - } - } - - func loadGlobalKeybindFromPreferences() { - let globalKeybind = GlobalKeybindPreference.fromJson(Preferences.preferences[.globalHotkey] as! String?) - - if (globalKeybind != nil) { - updateKeybindButton(globalKeybind!) - } else { - buttonSetShortcut.title = "prefs.shortcut_set".localized - } - - buttonClearShortcut.isEnabled = globalKeybind != nil - } - - func updateGlobalShortcut(_ event : NSEvent) { - self.listeningForGlobalHotkey = false - - if let characters = event.charactersIgnoringModifiers { - let newGlobalKeybind = GlobalKeybindPreference.init( - function: event.modifierFlags.contains(.function), - control: event.modifierFlags.contains(.control), - command: event.modifierFlags.contains(.command), - shift: event.modifierFlags.contains(.shift), - option: event.modifierFlags.contains(.option), - capsLock: event.modifierFlags.contains(.capsLock), - carbonFlags: event.modifierFlags.carbonFlags, - characters: characters, - keyCode: UInt32(event.keyCode) - ) - - Preferences.update(.globalHotkey, value: newGlobalKeybind.toJson()) - - updateKeybindButton(newGlobalKeybind) - buttonClearShortcut.isEnabled = true - - App.shared.shortcutHotkey = HotKey( - keyCombo: KeyCombo( - carbonKeyCode: UInt32(event.keyCode), - carbonModifiers: event.modifierFlags.carbonFlags - ) - ) - } - } - - @IBAction func register(_ sender: Any) { - unregister(nil) - listeningForGlobalHotkey = true - view.window?.makeFirstResponder(nil) - } - - @IBAction func unregister(_ sender: Any?) { - listeningForGlobalHotkey = false - App.shared.shortcutHotkey = nil - buttonSetShortcut.title = "" - - Preferences.update(.globalHotkey, value: nil) - } - - func updateClearButton(_ globalKeybindPreference: GlobalKeybindPreference?) { - if globalKeybindPreference != nil { - buttonClearShortcut.isEnabled = true - } else { - buttonClearShortcut.isEnabled = false - } - } - - func updateKeybindButton(_ globalKeybindPreference: GlobalKeybindPreference) { - buttonSetShortcut.title = globalKeybindPreference.description - } - - @IBAction func pressed(_ sender: Any) { - self.view.window?.windowController?.close() - } - + // MARK: - Deinitialization deinit { diff --git a/phpmon/Domain/Preferences/PrefsWC.swift b/phpmon/Domain/Preferences/PrefsWC.swift index 3d2dd55..a2c69c3 100644 --- a/phpmon/Domain/Preferences/PrefsWC.swift +++ b/phpmon/Domain/Preferences/PrefsWC.swift @@ -13,22 +13,32 @@ struct Keys { static let Space = 49 } -class PrefsWC: NSWindowController { +class PrefsWC: PMWindowController { + + // MARK: - Window Identifier + + override var windowName: String { + return "Preferences" + } + + // MARK: - Window Lifecycle override func windowDidLoad() { super.windowDidLoad() } + // MARK: - Key Interaction + override func keyDown(with event: NSEvent) { super.keyDown(with: event) - if let vc = self.contentViewController as? PrefsVC { - if vc.listeningForGlobalHotkey { + if let vc = contentViewController as? PrefsVC { + if vc.listeningForHotkeyView != nil { if event.keyCode == Keys.Escape || event.keyCode == Keys.Space { print("A blacklisted key was pressed, canceling listen") - vc.listeningForGlobalHotkey = false + vc.listeningForHotkeyView = nil } else { - vc.updateGlobalShortcut(event) + vc.listeningForHotkeyView!.updateShortcut(event) } } } diff --git a/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.swift b/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.swift new file mode 100644 index 0000000..2736e08 --- /dev/null +++ b/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.swift @@ -0,0 +1,44 @@ +// +// CheckboxPreferenceView.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 17/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation + +import Foundation +import Cocoa + +class CheckboxPreferenceView: NSView, XibLoadable { + + @IBOutlet weak var labelSection: NSTextField! + @IBOutlet weak var labelDescription: NSTextField! + @IBOutlet weak var buttonCheckbox: NSButton! + + var action: (() -> Void)! + + var preference: PreferenceName! { + didSet { + let shouldDisplay = Preferences.preferences[self.preference] as! Bool == true + self.buttonCheckbox.state = shouldDisplay ? .on : .off + } + } + + static func make(sectionText: String, descriptionText: String, checkboxText: String, preference: PreferenceName, action: @escaping () -> Void) -> NSView { + let view = Self.createFromXib()! + view.labelSection.stringValue = sectionText + view.labelDescription.stringValue = descriptionText + view.buttonCheckbox.title = checkboxText + view.preference = preference + view.action = action + return view + } + + @IBAction func toggled(_ sender: Any) { + Preferences.update(self.preference, value: buttonCheckbox.state == .on) + self.action() + } + +} diff --git a/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.xib b/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.xib new file mode 100644 index 0000000..02aa72b --- /dev/null +++ b/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.xib @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpmon/Domain/Preferences/Views/HotkeyPreferenceView.swift b/phpmon/Domain/Preferences/Views/HotkeyPreferenceView.swift new file mode 100644 index 0000000..717be58 --- /dev/null +++ b/phpmon/Domain/Preferences/Views/HotkeyPreferenceView.swift @@ -0,0 +1,97 @@ +// +// HotkeyPreferenceView.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 17/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation + +import Foundation +import HotKey +import Cocoa + +class HotkeyPreferenceView: NSView, XibLoadable { + + weak var delegate: PrefsVC? + + @IBOutlet weak var labelSection: NSTextField! + @IBOutlet weak var labelDescription: NSTextField! + + @IBOutlet weak var buttonSetShortcut: NSButton! + @IBOutlet weak var buttonClearShortcut: NSButton! + + static func make(sectionText: String, descriptionText: String, _ prefsVC: PrefsVC) -> NSView { + let view = Self.createFromXib()! + view.labelSection.stringValue = sectionText + view.labelDescription.stringValue = descriptionText + view.buttonClearShortcut.title = "prefs.shortcut_clear".localized + view.delegate = prefsVC + view.loadGlobalKeybindFromPreferences() + return view + } + + // MARK: - Shortcut Functionality + + // Adapted from: https://dev.to/mitchartemis/creating-a-global-configurable-shortcut-for-macos-apps-in-swift-25e9 + + func updateShortcut(_ event: NSEvent) { + guard let characters = event.charactersIgnoringModifiers else { return } + + let newGlobalKeybind = GlobalKeybindPreference.init( + function: event.modifierFlags.contains(.function), + control: event.modifierFlags.contains(.control), + command: event.modifierFlags.contains(.command), + shift: event.modifierFlags.contains(.shift), + option: event.modifierFlags.contains(.option), + capsLock: event.modifierFlags.contains(.capsLock), + carbonFlags: event.modifierFlags.carbonFlags, + characters: characters, + keyCode: UInt32(event.keyCode) + ) + + Preferences.update(.globalHotkey, value: newGlobalKeybind.toJson()) + + updateKeybindButton(newGlobalKeybind) + buttonClearShortcut.isEnabled = true + + App.shared.shortcutHotkey = HotKey( + keyCombo: KeyCombo( + carbonKeyCode: UInt32(event.keyCode), + carbonModifiers: event.modifierFlags.carbonFlags + ) + ) + } + + func loadGlobalKeybindFromPreferences() { + let globalKeybind = GlobalKeybindPreference.fromJson(Preferences.preferences[.globalHotkey] as! String?) + + if (globalKeybind != nil) { + updateKeybindButton(globalKeybind!) + } else { + buttonSetShortcut.title = "prefs.shortcut_set".localized + } + + buttonClearShortcut.isEnabled = globalKeybind != nil + } + + func updateKeybindButton(_ globalKeybindPreference: GlobalKeybindPreference) { + buttonSetShortcut.title = globalKeybindPreference.description + } + + @IBAction func register(_ sender: Any) { + unregister(nil) + delegate?.listeningForHotkeyView = self + delegate?.view.window?.makeFirstResponder(nil) + buttonSetShortcut.title = "prefs.shortcut_listening".localized + } + + @IBAction func unregister(_ sender: Any?) { + delegate?.listeningForHotkeyView = nil + App.shared.shortcutHotkey = nil + buttonSetShortcut.title = "prefs.shortcut_set".localized + Preferences.update(.globalHotkey, value: nil) + } + +} diff --git a/phpmon/Domain/Preferences/Views/HotkeyPreferenceView.xib b/phpmon/Domain/Preferences/Views/HotkeyPreferenceView.xib new file mode 100644 index 0000000..08ea47d --- /dev/null +++ b/phpmon/Domain/Preferences/Views/HotkeyPreferenceView.xib @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpmon/Domain/SiteList/SiteListCell.swift b/phpmon/Domain/SiteList/SiteListCell.swift new file mode 100644 index 0000000..1bcf0f3 --- /dev/null +++ b/phpmon/Domain/SiteList/SiteListCell.swift @@ -0,0 +1,51 @@ +// +// SiteListCell.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 03/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Cocoa +import AppKit + +class SiteListCell: NSTableCellView +{ + @IBOutlet weak var labelSiteName: NSTextField! + @IBOutlet weak var labelPathName: NSTextField! + + @IBOutlet weak var imageViewLock: NSImageView! + @IBOutlet weak var imageViewType: NSImageView! + + @IBOutlet weak var labelDriver: NSTextField! + + override func draw(_ dirtyRect: NSRect) { + super.draw(dirtyRect) + } + + func populateCell(with site: Valet.Site) { + // Make sure to show the TLD + labelSiteName.stringValue = "\(site.name!).\(Valet.shared.config.tld)" + + // Show the absolute path, except make sure to replace the /Users/username segment with ~ for readability + labelPathName.stringValue = site.absolutePath + .replacingOccurrences(of: "/Users/\(Paths.whoami)", with: "~") + + // If the `aliasPath` is nil, we're dealing with a parked site (otherwise: linked). + imageViewType.image = NSImage( + named: site.aliasPath == nil + ? "IconParked" + : "IconLinked" + ) + imageViewType.contentTintColor = NSColor.tertiaryLabelColor + + // 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.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 ?? "???" + } +} diff --git a/phpmon/Domain/SiteList/SiteListVC+ContextMenu.swift b/phpmon/Domain/SiteList/SiteListVC+ContextMenu.swift new file mode 100644 index 0000000..b1e246b --- /dev/null +++ b/phpmon/Domain/SiteList/SiteListVC+ContextMenu.swift @@ -0,0 +1,93 @@ +// +// SiteListVC+ContextMenu.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 10/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +extension SiteListVC { + + internal func reloadContextMenu() { + guard let site = selectedSite else { + tableView.menu = nil + return + } + + let menu = NSMenu() + + addSystemApps(to: menu) + addSeparator(to: menu) + addDetectedApps(to: menu) + addSeparator(to: menu) + + addUnlink(to: menu, with: site) + addToggleSecure(to: menu, with: site) + + tableView.menu = menu + } + + private func addSystemApps(to menu: NSMenu) { + menu.addItem(withTitle: "site_list.system_apps".localized, action: nil, keyEquivalent: "") + menu.addItem( + withTitle: "site_list.open_in_finder".localized, + action: #selector(self.openInFinder), + keyEquivalent: "F" + ) + menu.addItem( + withTitle: "site_list.open_in_terminal".localized, + action: #selector(self.openInTerminal), + keyEquivalent: "T" + ) + menu.addItem( + withTitle: "site_list.open_in_browser".localized, + action: #selector(self.openInBrowser), + keyEquivalent: "B" + ) + } + + private func addDetectedApps(to menu: NSMenu) { + if (applications.count > 0) { + menu.addItem(NSMenuItem.separator()) + menu.addItem(withTitle: "site_list.detected_apps".localized, action: nil, keyEquivalent: "") + + for (_, editor) in applications.enumerated() { + let editorMenuItem = EditorMenuItem( + title: "Open with \(editor.name)", + action: #selector(self.openWithEditor(sender:)), + keyEquivalent: "" + ) + editorMenuItem.editor = editor + menu.addItem(editorMenuItem) + } + } + } + + private func addUnlink(to menu: NSMenu, with site: Valet.Site) { + if (site.aliasPath != nil) { + menu.addItem( + withTitle: "site_list.unlink".localized, + action: #selector(self.unlinkSite), + keyEquivalent: "" + ) + menu.addItem(NSMenuItem.separator()) + } + } + + private func addToggleSecure(to menu: NSMenu, with site: Valet.Site) { + menu.addItem( + withTitle: site.secured + ? "site_list.unsecure".localized + : "site_list.secure".localized, + action: #selector(toggleSecure), + keyEquivalent: "" + ) + } + + private func addSeparator(to menu: NSMenu) { + menu.addItem(NSMenuItem.separator()) + } + +} diff --git a/phpmon/Domain/SiteList/SiteListVC.swift b/phpmon/Domain/SiteList/SiteListVC.swift new file mode 100644 index 0000000..b03fad1 --- /dev/null +++ b/phpmon/Domain/SiteList/SiteListVC.swift @@ -0,0 +1,273 @@ +// +// SiteListVC.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 30/03/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Cocoa +import HotKey +import Carbon + +class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource { + + // MARK: - Outlets + + @IBOutlet weak var tableView: NSTableView! + @IBOutlet weak var progressIndicator: NSProgressIndicator! + + // MARK: - Variables + + /// List of sites that will be displayed in this view. Originates from the `Valet` object. + var sites: [Valet.Site] = [] + + /// Array that contains various apps that might open a particular site directory. + var applications: [Application] { + return App.shared.detectedApplications + } + + /// String that was last searched for. Empty by default. + var lastSearchedFor = "" + + // MARK: - Helper Variables + + var selectedSite: Valet.Site? { + if tableView.selectedRow == -1 { + return nil + } + return sites[tableView.selectedRow] + } + + // MARK: - Display + + public static func create(delegate: NSWindowDelegate?) { + let storyboard = NSStoryboard(name: "Main" , bundle : nil) + + let windowController = storyboard.instantiateController( + withIdentifier: "siteListWindow" + ) as! SiteListWC + + windowController.window!.title = "site_list.title".localized + windowController.window!.subtitle = "site_list.subtitle".localized + windowController.window!.delegate = delegate + windowController.window!.styleMask = [ + .titled, .closable, .resizable, .miniaturizable + ] + windowController.window!.minSize = NSSize(width: 550, height: 200) + windowController.window!.delegate = windowController + windowController.positionWindowInTopLeftCorner() + + App.shared.siteListWindowController = windowController + } + + public static func show(delegate: NSWindowDelegate? = nil) { + if (App.shared.siteListWindowController == nil) { + Self.create(delegate: delegate) + } + + App.shared.siteListWindowController!.showWindow(self) + NSApp.activate(ignoringOtherApps: true) + } + + // MARK: - Lifecycle + + override func viewDidLoad() { + tableView.doubleAction = #selector(self.doubleClicked(sender:)) + if !Valet.shared.sites.isEmpty { + // Preloaded list + sites = Valet.shared.sites + searchedFor(text: lastSearchedFor) + } else { + reloadSites() + } + } + + // MARK: - Async Operations + + /** + Disables the UI so the user cannot interact with it. + Also shows a spinner to indicate that we're busy. + */ + private func setUIBusy() { + progressIndicator.startAnimation(nil) + tableView.alphaValue = 0.3 + tableView.isEnabled = false + } + + /** + Re-enables the UI so the user can interact with it. + */ + private func setUINotBusy() { + progressIndicator.stopAnimation(nil) + tableView.alphaValue = 1.0 + tableView.isEnabled = true + } + + /** + Executes a specific callback and fires the completion callback, + while updating the UI as required. As long as the completion callback + does not fire, the app is presumed to be busy and the UI reflects this. + + - Parameter execute: Callback of the work that needs to happen. + - Parameter completion: Callback that is fired when the work is done. + */ + private func waitAndExecute(_ execute: @escaping () -> Void, completion: @escaping () -> Void = {}) + { + setUIBusy() + DispatchQueue.global(qos: .userInitiated).async { [unowned self] in + execute() + + DispatchQueue.main.async { [self] in + completion() + setUINotBusy() + } + } + } + + // MARK: - Site Data Loading + + func reloadSites() { + waitAndExecute { + Valet.shared.reloadSites() + } completion: { [self] in + sites = Valet.shared.sites + searchedFor(text: lastSearchedFor) + } + } + + // MARK: - Table View Delegate + + func numberOfRows(in tableView: NSTableView) -> Int { + return sites.count + } + + func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { + guard let userCell = tableView.makeView( + withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "siteItem"), owner: self + ) as? SiteListCell else { return nil } + + userCell.populateCell(with: sites[row]) + + return userCell + } + + func tableViewSelectionDidChange(_ notification: Notification) { + reloadContextMenu() + } + + @objc func doubleClicked(sender: Any) { + guard self.selectedSite != nil else { + return + } + + self.openInBrowser() + } + + // MARK: Secure & Unsecure + + @objc public func toggleSecure() { + let rowToReload = tableView.selectedRow + let originalSecureStatus = selectedSite!.secured + let action = selectedSite!.secured ? "unsecure" : "secure" + let selectedSite = selectedSite! + let command = "cd \(selectedSite.absolutePath!) && sudo \(Paths.valet) \(action) && exit;" + + waitAndExecute { + Shell.run(command, requiresPath: true) + } completion: { [self] in + selectedSite.determineSecured(Valet.shared.config.tld) + if selectedSite.secured == originalSecureStatus { + Alert.notify( + message: "site_list.alerts_status_not_changed.title".localized, + info: "site_list.alerts_status_not_changed.desc".localized(command) + ) + } else { + let newState = selectedSite.secured ? "secured" : "unsecured" + LocalNotification.send( + title: "site_list.alerts_status_changed.title".localized, + subtitle: "site_list.alerts_status_changed.desc" + .localized( + "\(selectedSite.name!).\(Valet.shared.config.tld)", + newState + ) + ) + } + + tableView.reloadData(forRowIndexes: [rowToReload], columnIndexes: [0]) + tableView.deselectRow(rowToReload) + tableView.selectRowIndexes([rowToReload], byExtendingSelection: true) + } + } + + // MARK: Open in Browser & Finder + + @objc public func openInBrowser() { + let prefix = selectedSite!.secured ? "https://" : "http://" + let url = "\(prefix)\(selectedSite!.name!).\(Valet.shared.config.tld)" + NSWorkspace.shared.open(URL(string: url)!) + } + + @objc public func openInFinder() { + Shell.run("open \(selectedSite!.absolutePath!)") + } + + @objc public func openInTerminal() { + Shell.run("open -b com.apple.terminal \(selectedSite!.absolutePath!)") + } + + @objc public func unlinkSite() { + guard let site = selectedSite else { + return + } + + if site.aliasPath == nil { + return + } + + Alert.confirm( + onWindow: view.window!, + messageText: "site_list.confirm_unlink".localized(site.name), + informativeText: "site_link.confirm_link".localized, + buttonTitle: "site_list.unlink".localized, + secondButtonTitle: "Cancel", + style: .critical, + onFirstButtonPressed: { + Shell.run("valet unlink \(site.name!)", requiresPath: true) + self.reloadSites() + } + ) + } + + // MARK: - (Search) Text Field Delegate + + func searchedFor(text: String) { + lastSearchedFor = text + + let searchString = text.lowercased() + + if searchString.isEmpty { + sites = Valet.shared.sites + tableView.reloadData() + return + } + + sites = Valet.shared.sites.filter({ site in + return site.name.lowercased().contains(searchString) + }) + + tableView.reloadData() + } + + // MARK: - Context Menu + + @objc func openWithEditor(sender: EditorMenuItem) { + guard let editor = sender.editor else { return } + editor.openDirectory(file: selectedSite!.absolutePath!) + } + // MARK: - Deinitialization + + deinit { + print("VC deallocated") + } +} diff --git a/phpmon/Domain/SiteList/SiteListWC.swift b/phpmon/Domain/SiteList/SiteListWC.swift new file mode 100644 index 0000000..d652dad --- /dev/null +++ b/phpmon/Domain/SiteList/SiteListWC.swift @@ -0,0 +1,50 @@ +// +// SiteListWC.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 03/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +class SiteListWC: PMWindowController, NSSearchFieldDelegate, NSToolbarDelegate { + + // MARK: - Window Identifier + + override var windowName: String { + return "SiteList" + } + + // MARK: - Outlets + + @IBOutlet weak var searchToolbarItem: NSSearchToolbarItem! + + // MARK: - Window Lifecycle + + override func windowDidLoad() { + super.windowDidLoad() + self.searchToolbarItem.searchField.delegate = self + self.searchToolbarItem.searchField.becomeFirstResponder() + } + + // MARK: - Search functionality + + var contentVC: SiteListVC { + return self.contentViewController as! SiteListVC + } + + func controlTextDidChange(_ notification: Notification) { + guard let searchField = notification.object as? NSSearchField else { + return + } + + contentVC.searchedFor(text: searchField.stringValue) + } + + // MARK: - Reload functionality + + @IBAction func pressedReload(_ sender: Any) { + contentVC.reloadSites() + } +} diff --git a/phpmon/Domain/Terminal/Paths.swift b/phpmon/Domain/Terminal/Paths.swift index d25cfb4..6ffe80a 100644 --- a/phpmon/Domain/Terminal/Paths.swift +++ b/phpmon/Domain/Terminal/Paths.swift @@ -33,12 +33,14 @@ class Paths { print("This usually means we're in trouble... (no Homebrew?)") baseDir = .usr } - - print("Homebrew directory: \(baseDir)") } // - MARK: Binaries + public static var valet: String { + return "/Users/\(whoami)/.composer/vendor/bin/valet" + } + public static var brew: String { return "\(binPath)/brew" } @@ -53,6 +55,10 @@ class Paths { // - MARK: Paths + public static var whoami: String { + return String(Shell.pipe("whoami").split(separator: "\n")[0]) + } + public static var binPath: String { return "\(shared.baseDir.rawValue)/bin" } diff --git a/phpmon/Domain/Terminal/Shell.swift b/phpmon/Domain/Terminal/Shell.swift index 6cf482d..ddfeb02 100644 --- a/phpmon/Domain/Terminal/Shell.swift +++ b/phpmon/Domain/Terminal/Shell.swift @@ -11,33 +11,26 @@ class Shell { // MARK: - Invoke static functions - public static func run(_ command: String) { - Shell.user.run(command) + public static func run( + _ command: String, + requiresPath: Bool = false + ) { + Shell.user.run(command, requiresPath: requiresPath) } - public static func pipe(_ command: String) -> String { - return Shell.user.pipe(command) + public static func pipe( + _ command: String, + requiresPath: Bool = false + ) -> String { + return Shell.user.pipe(command, requiresPath: requiresPath) } // MARK: - Singleton - var shell: String - - init() { - // Determine if we're using macOS Catalina or newer (that support /bin/zsh as default shell) - let at_least_10_15 = ProcessInfo.processInfo.isOperatingSystemAtLeast( - .init(majorVersion: 10, minorVersion: 15, patchVersion: 0)) - - // If macOS Mojave is being used, we'll default to /bin/bash - shell = at_least_10_15 - ? "/bin/sh" - : "/bin/bash" - - print(at_least_10_15 - ? "Detected recent macOS (> 10.15): defaulting to /bin/sh" - : "Detected older macOS (< 10.15): defaulting to /bin/bash" - ) - } + /** + We now require macOS 11, so no need to detect which terminal to use. + */ + var shell: String = "/bin/sh" /** Singleton to access a user shell (with --login) @@ -49,37 +42,73 @@ class Shell { Uses the default shell. - Parameter command: The command to run + - Parameter requiresPath: By default, the PATH is not resolved but some binaries might require this */ - func run(_ command: String) { + func run( + _ command: String, + requiresPath: Bool = false + ) { // Equivalent of piping to /dev/null; don't do anything with the string - _ = pipe(command) + _ = Shell.pipe(command, requiresPath: requiresPath) } /** Runs a shell command and returns the output. - Parameter command: The command to run - - Parameter shell: Path to the shell to invoke + - Parameter requiresPath: By default, the PATH is not resolved but some binaries might require this */ - func pipe(_ command: String) -> String { + func pipe( + _ command: String, + requiresPath: Bool = false + ) -> String { + let shellOutput = self.execute(command, requiresPath: requiresPath) + let hasError = ( + shellOutput.standardOutput == "" + && shellOutput.errorOutput.lengthOfBytes(using: .utf8) > 0 + ) + return !hasError ? shellOutput.standardOutput : shellOutput.errorOutput + } + + /** + Runs the command and returns a `ShellOutput` object, which contains info about the process. + + - Parameter command: The command to run + - Parameter requiresPath: By default, the PATH is not resolved but some binaries might require this + - Parameter waitUntilExit: Waits for the command to complete before returning the `ShellOutput` + */ + func execute( + _ command: String, + requiresPath: Bool = false, + waitUntilExit: Bool = false + ) -> ShellOutput { let task = Process() let outputPipe = Pipe() let errorPipe = Pipe() + let tailoredCommand = requiresPath + ? "export PATH=\(Paths.binPath):$PATH && \(command)" + : command + task.launchPath = self.shell - task.arguments = ["--login", "-c", command] + task.arguments = ["--login", "-c", tailoredCommand] task.standardOutput = outputPipe task.standardError = errorPipe task.launch() - let error = String(data: errorPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! - let output = String(data: outputPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)! - - if (output == "" && error.lengthOfBytes(using: .utf8) > 0) { - return error + if waitUntilExit { + task.waitUntilExit() } - - return output + + return ShellOutput( + standardOutput: String( + data: outputPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8 + )!, + errorOutput: String( + data: errorPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8 + )!, + task: task + ) } /** @@ -89,5 +118,18 @@ class Shell { public static func fileExists(_ path: String) -> Bool { return Shell.pipe("if [ -f \(path) ]; then /bin/echo -n \"0\"; fi") == "0" } - +} + +class ShellOutput { + let standardOutput: String + let errorOutput: String + let task: Process + + init(standardOutput: String, + errorOutput: String, + task: Process) { + self.standardOutput = standardOutput + self.errorOutput = errorOutput + self.task = task + } } diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 444c25b..42050fc 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -25,7 +25,8 @@ "mi_manage_services" = "Manage services"; "mi_restart_all_services" = "Restart all services"; "mi_stop_all_services" = "Stop all services"; -"mi_force_load_latest" = "Force load latest PHP version"; +"mi_force_load_latest" = "Force load (latest) PHP %@"; +"mi_force_load_latest_unavailable" = "Force load unavailable (PHP %@ not installed)"; "mi_php_refresh" = "Refresh information"; "mi_configuration" = "Configuration"; @@ -41,13 +42,47 @@ "mi_detected_extensions" = "Detected Extensions"; "mi_no_extensions_detected" = "No additional extensions detected."; +"mi_valet" = "Laravel Valet"; +"mi_sitelist" = "View linked & parked domains..."; + "mi_preferences" = "Preferences..."; "mi_quit" = "Quit PHP Monitor"; "mi_about" = "About PHP Monitor"; +// SITE LIST + +"site_list.title" = "Domains"; +"site_list.subtitle" = "Linked & Parked"; + +"site_list.alerts_status_not_changed.title" = "SSL Status Not Changed"; +"site_list.alerts_status_not_changed.desc" = "Something went wrong. Try running the command in your terminal manually: %@"; + +"site_list.alerts_status_changed.title" = "SSL Status Changed"; +"site_list.alerts_status_changed.desc" = "The domain '%@' is now %@."; + +"site_list.confirm_unlink" = "Are you sure you want to unlink '%@'?"; +"site_link.confirm_link" = "No files will be removed. If needed, the site will need to be relinked via the command line."; + +// SITE LIST ACTIONS + +"site_list.unlink" = "Unlink Directory"; +"site_list.secure" = "Secure Domain"; +"site_list.unsecure" = "Unsecure Domain"; +"site_list.open_in_finder" = "Open in Finder"; +"site_list.open_in_browser" = "Open in Browser"; +"site_list.open_in_terminal" = "Open in Terminal"; +"site_list.detected_apps" = "Detected Applications"; +"site_list.system_apps" = "System Applications"; + +// EDITORS + +"editors.alert.try_again" = "Try Again"; +"editors.alert.cancel" = "Cancel"; + // PREFERENCES "prefs.title" = "PHP Monitor"; +"prefs.subtitle" = "Preferences"; "prefs.close" = "Close"; "prefs.global_shortcut" = "Global shortcut:"; @@ -55,13 +90,22 @@ "prefs.services" = "Services:"; "prefs.auto_restart_services_title" = "Auto-restart PHP-FPM"; -"prefs_auto_restart_services_desc" = "When checked, will automatically restart PHP-FPM when\nyou check or uncheck an extension. Slightly slower when enabled, \nbut this applies the extension change immediately for all sites \nyou're serving, no need to restart PHP-FPM manually."; +"prefs.auto_restart_services_desc" = "When checked, will automatically restart PHP-FPM when\nyou check or uncheck an extension. Slightly slower when enabled, \nbut this applies the extension change immediately for all sites \nyou're serving, no need to restart PHP-FPM manually."; "prefs.dynamic_icon_title" = "Display dynamic icon in menu bar"; "prefs.dynamic_icon_desc" = "If you uncheck this box, the truck icon will always be visible.\nIf checked, it will display the major version number of the\ncurrently linked PHP version."; "prefs.display_full_php_version" = "Display full PHP version in menu bar"; "prefs.display_full_php_version_desc" = "Display the full version instead of the major version only.\n(This may be undesirable on smaller displays,\nso this is disabled by default.)"; + +"prefs.use_internal_switcher" = "Use PHP Monitor’s own version switcher"; +"prefs.use_internal_switcher_desc" = +"By default, PHP Monitor will attempt to use Laravel Valet +in order to switch PHP versions. If you prefer a different +switcher or are having issues with `valet use php`, you may +use PHP Monitor's own switcher which is slightly faster, +but might cause issues with permissions in your Homebrew +directories, since PHP Monitor controls the services."; "prefs.shortcut_set" = "Set global shortcut"; "prefs.shortcut_listening" = ""; @@ -106,11 +150,18 @@ "alert.php_alias_conflict.title" = "Homebrew `php` formula alias conflict detected"; "alert.php_alias_conflict.info" = "PHP Monitor has detected conflicting `php` aliases in your Homebrew setup, both of which have been detected as installed.\n\nThis will likely result in failed linking when switching PHP versions, and will break PHP Monitor functionality.\n\nFor more information, please visit: https://github.com/nicoverbruggen/phpmon/issues/54"; +"alert.min_valet_version.title" = "Your version of Valet is outdated, please upgrade!"; +"alert.min_valet_version.info" = "You are currently running Valet %@. + +For optimal support of the latest versions of PHP and proper version switching, it is recommended that you update to version %@. + +You can do this by running `composer global update` in your terminal. After that, run `valet install` again. For best results, restart PHP Monitor after that."; + // STARTUP /// 1. PHP binary not found "startup.errors.php_binary.title" = "PHP is not correctly installed"; -"startup.errors.php_binary_desc" = "You must install PHP via brew. Try running `which php` in Terminal, it should return `/usr/local/bin/php` (or `/opt/homebrew/bin/php`). The app will not work correctly until you resolve this issue. (Usually `brew link php` resolves this issue.)"; +"startup.errors.php_binary.desc" = "You must install PHP via brew. Try running `which php` in Terminal, it should return `/usr/local/bin/php` (or `/opt/homebrew/bin/php`). The app will not work correctly until you resolve this issue. (Usually `brew link php` resolves this issue.)"; /// 2. PHP not found in /usr/local/opt or /opt/homebrew/opt "startup.errors.php_opt.title" = "PHP is not correctly installed";