|
|
@@ -10,21 +10,32 @@ import Cocoa
|
|
|
@main
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
private var statusItem: NSStatusItem?
|
|
|
- private let customMenuBarIconPath = "/Users/devmac1/Downloads/menu_bar_icon.png"
|
|
|
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
|
|
+ applyBundledAppIcon()
|
|
|
configureMainWindowIfNeeded()
|
|
|
setupStatusBarItem()
|
|
|
StatusBarAppIconsController.shared.start()
|
|
|
}
|
|
|
|
|
|
+ private func applyBundledAppIcon() {
|
|
|
+ if let assetAppIcon = NSImage(named: "AppIcon") {
|
|
|
+ NSApp.applicationIconImage = assetAppIcon
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if let icnsURL = Bundle.main.url(forResource: "AppIcon", withExtension: "icns"),
|
|
|
+ let icnsIcon = NSImage(contentsOf: icnsURL) {
|
|
|
+ NSApp.applicationIconImage = icnsIcon
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private func setupStatusBarItem() {
|
|
|
let item = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
|
|
|
statusItem = item
|
|
|
|
|
|
guard let button = item.button else { return }
|
|
|
- if let customIcon = NSImage(contentsOfFile: customMenuBarIconPath) {
|
|
|
- button.image = scaledMenuBarIcon(from: customIcon)
|
|
|
+ if let menuBarIcon = NSImage(named: "menu_bar_icon") {
|
|
|
+ button.image = menuBarIcon
|
|
|
button.image?.isTemplate = false
|
|
|
} else {
|
|
|
button.image = NSImage(systemSymbolName: "square.grid.2x2.fill", accessibilityDescription: "My Apps")
|
|
|
@@ -37,30 +48,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
|
|
|
}
|
|
|
|
|
|
- private func scaledMenuBarIcon(from source: NSImage) -> NSImage {
|
|
|
- let side: CGFloat = 16
|
|
|
- let target = NSSize(width: side, height: side)
|
|
|
- let srcSize = source.size
|
|
|
- guard srcSize.width > 0, srcSize.height > 0 else { return source }
|
|
|
-
|
|
|
- let image = NSImage(size: target, flipped: false) { _ in
|
|
|
- let scale = min(side / srcSize.width, side / srcSize.height)
|
|
|
- let width = srcSize.width * scale
|
|
|
- let height = srcSize.height * scale
|
|
|
- let x = (side - width) / 2
|
|
|
- let y = (side - height) / 2
|
|
|
- let destinationRect = NSRect(x: x, y: y, width: width, height: height)
|
|
|
- source.draw(
|
|
|
- in: destinationRect,
|
|
|
- from: NSRect(origin: .zero, size: srcSize),
|
|
|
- operation: .sourceOver,
|
|
|
- fraction: 1
|
|
|
- )
|
|
|
- return true
|
|
|
- }
|
|
|
- return image
|
|
|
- }
|
|
|
-
|
|
|
@objc
|
|
|
private func statusBarButtonClicked(_ sender: Any?) {
|
|
|
guard let event = NSApp.currentEvent else {
|