-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
59 lines (50 loc) · 1.74 KB
/
AppDelegate.swift
File metadata and controls
59 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Cocoa
import SwiftUI
class AppDelegate: NSObject, NSApplicationDelegate {
var window: OverlayWindow?
var statusItem: NSStatusItem!
func applicationDidFinishLaunching(_ notification: Notification) {
// Create the overlay window (start hidden)
let contentView = NSHostingView(rootView: ContentView())
window = OverlayWindow(view: contentView)
window?.orderOut(nil)
// Create menu bar icon
setupStatusItem()
}
private func setupStatusItem() {
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
if let button = statusItem.button {
button.image = NSImage(
systemSymbolName: "bubble.left.and.bubble.right.fill",
accessibilityDescription: "Overlay ChatGPT"
)
button.target = self
button.action = #selector(toggleOverlay(_:))
}
let menu = NSMenu()
menu.addItem(
withTitle: "Show / Hide Overlay",
action: #selector(toggleOverlay(_:)),
keyEquivalent: ""
)
menu.addItem(
withTitle: "Quit",
action: #selector(quitAppFromMenu(_:)),
keyEquivalent: "q"
)
statusItem.menu = menu
statusItem.menu?.autoenablesItems = false
}
@objc private func toggleOverlay(_ sender: Any?) {
guard let window = window else { return }
if window.isVisible {
window.orderOut(nil)
} else {
window.makeKeyAndOrderFront(nil)
NSApplication.shared.activate(ignoringOtherApps: true)
}
}
@objc private func quitAppFromMenu(_ sender: Any?) {
NSApplication.shared.terminate(nil)
}
}