1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50: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:
2022-02-05 00:41:10 +01:00
parent 18d6d73f94
commit a13a17b106
14 changed files with 79 additions and 23 deletions

View File

@ -1,4 +1,4 @@
# README for interested developers
# DEVELOPER README
## 🔧 Build instructions

View File

@ -242,6 +242,7 @@
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>"; };
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>"; };
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; };
@ -446,6 +447,7 @@
C4F8C0A522D4FA41002EFE61 /* README.md */,
C4E713562570150F00007428 /* SECURITY.md */,
C4F7807425D7F7E5000DBC97 /* RELEASE.md */,
C4168F4427ADB4A3003B6C39 /* DEVELOPER.md */,
C4E713572570151400007428 /* docs */,
C41C1B3522B0097F00E7CF16 /* phpmon */,
C4F7807A25D7F84B000DBC97 /* phpmon-tests */,

Binary file not shown.

BIN
assets/version.afdesign Normal file

Binary file not shown.

View File

@ -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])
}

View File

@ -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)
}
/**

View 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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -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"
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 940 B

View File

@ -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
}