mirror of
https://github.com/AppHouseKitchen/AlDente-Battery_Care_and_Monitoring.git
synced 2026-04-26 10:48:41 +02:00
first commit
This commit is contained in:
64
AlDente/AppDelegate.swift
Normal file
64
AlDente/AppDelegate.swift
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// AlDente
|
||||
//
|
||||
// Created by David Wernhart on 09.02.20.
|
||||
// Copyright © 2020 David Wernhart. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import SwiftUI
|
||||
import ServiceManagement
|
||||
import Foundation
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
//var window: NSWindow!
|
||||
var statusBarItem: NSStatusItem!
|
||||
var popover: NSPopover!
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
|
||||
let contentView = ContentView()
|
||||
|
||||
// Create the popover
|
||||
let popover = NSPopover()
|
||||
popover.contentSize = NSSize(width: 400, height: 600)
|
||||
popover.behavior = .transient
|
||||
popover.contentViewController = NSHostingController(rootView: contentView)
|
||||
self.popover = popover
|
||||
|
||||
|
||||
let statusBar = NSStatusBar.system
|
||||
statusBarItem = statusBar.statusItem(
|
||||
withLength: NSStatusItem.squareLength)
|
||||
statusBarItem.button?.title = "🍝"
|
||||
|
||||
if let button = self.statusBarItem.button {
|
||||
button.action = #selector(togglePopover(_:))
|
||||
}
|
||||
|
||||
Helper.instance.checkHelperVersion()
|
||||
|
||||
}
|
||||
|
||||
@objc func togglePopover(_ sender: AnyObject?) {
|
||||
self.popover.contentViewController?.view.window?.becomeKey()
|
||||
if let button = self.statusBarItem.button {
|
||||
if self.popover.isShown {
|
||||
self.popover.performClose(sender)
|
||||
} else {
|
||||
self.popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
// Insert code here to tear down your application
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user