Initial commit: IceGlass NHL game tracker

macOS menu bar app providing NHL game situational awareness with
league-wide scoreboard, dynamic polling, notifications with team
logos, and configurable display options.
This commit is contained in:
2026-04-13 21:44:08 -04:00
commit 8f8f8b2755
158 changed files with 2752 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
//
// ApiService.swift
// IceGlass
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//
import Foundation
typealias ApiServiceCallback = (_ jsonData: Data, _ response: URLResponse) -> Void
class ApiService: @unchecked Sendable {
private let logger = IceGlassLogger(
subsystem: Bundle.main.bundleIdentifier ?? "dev.rzen.indie.IceGlass",
category: "ApiService"
)
let url: URL
let callback: ApiServiceCallback
var previousFetchTime: Date = .distantPast
init(url: URL?, callback: @escaping ApiServiceCallback) {
guard let url = url else {
AppTerminator.terminate()
self.url = URL(string: "")!
self.callback = { (_: Data, _: URLResponse) in }
return
}
self.url = url
self.callback = callback
}
func fetch() async {
do {
let (data, response) = try await URLSession.shared.data(from: url)
logger.info("Polling: \(self.url)")
logger.debug("Previous: \(Date.now.timeIntervalSince(previousFetchTime).humanReadableTime())")
previousFetchTime = Date.now
callback(data, response)
} catch {
logger.error("Invalid response from \(self.url) \(error)")
}
}
}