added macOSMenuBar

This commit is contained in:
SerenityUX 2023-05-13 15:33:31 -04:00 committed by Conrad Kramer
parent efee4afc8d
commit 534e615919
9 changed files with 160 additions and 35 deletions

View file

@ -4,14 +4,50 @@ import SwiftUI
@main
@MainActor
struct BurrowApp: App {
//To connect to the App Delegate
@NSApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
TunnelView()
}
}
}
@MainActor
class AppDelegate: NSObject, NSApplicationDelegate {
static let tunnel = Tunnel { manager, proto in
proto.serverAddress = "hackclub.com"
manager.localizedDescription = "Burrow"
}
var body: some Scene {
WindowGroup {
TunnelView(tunnel: Self.tunnel)
var statusItem: NSStatusItem?
var popOver = NSPopover()
func applicationDidFinishLaunching(_ notification: Notification) {
let menuView = MenuView(tunnel: AppDelegate.tunnel)
// Creating apopOver
popOver.behavior = .transient
popOver.animates = true
popOver.contentViewController = NSViewController()
popOver.contentViewController?.view = NSHostingView(rootView: menuView)
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
// Safe Check if status Button is Available or not...
if let menuButton = statusItem?.button {
let icon = "network.badge.shield.half.filled"
menuButton.image = NSImage(systemSymbolName: icon, accessibilityDescription: nil)
menuButton.action = #selector(menuButtonToggle)
}
}
@objc func menuButtonToggle() {
if let menuButton = statusItem?.button {
self.popOver.show(relativeTo: menuButton.bounds, of: menuButton, preferredEdge: NSRectEdge.minY)
}
}
}