This repository has been archived on 2026-03-31. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
1.1.1.1-macOS/four/AppDelegate.swift

44 lines
1.3 KiB
Swift

//
// AppDelegate.swift
// four
//
// Created by Ryan McGrath on 12/23/18.
// Copyright © 2018 Ryan McGrath. All rights reserved.
//
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
lazy var popover: NSPopover = {
return NSPopover()
}()
lazy var statusItem: NSStatusItem = {
return NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
}()
func applicationDidFinishLaunching(_ aNotification: Notification) {
popover.behavior = .transient
popover.appearance = NSAppearance.current
popover.contentSize = CGSize(width: 300.0, height: 300.0)
popover.contentViewController = ViewController()
let statusBarIcon = Icons.statusBarIcon()
statusBarIcon.isTemplate = true
statusItem.button?.image = statusBarIcon
statusItem.button?.alternateImage = statusBarIcon
statusItem.button?.action = #selector(togglePopover)
}
func applicationWillTerminate(_ aNotification: Notification) {
}
@objc
func togglePopover(sender: Any?) {
if(popover.isShown) {
popover.performClose(sender)
} else {
popover.show(relativeTo: statusItem.button!.bounds, of: statusItem.button!, preferredEdge: .minY)
}
}
}