From f192ffd5bc644227d723469aaf4712f8d8317fd5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 18 Dec 2023 13:41:46 -0800 Subject: [PATCH] macos: boilerplate to setup updater menu item --- macos/Sources/AppDelegate.swift | 17 ++++++++++++++++- macos/Sources/MainMenu.xib | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/macos/Sources/AppDelegate.swift b/macos/Sources/AppDelegate.swift index d1b16d176..e39b34365 100644 --- a/macos/Sources/AppDelegate.swift +++ b/macos/Sources/AppDelegate.swift @@ -1,6 +1,7 @@ import AppKit import UserNotifications import OSLog +import Sparkle import GhosttyKit class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, UNUserNotificationCenterDelegate, GhosttyAppStateDelegate { @@ -12,6 +13,7 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, UNUserNoti ) /// Various menu items so that we can programmatically sync the keyboard shortcut with the Ghostty config. + @IBOutlet private var menuCheckForUpdates: NSMenuItem? @IBOutlet private var menuOpenConfig: NSMenuItem? @IBOutlet private var menuReloadConfig: NSMenuItem? @IBOutlet private var menuQuit: NSMenuItem? @@ -56,8 +58,17 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, UNUserNoti /// Manages our terminal windows. let terminalManager: TerminalManager + /// Manages updates + let updaterController: SPUStandardUpdaterController + override init() { - self.terminalManager = TerminalManager(ghostty) + terminalManager = TerminalManager(ghostty) + updaterController = SPUStandardUpdaterController( + startingUpdater: true, + updaterDelegate: nil, + userDriverDelegate: nil + ) + super.init() ghostty.delegate = self @@ -80,6 +91,10 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, UNUserNoti "ApplePressAndHoldEnabled": false, ]) + // Hook up updater menu + menuCheckForUpdates?.target = updaterController + menuCheckForUpdates?.action = #selector(SPUStandardUpdaterController.checkForUpdates(_:)) + // Let's launch our first window. We only do this if we have no other windows. It // is possible to have other windows if we're opening a URL since `application(_:openFile:)` // is called before this. diff --git a/macos/Sources/MainMenu.xib b/macos/Sources/MainMenu.xib index df7635f9a..87b197e6b 100644 --- a/macos/Sources/MainMenu.xib +++ b/macos/Sources/MainMenu.xib @@ -14,6 +14,7 @@ + @@ -58,6 +59,9 @@ + + +