58 lines
1.6 KiB
Swift
58 lines
1.6 KiB
Swift
//
|
|
// AppDelegate.swift
|
|
// AlDente
|
|
//
|
|
// Created by David Wernhart on 09.02.20.
|
|
// Copyright © 2020 David Wernhart. All rights reserved.
|
|
//
|
|
|
|
import AppKit
|
|
import SwiftUI
|
|
import LaunchAtLogin
|
|
|
|
@NSApplicationMain
|
|
final 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?.image = NSImage(named: "menubaricon")!
|
|
statusBarItem.button?.action = #selector(togglePopover(_:))
|
|
|
|
Helper.instance.checkHelperVersion()
|
|
|
|
LaunchAtLogin.isEnabled = true
|
|
}
|
|
|
|
@objc func togglePopover(_ sender: AnyObject?) {
|
|
popover.contentViewController?.view.window?.becomeKey()
|
|
|
|
if let button = self.statusBarItem.button {
|
|
if popover.isShown {
|
|
popover.performClose(sender)
|
|
} else {
|
|
popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
|
|
}
|
|
}
|
|
}
|
|
|
|
func applicationWillTerminate(_ aNotification: Notification) {
|
|
// Insert code here to tear down your application
|
|
}
|
|
|
|
}
|