mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-12-30 01:54:49 +00:00
There is a sparkle-related 'issue' with the previous implementation. When you download/install in the `updateAvailable` state, if you don't install it, then check the updates again. Sparkle loses its downloaded stage in the delegate (it's normal when I use the sparkle source code). This time, when you click install in the `updateAvailable` state, it just uses the previous downloaded package and starts to install, without calling `showReady(toInstallAndRelaunch:)`. I think removing `readyToInstall` in our customed ui, will reduce one step to install an update for most of the users out there, which makes sense, since the current package is pretty small, only takes a few seconds to download for a normal network, and they intended to install this update.
37 lines
1.6 KiB
Swift
37 lines
1.6 KiB
Swift
import Sparkle
|
|
import Cocoa
|
|
|
|
extension UpdateDriver: 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"
|
|
}
|
|
}
|
|
|
|
/// Called when an update is scheduled to install silently,
|
|
/// which occurs when `auto-update = download`.
|
|
///
|
|
/// When `auto-update = check`, Sparkle will call the corresponding
|
|
/// delegate method on the responsible driver instead.
|
|
func updater(_ updater: SPUUpdater, willInstallUpdateOnQuit item: SUAppcastItem, immediateInstallationBlock immediateInstallHandler: @escaping () -> Void) -> Bool {
|
|
viewModel.state = .installing(.init(isAutoUpdate: true, retryTerminatingApplication: immediateInstallHandler))
|
|
return true
|
|
}
|
|
|
|
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() }
|
|
}
|
|
}
|