diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 52de760..9921cae 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -15,6 +15,8 @@ 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 */; }; @@ -122,6 +124,7 @@ 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 = ""; }; @@ -321,6 +324,7 @@ children = ( C476FF9722B0DD830098105B /* Alert.swift */, 54B48B5E275F66AE006D90C5 /* Editor.swift */, + C4188988275FE8CB001EF227 /* Filesystem.swift */, C474B00524C0E98C00066A22 /* LocalNotification.swift */, C41C1B4822B00A9800E7CF16 /* MenuBarImageGenerator.swift */, C4CCBA6B275C567B008C7055 /* PMWindowController.swift */, @@ -553,6 +557,7 @@ 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 */, @@ -612,6 +617,7 @@ 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 */, 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/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/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/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index dd9f50e..ad2d4db 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -141,7 +141,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { */ func setStatusBarImage(version: String) { setStatusBar( - image: MenuBarImageGenerator.textToImage(text: version) + image: MenuBarImageGenerator.textToImageWithIcon(text: version) ) }