ghostty/macos/Sources/Features/Update/UpdateDelegate.swift
Mitchell Hashimoto 8f15f1a066 Make Ghostty release channel aware
Ghostty now has a release channel build configuration. Current valid
values are "tip" and "stable" but I imagine more will be added in the
future.

The release channel is inferred whether the version we specify with the
`-Dversion-string` build flag has a prerelease tag or not. If it does,
the release channel is "tip". If it doesn't, the release channel is
"stable".

This also adds a configuration to specify the release channel for
auto-updates for the macOS application.
2024-12-20 14:21:59 -08:00

27 lines
1.0 KiB
Swift

import Sparkle
import Cocoa
class UpdaterDelegate: NSObject, SPUUpdaterDelegate {
func feedURLString(for updater: SPUUpdater) -> String? {
guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else {
return nil
}
// Sparkle supports a native concept of "channels" but it requires that
// you share a single appcast file. We don't want to do that so we
// do this instead.
switch (appDelegate.ghostty.config.autoUpdateChannel) {
case .tip: return "https://tip.files.ghostty.org/appcast.xml"
case .stable: return "https://release.files.ghostty.org/appcast.xml"
}
}
func updaterWillRelaunchApplication(_ updater: SPUUpdater) {
// When the updater is relaunching the application we want to get macOS
// to invalidate and re-encode all of our restorable state so that when
// we relaunch it uses it.
NSApp.invalidateRestorableState()
for window in NSApp.windows { window.invalidateRestorableState() }
}
}