Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public final class NativeHostApplicationController: NSObject, NSApplicationDeleg
private var selfCaptureRegistrationWindow: NSWindow?
private var didBootstrap = false
private var didPresentLaunchPermissionOnboarding = false
private let softwareUpdater = NativeHostSoftwareUpdater()
private lazy var softwareUpdater = NativeHostSoftwareUpdater()
@objc public dynamic var window: NSWindow?
private lazy var sessionController: CaptureSessionController = {
let controller = CaptureSessionController(settingsStore: settingsStore)
Expand Down Expand Up @@ -145,6 +145,7 @@ public final class NativeHostApplicationController: NSObject, NSApplicationDeleg
)
Self.applyApplicationIcon()
configureStatusItem()
_ = softwareUpdater
configureGlobalHotKeys()
showSelfCaptureRegistrationWindow()
NotificationCenter.default.addObserver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import Sparkle

@MainActor
final class NativeHostSoftwareUpdater {
final class NativeHostSoftwareUpdater: NSObject {
enum Mode: String, CaseIterable {
case off
case check
Expand Down Expand Up @@ -60,14 +60,15 @@ final class NativeHostSoftwareUpdater {
host: "github.com",
path: "/hack-ink/rsnap/releases/latest")

private let updaterController: SPUStandardUpdaterController?
private var updaterController: SPUStandardUpdaterController?

init() {
override init() {
super.init()
if Self.hasSparkleConfiguration {
let controller = SPUStandardUpdaterController(
startingUpdater: true,
updaterDelegate: nil,
userDriverDelegate: nil)
userDriverDelegate: self)
updaterController = controller
NativeHostTelemetry.lifecycleEvent("native_host.sparkle_updater_started")
requestImmediateLaunchUpdateCheckIfEnabled(using: controller.updater)
Expand Down Expand Up @@ -177,6 +178,11 @@ final class NativeHostSoftwareUpdater {
return trimmed.isEmpty ? nil : trimmed
}

private func showUpdateAlertInFront() {
NSApp.setActivationPolicy(.regular)
NSRunningApplication.current.activate(options: [.activateAllWindows])
}

private static func httpsURL(host: String, path: String) -> URL {
var components = URLComponents()
components.scheme = "https"
Expand All @@ -189,6 +195,33 @@ final class NativeHostSoftwareUpdater {
}
}

extension NativeHostSoftwareUpdater: @preconcurrency SPUStandardUserDriverDelegate {
var supportsGentleScheduledUpdateReminders: Bool {
true
}

func standardUserDriverShouldHandleShowingScheduledUpdate(
_: SUAppcastItem,
andInImmediateFocus _: Bool
) -> Bool {
true
}

func standardUserDriverWillHandleShowingUpdate(
_ handleShowingUpdate: Bool,
forUpdate _: SUAppcastItem,
state _: SPUUserUpdateState
) {
guard handleShowingUpdate else {
return
}
showUpdateAlertInFront()
NativeHostTelemetry.lifecycleEvent(
"native_host.sparkle_update_alert_focused",
detail: "source=standard_driver")
}
}

package enum SoftwareUpdateModeResolution {
fileprivate static func mode(
automaticallyChecksForUpdates: Bool,
Expand Down