Files
ghostty/macos/Sources/Features/About/AboutViewModel.swift
Lukas a79557f521 macOS: stop cycling icons when AboutWindow is closed
and start cycling with current icon
2026-02-24 08:58:15 +01:00

41 lines
1022 B
Swift

import Combine
class AboutViewModel: ObservableObject {
@Published var currentIcon: Ghostty.MacOSIcon?
@Published var isHovering: Bool = false
private var timerCancellable: AnyCancellable?
private let icons: [Ghostty.MacOSIcon] = [
.official,
.blueprint,
.chalkboard,
.microchip,
.glass,
.holographic,
.paper,
.retro,
.xray,
]
func startCyclingIcons() {
timerCancellable = Timer.publish(every: 3, on: .main, in: .common)
.autoconnect()
.sink { [weak self] _ in
guard let self, !isHovering else { return }
advanceToNextIcon()
}
}
func stopCyclingIcons() {
timerCancellable = nil
currentIcon = nil
}
func advanceToNextIcon() {
let currentIndex = currentIcon.flatMap(icons.firstIndex(of:)) ?? 0
let nextIndex = icons.indexWrapping(after: currentIndex)
currentIcon = icons[nextIndex]
}
}