Skip to content

Commit 03ede46

Browse files
committed
fix: hashable conformance for timeofday and strong window delegate refs
- timeofday now conforms to hashable so scheduleblock can too - windowclosedelegate instances stored as strong properties on appdelegate to prevent immediate deallocation (nswindow.delegate is weak)
1 parent 04086c7 commit 03ede46

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

Tome/AppDelegate.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1717
private var aboutWindow: NSWindow?
1818
private var pauseWindow: NSWindow?
1919

20+
// window delegates must be held strongly (NSWindow.delegate is weak)
21+
private var prefsWindowDelegate: WindowCloseDelegate?
22+
private var aboutWindowDelegate: WindowCloseDelegate?
23+
2024
func applicationDidFinishLaunching(_ notification: Notification) {
2125
NSApp.setActivationPolicy(.accessory)
2226

@@ -204,7 +208,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
204208
.environmentObject(ScheduleManager.shared)
205209
let window = makeWindow(title: "Tome Preferences", content: view, size: NSSize(width: 680, height: 520))
206210
prefsWindow = window
207-
window.delegate = WindowCloseDelegate { [weak self] in self?.prefsWindow = nil }
211+
let prefsDelegate = WindowCloseDelegate { [weak self] in self?.prefsWindow = nil }
212+
prefsWindowDelegate = prefsDelegate
213+
window.delegate = prefsDelegate
208214
}
209215
prefsWindow?.makeKeyAndOrderFront(nil)
210216
NSApp.activate(ignoringOtherApps: true)
@@ -216,7 +222,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
216222
let window = makeWindow(title: "About Tome", content: view, size: NSSize(width: 340, height: 300))
217223
window.styleMask = [.titled, .closable]
218224
aboutWindow = window
219-
window.delegate = WindowCloseDelegate { [weak self] in self?.aboutWindow = nil }
225+
let aboutDelegate = WindowCloseDelegate { [weak self] in self?.aboutWindow = nil }
226+
aboutWindowDelegate = aboutDelegate
227+
window.delegate = aboutDelegate
220228
}
221229
aboutWindow?.makeKeyAndOrderFront(nil)
222230
NSApp.activate(ignoringOtherApps: true)

Tome/Models/ScheduleBlock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enum Weekday: Int, Codable, CaseIterable, Identifiable {
3030
}
3131
}
3232

33-
struct TimeOfDay: Codable, Equatable {
33+
struct TimeOfDay: Codable, Equatable, Hashable {
3434
var hour: Int // 0-23
3535
var minute: Int // 0-59
3636

0 commit comments

Comments
 (0)