diff --git a/DEVS.md b/DEVELOPER.md similarity index 98% rename from DEVS.md rename to DEVELOPER.md index e97b238..f06f564 100644 --- a/DEVS.md +++ b/DEVELOPER.md @@ -1,4 +1,4 @@ -# README for interested developers +# DEVELOPER README ## 🔧 Build instructions diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index fadf9a5..1bae20a 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -242,6 +242,7 @@ C415D3DE2770F34D005EF286 /* AllowedArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AllowedArguments.swift; sourceTree = ""; }; C415D3E52770F540005EF286 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; C415D3E72770F692005EF286 /* AppDelegate+InterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+InterApp.swift"; sourceTree = ""; }; + C4168F4427ADB4A3003B6C39 /* DEVELOPER.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = DEVELOPER.md; sourceTree = ""; }; C417DC73277614690015E6EE /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.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; }; @@ -446,6 +447,7 @@ C4F8C0A522D4FA41002EFE61 /* README.md */, C4E713562570150F00007428 /* SECURITY.md */, C4F7807425D7F7E5000DBC97 /* RELEASE.md */, + C4168F4427ADB4A3003B6C39 /* DEVELOPER.md */, C4E713572570151400007428 /* docs */, C41C1B3522B0097F00E7CF16 /* phpmon */, C4F7807A25D7F84B000DBC97 /* phpmon-tests */, diff --git a/assets/icons.afdesign b/assets/icons.afdesign index d495d72..a78eaf1 100644 Binary files a/assets/icons.afdesign and b/assets/icons.afdesign differ diff --git a/assets/version.afdesign b/assets/version.afdesign new file mode 100644 index 0000000..35647e3 Binary files /dev/null and b/assets/version.afdesign differ diff --git a/phpmon-common/Core/Paths.swift b/phpmon-common/Core/Paths.swift index 56fc65b..a227cc3 100644 --- a/phpmon-common/Core/Paths.swift +++ b/phpmon-common/Core/Paths.swift @@ -20,7 +20,7 @@ public class Paths { private var userName : String init() { - baseDir = Shell.fileExists("\(HomebrewDir.opt.rawValue)/bin/brew") ? .opt : .usr + baseDir = FileManager.default.fileExists(atPath: "\(HomebrewDir.opt.rawValue)/bin/brew") ? .opt : .usr userName = String(Shell.pipe("whoami").split(separator: "\n")[0]) } diff --git a/phpmon-common/Core/Shell.swift b/phpmon-common/Core/Shell.swift index a1ae6c1..8ea3e2e 100644 --- a/phpmon-common/Core/Shell.swift +++ b/phpmon-common/Core/Shell.swift @@ -105,12 +105,12 @@ public class Shell { } /** - Checks if a file exists at the provided path. - Uses `/bin/echo` instead of the `builtin` (which does not support `-n`). + Checks if a file exists at a certain path. + Used to be done with a shell command, now uses the native FileManager class instead. */ public static func fileExists(_ path: String) -> Bool { - let escapedPath = path.replacingOccurrences(of: " ", with: "\\ ") - return Shell.pipe("if [ -f \(escapedPath) ]; then /bin/echo -n \"0\"; fi") == "0" + let fullPath = path.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)") + return FileManager.default.fileExists(atPath: fullPath) } /** diff --git a/phpmon/Assets.xcassets/MB_Elephant.imageset/Contents.json b/phpmon/Assets.xcassets/MB_Elephant.imageset/Contents.json new file mode 100644 index 0000000..5c666d4 --- /dev/null +++ b/phpmon/Assets.xcassets/MB_Elephant.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "filename" : "Menu Bar Elephant.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Menu Bar Elephant@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant.png b/phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant.png new file mode 100644 index 0000000..8dd923e Binary files /dev/null and b/phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant.png differ diff --git a/phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant@2x.png b/phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant@2x.png new file mode 100644 index 0000000..86bc7e8 Binary files /dev/null and b/phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant@2x.png differ diff --git a/phpmon/Assets.xcassets/StatusBarPHP.imageset/Contents.json b/phpmon/Assets.xcassets/MB_PHP.imageset/Contents.json similarity index 78% rename from phpmon/Assets.xcassets/StatusBarPHP.imageset/Contents.json rename to phpmon/Assets.xcassets/MB_PHP.imageset/Contents.json index effdb9c..0f8299a 100644 --- a/phpmon/Assets.xcassets/StatusBarPHP.imageset/Contents.json +++ b/phpmon/Assets.xcassets/MB_PHP.imageset/Contents.json @@ -1,11 +1,12 @@ { "images" : [ { + "filename" : "Menu Bar.png", "idiom" : "universal", "scale" : "1x" }, { - "filename" : "php@2x.png", + "filename" : "Menu Bar@2x.png", "idiom" : "universal", "scale" : "2x" }, diff --git a/phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar.png b/phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar.png new file mode 100644 index 0000000..179b98e Binary files /dev/null and b/phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar.png differ diff --git a/phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar@2x.png b/phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar@2x.png new file mode 100644 index 0000000..522077c Binary files /dev/null and b/phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar@2x.png differ diff --git a/phpmon/Assets.xcassets/StatusBarPHP.imageset/php@2x.png b/phpmon/Assets.xcassets/StatusBarPHP.imageset/php@2x.png deleted file mode 100644 index 497b4a8..0000000 Binary files a/phpmon/Assets.xcassets/StatusBarPHP.imageset/php@2x.png and /dev/null differ diff --git a/phpmon/Domain/Helpers/MenuBarImageGenerator.swift b/phpmon/Domain/Helpers/MenuBarImageGenerator.swift index 21621a7..f250b0f 100644 --- a/phpmon/Domain/Helpers/MenuBarImageGenerator.swift +++ b/phpmon/Domain/Helpers/MenuBarImageGenerator.swift @@ -42,7 +42,7 @@ class MenuBarImageGenerator { let targetImage: NSImage = NSImage(size: image.size) - let rep: NSBitmapImageRep = NSBitmapImageRep( + let representation: NSBitmapImageRep = NSBitmapImageRep( bitmapDataPlanes: nil, pixelsWide: Int(image.size.width), pixelsHigh: Int(image.size.height), @@ -55,7 +55,7 @@ class MenuBarImageGenerator { bitsPerPixel: 0 )! - targetImage.addRepresentation(rep) + targetImage.addRepresentation(representation) targetImage.lockFocus() image.draw(in: imageRect) @@ -69,32 +69,63 @@ class MenuBarImageGenerator { The same as before, but also attempts to add an icon to the left. */ 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 + // We'll start out with the image containing the text + let textImage = self.textToImage(text: text) + + // Then we'll fetch the image we want on the left + let iconImage = NSImage(named: "MB_PHP")! + + // We'll need to reference the width of the icon a bunch of times + let iconWidthSize = iconImage.size.width + + // There will also be an additional divider between the image and the text (image) + let divider: CGFloat = 3 + + // Use a fixed size for the height of the menu bar (18pt) let imageRect = CGRect( x: 0, y: 0, - width: textImage.size.width + divider, - height: textImage.size.height + width: textImage.size.width + iconWidthSize + divider, + height: 18 ) + // Create a new image, we'll draw the text and our icon in there let image: NSImage = NSImage(size: imageRect.size) image.lockFocus() + + // Calculate the offset between the image and the text + let offset = imageRect.size.width - textImage.size.width - let difference = imageRect.size.width - textImage.size.width + // Draw the text with a negative x offset (so there is room on the left for the icon) + textImage.draw( + in: imageRect, + from: NSRect( + x: -offset, + y: 0, + width: textImage.size.width + offset, + height: textImage.size.height + ), + operation: .overlay, + fraction: 1 + ) - 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) + // Draw the icon directly in the left of the imageRect (where we left space) + iconImage.draw( + in: imageRect, + from: NSRect( + x: 0, + y: 0, + width: imageRect.size.width, + height: imageRect.size.height + ), + operation: .overlay, + fraction: 1 + ) + // We're done with this image image.unlockFocus() + return image }