Skip to content

Commit

Permalink
feat: added calendar reset and update mechanism when opening the popu…
Browse files Browse the repository at this point in the history
…p view
  • Loading branch information
exelban committed Oct 19, 2024
1 parent 9ed4ee5 commit 65fcc70
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Modules/Clock/popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal class Popup: PopupWrapper {
}
}

override func settings() -> NSView? {
public override func settings() -> NSView? {
let view = SettingsContainerView()

view.addArrangedSubview(PreferencesSection([
Expand All @@ -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() }
Expand All @@ -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())
Expand Down Expand Up @@ -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))

Expand All @@ -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
}
Expand Down

0 comments on commit 65fcc70

Please sign in to comment.