A MacOS menu bar applet that displays the current lunar phase.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

//
// ViewController.swift
// LunaMac
//
// Created by Claire Davis on 9/22/22.
// Copyright © 2022 A Better Geek. All rights reserved.
//
import Cocoa
class ViewController: NSViewController, NSWindowDelegate {
let appDelegate = NSApplication.shared.delegate as! AppDelegate
@IBOutlet var textView: NSTextView!
override func viewDidLoad() {
print("view did load")
super.viewDidLoad()
toggleWindow(boolShow: true)
}
override func viewDidAppear() {
self.view.window?.delegate = self
// use this to load the changelog, maybe?
if (self.view.window?.title.contains("Changelog") ?? false) {
let logPath = Bundle.main.path(forResource: "changelog.txt", ofType: nil)!
let logText = try! String(contentsOfFile: logPath, encoding: String.Encoding.utf8)
print(logText)
}
}
// triggers when window is closed
override func viewWillDisappear() {
print("view will disappear")
toggleWindow(boolShow: false)
}
func toggleWindow(boolShow: Bool = false) {
// get the window title to set the right bool
// window title is in self.view.window.title
let winTitle = self.view.window?.title
if (winTitle?.contains("About") ?? false) {
appDelegate.infoOpen = boolShow
}
else if (winTitle?.contains("Changelog") ?? false) {
appDelegate.logOpen = boolShow
}
}
}