mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
👌 Various improvements
- Properly draw the menu bar icon (now with extra documentation) - Resolve Paths via FileManager.default - Updated DEV readme - Add PHP Elephant icon (TBD)
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
# README for interested developers
|
# DEVELOPER README
|
||||||
|
|
||||||
## 🔧 Build instructions
|
## 🔧 Build instructions
|
||||||
|
|
@ -242,6 +242,7 @@
|
|||||||
C415D3DE2770F34D005EF286 /* AllowedArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AllowedArguments.swift; sourceTree = "<group>"; };
|
C415D3DE2770F34D005EF286 /* AllowedArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AllowedArguments.swift; sourceTree = "<group>"; };
|
||||||
C415D3E52770F540005EF286 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
C415D3E52770F540005EF286 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||||
C415D3E72770F692005EF286 /* AppDelegate+InterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+InterApp.swift"; sourceTree = "<group>"; };
|
C415D3E72770F692005EF286 /* AppDelegate+InterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+InterApp.swift"; sourceTree = "<group>"; };
|
||||||
|
C4168F4427ADB4A3003B6C39 /* DEVELOPER.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = DEVELOPER.md; sourceTree = "<group>"; };
|
||||||
C417DC73277614690015E6EE /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
|
C417DC73277614690015E6EE /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
|
||||||
C4188988275FE8CB001EF227 /* Filesystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filesystem.swift; sourceTree = "<group>"; };
|
C4188988275FE8CB001EF227 /* Filesystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filesystem.swift; sourceTree = "<group>"; };
|
||||||
C41C1B3322B0097F00E7CF16 /* PHP Monitor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PHP Monitor.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
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 */,
|
C4F8C0A522D4FA41002EFE61 /* README.md */,
|
||||||
C4E713562570150F00007428 /* SECURITY.md */,
|
C4E713562570150F00007428 /* SECURITY.md */,
|
||||||
C4F7807425D7F7E5000DBC97 /* RELEASE.md */,
|
C4F7807425D7F7E5000DBC97 /* RELEASE.md */,
|
||||||
|
C4168F4427ADB4A3003B6C39 /* DEVELOPER.md */,
|
||||||
C4E713572570151400007428 /* docs */,
|
C4E713572570151400007428 /* docs */,
|
||||||
C41C1B3522B0097F00E7CF16 /* phpmon */,
|
C41C1B3522B0097F00E7CF16 /* phpmon */,
|
||||||
C4F7807A25D7F84B000DBC97 /* phpmon-tests */,
|
C4F7807A25D7F84B000DBC97 /* phpmon-tests */,
|
||||||
|
Binary file not shown.
BIN
assets/version.afdesign
Normal file
BIN
assets/version.afdesign
Normal file
Binary file not shown.
@ -20,7 +20,7 @@ public class Paths {
|
|||||||
private var userName : String
|
private var userName : String
|
||||||
|
|
||||||
init() {
|
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])
|
userName = String(Shell.pipe("whoami").split(separator: "\n")[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,12 +105,12 @@ public class Shell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks if a file exists at the provided path.
|
Checks if a file exists at a certain path.
|
||||||
Uses `/bin/echo` instead of the `builtin` (which does not support `-n`).
|
Used to be done with a shell command, now uses the native FileManager class instead.
|
||||||
*/
|
*/
|
||||||
public static func fileExists(_ path: String) -> Bool {
|
public static func fileExists(_ path: String) -> Bool {
|
||||||
let escapedPath = path.replacingOccurrences(of: " ", with: "\\ ")
|
let fullPath = path.replacingOccurrences(of: "~", with: "/Users/\(Paths.whoami)")
|
||||||
return Shell.pipe("if [ -f \(escapedPath) ]; then /bin/echo -n \"0\"; fi") == "0"
|
return FileManager.default.fileExists(atPath: fullPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
22
phpmon/Assets.xcassets/MB_Elephant.imageset/Contents.json
vendored
Normal file
22
phpmon/Assets.xcassets/MB_Elephant.imageset/Contents.json
vendored
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
BIN
phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant.png
vendored
Normal file
BIN
phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant@2x.png
vendored
Normal file
BIN
phpmon/Assets.xcassets/MB_Elephant.imageset/Menu Bar Elephant@2x.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
|
"filename" : "Menu Bar.png",
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "php@2x.png",
|
"filename" : "Menu Bar@2x.png",
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
},
|
},
|
BIN
phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar.png
vendored
Normal file
BIN
phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 658 B |
BIN
phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar@2x.png
vendored
Normal file
BIN
phpmon/Assets.xcassets/MB_PHP.imageset/Menu Bar@2x.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 793 B |
Binary file not shown.
Before Width: | Height: | Size: 940 B |
@ -42,7 +42,7 @@ class MenuBarImageGenerator {
|
|||||||
|
|
||||||
let targetImage: NSImage = NSImage(size: image.size)
|
let targetImage: NSImage = NSImage(size: image.size)
|
||||||
|
|
||||||
let rep: NSBitmapImageRep = NSBitmapImageRep(
|
let representation: NSBitmapImageRep = NSBitmapImageRep(
|
||||||
bitmapDataPlanes: nil,
|
bitmapDataPlanes: nil,
|
||||||
pixelsWide: Int(image.size.width),
|
pixelsWide: Int(image.size.width),
|
||||||
pixelsHigh: Int(image.size.height),
|
pixelsHigh: Int(image.size.height),
|
||||||
@ -55,7 +55,7 @@ class MenuBarImageGenerator {
|
|||||||
bitsPerPixel: 0
|
bitsPerPixel: 0
|
||||||
)!
|
)!
|
||||||
|
|
||||||
targetImage.addRepresentation(rep)
|
targetImage.addRepresentation(representation)
|
||||||
targetImage.lockFocus()
|
targetImage.lockFocus()
|
||||||
|
|
||||||
image.draw(in: imageRect)
|
image.draw(in: imageRect)
|
||||||
@ -69,32 +69,63 @@ class MenuBarImageGenerator {
|
|||||||
The same as before, but also attempts to add an icon to the left.
|
The same as before, but also attempts to add an icon to the left.
|
||||||
*/
|
*/
|
||||||
public static func textToImageWithIcon(text: String) -> NSImage {
|
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(
|
let imageRect = CGRect(
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: textImage.size.width + divider,
|
width: textImage.size.width + iconWidthSize + divider,
|
||||||
height: textImage.size.height
|
height: 18
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create a new image, we'll draw the text and our icon in there
|
||||||
let image: NSImage = NSImage(size: imageRect.size)
|
let image: NSImage = NSImage(size: imageRect.size)
|
||||||
image.lockFocus()
|
image.lockFocus()
|
||||||
|
|
||||||
let difference = imageRect.size.width - textImage.size.width
|
// Calculate the offset between the image and the text
|
||||||
|
let offset = imageRect.size.width - textImage.size.width
|
||||||
|
|
||||||
textImage.draw(in: imageRect, from: NSRect(
|
// Draw the text with a negative x offset (so there is room on the left for the icon)
|
||||||
x: -difference,
|
textImage.draw(
|
||||||
y: 0, width: textImage.size.width + difference,
|
in: imageRect,
|
||||||
height: textImage.size.height
|
from: NSRect(
|
||||||
), operation: .overlay, fraction: 1)
|
x: -offset,
|
||||||
|
y: 0,
|
||||||
|
width: textImage.size.width + offset,
|
||||||
|
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()
|
image.unlockFocus()
|
||||||
|
|
||||||
return image
|
return image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user