mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added calendar reset and update mechanism when opening the popup view
This commit is contained in:
@@ -84,7 +84,7 @@ internal class Popup: PopupWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
override func settings() -> NSView? {
|
||||
public override func settings() -> NSView? {
|
||||
let view = SettingsContainerView()
|
||||
|
||||
view.addArrangedSubview(PreferencesSection([
|
||||
@@ -99,6 +99,12 @@ internal class Popup: PopupWrapper {
|
||||
return view
|
||||
}
|
||||
|
||||
public override func appear() {
|
||||
if self.calendarState {
|
||||
self.calendarView?.checkCurrentDay()
|
||||
}
|
||||
}
|
||||
|
||||
private func rearrange() {
|
||||
let views = self.subviews.filter{ $0 is ClockView }.compactMap{ $0 as? ClockView }
|
||||
views.forEach{ $0.removeFromSuperview() }
|
||||
@@ -124,6 +130,7 @@ private class CalendarView: NSStackView {
|
||||
|
||||
private var year: Int
|
||||
private var month: Int
|
||||
private var day: Int
|
||||
|
||||
private var currentYear: Int {
|
||||
Calendar.current.component(.year, from: Date())
|
||||
@@ -155,6 +162,7 @@ private class CalendarView: NSStackView {
|
||||
)
|
||||
self.year = Calendar.current.component(.year, from: Date())
|
||||
self.month = Calendar.current.component(.month, from: Date())
|
||||
self.day = Calendar.current.component(.day, from: Date())
|
||||
|
||||
super.init(frame: NSRect(x: 0, y: 0, width: width, height: width - 32))
|
||||
|
||||
@@ -177,6 +185,16 @@ private class CalendarView: NSStackView {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
public func checkCurrentDay() {
|
||||
guard self.day != self.currentDay || self.month != self.currentMonth || self.year != self.currentYear else { return }
|
||||
|
||||
self.year = self.currentYear
|
||||
self.month = self.currentMonth
|
||||
self.day = self.currentDay
|
||||
|
||||
self.setup()
|
||||
}
|
||||
|
||||
override func updateLayer() {
|
||||
self.layer?.backgroundColor = (isDarkMode ? NSColor(red: 17/255, green: 17/255, blue: 17/255, alpha: 0.25) : NSColor(red: 245/255, green: 245/255, blue: 245/255, alpha: 1)).cgColor
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user