macos: boilerplate to setup updater menu item

This commit is contained in:
Mitchell Hashimoto
2023-12-18 13:41:46 -08:00
parent caf6ebc6ef
commit f192ffd5bc
2 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import AppKit import AppKit
import UserNotifications import UserNotifications
import OSLog import OSLog
import Sparkle
import GhosttyKit import GhosttyKit
class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, UNUserNotificationCenterDelegate, GhosttyAppStateDelegate { 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. /// 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 menuOpenConfig: NSMenuItem?
@IBOutlet private var menuReloadConfig: NSMenuItem? @IBOutlet private var menuReloadConfig: NSMenuItem?
@IBOutlet private var menuQuit: NSMenuItem? @IBOutlet private var menuQuit: NSMenuItem?
@ -56,8 +58,17 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, UNUserNoti
/// Manages our terminal windows. /// Manages our terminal windows.
let terminalManager: TerminalManager let terminalManager: TerminalManager
/// Manages updates
let updaterController: SPUStandardUpdaterController
override init() { override init() {
self.terminalManager = TerminalManager(ghostty) terminalManager = TerminalManager(ghostty)
updaterController = SPUStandardUpdaterController(
startingUpdater: true,
updaterDelegate: nil,
userDriverDelegate: nil
)
super.init() super.init()
ghostty.delegate = self ghostty.delegate = self
@ -80,6 +91,10 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, UNUserNoti
"ApplePressAndHoldEnabled": false, "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 // 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 possible to have other windows if we're opening a URL since `application(_:openFile:)`
// is called before this. // is called before this.

View File

@ -14,6 +14,7 @@
<customObject id="-3" userLabel="Application" customClass="NSObject"/> <customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="bbz-4X-AYv" userLabel="AppDelegate" customClass="AppDelegate" customModule="Ghostty" customModuleProvider="target"> <customObject id="bbz-4X-AYv" userLabel="AppDelegate" customClass="AppDelegate" customModule="Ghostty" customModuleProvider="target">
<connections> <connections>
<outlet property="menuCheckForUpdates" destination="GEA-5y-yzH" id="0nV-Tf-nJQ"/>
<outlet property="menuClose" destination="DVo-aG-piG" id="R3t-0C-aSU"/> <outlet property="menuClose" destination="DVo-aG-piG" id="R3t-0C-aSU"/>
<outlet property="menuCloseAllWindows" destination="yKr-Vi-Yqw" id="Zet-Ir-zbm"/> <outlet property="menuCloseAllWindows" destination="yKr-Vi-Yqw" id="Zet-Ir-zbm"/>
<outlet property="menuCloseWindow" destination="W5w-UZ-crk" id="6ff-BT-ENV"/> <outlet property="menuCloseWindow" destination="W5w-UZ-crk" id="6ff-BT-ENV"/>
@ -58,6 +59,9 @@
<action selector="showAbout:" target="-1" id="tGt-68-tLn"/> <action selector="showAbout:" target="-1" id="tGt-68-tLn"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title="Check for Updates..." id="GEA-5y-yzH">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/> <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"> <menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
<connections> <connections>