macos: add "Check for Updates" action, menu item & key-binding support

This commit is contained in:
Aaron Ruan
2025-05-15 13:34:44 +08:00
parent a090e8eeed
commit 7ccc181332
8 changed files with 36 additions and 4 deletions

View File

@@ -667,6 +667,7 @@ typedef enum {
GHOSTTY_ACTION_CONFIG_CHANGE,
GHOSTTY_ACTION_CLOSE_WINDOW,
GHOSTTY_ACTION_RING_BELL,
GHOSTTY_ACTION_CHECK_FOR_UPDATES
} ghostty_action_tag_e;
typedef union {

View File

@@ -154,10 +154,6 @@ class AppDelegate: NSObject,
toggleSecureInput(self)
}
// Hook up updater menu
menuCheckForUpdates?.target = updaterController
menuCheckForUpdates?.action = #selector(SPUStandardUpdaterController.checkForUpdates(_:))
// Initial config loading
ghosttyConfigDidChange(config: ghostty.config)
@@ -374,6 +370,7 @@ class AppDelegate: NSObject,
private func syncMenuShortcuts(_ config: Ghostty.Config) {
guard ghostty.readiness == .ready else { return }
syncMenuShortcut(config, action: "check_for_updates", menuItem: self.menuCheckForUpdates)
syncMenuShortcut(config, action: "open_config", menuItem: self.menuOpenConfig)
syncMenuShortcut(config, action: "reload_config", menuItem: self.menuReloadConfig)
syncMenuShortcut(config, action: "quit", menuItem: self.menuQuit)
@@ -791,6 +788,10 @@ class AppDelegate: NSObject,
ghostty.reloadConfig()
}
@IBAction func checkForUpdates(_ sender: Any?) {
updaterController.checkForUpdates(sender)
}
@IBAction func newWindow(_ sender: Any?) {
terminalManager.newWindow()

View File

@@ -76,6 +76,9 @@
</menuItem>
<menuItem title="Check for Updates..." id="GEA-5y-yzH">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="checkForUpdates:" target="bbz-4X-AYv" id="z2n-lC-48f"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">

View File

@@ -550,6 +550,9 @@ extension Ghostty {
case GHOSTTY_ACTION_RING_BELL:
ringBell(app, target: target)
case GHOSTTY_ACTION_CHECK_FOR_UPDATES:
checkForUpdates(app)
case GHOSTTY_ACTION_CLOSE_ALL_WINDOWS:
fallthrough
case GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW:
@@ -588,6 +591,14 @@ extension Ghostty {
#endif
}
private static func checkForUpdates(
_ app: ghostty_app_t,
) {
if let appDelegate = NSApplication.shared.delegate as? AppDelegate {
appDelegate.checkForUpdates(nil)
}
}
private static func newWindow(_ app: ghostty_app_t, target: ghostty_target_s) {
switch (target.tag) {
case GHOSTTY_TARGET_APP:

View File

@@ -444,6 +444,7 @@ pub fn performAction(
.close_all_windows => _ = try rt_app.performAction(.app, .close_all_windows, {}),
.toggle_quick_terminal => _ = try rt_app.performAction(.app, .toggle_quick_terminal, {}),
.toggle_visibility => _ = try rt_app.performAction(.app, .toggle_visibility, {}),
.check_for_updates => _ = try rt_app.performAction(.app, .check_for_updates, {}),
}
}

View File

@@ -255,6 +255,8 @@ pub const Action = union(Key) {
/// it needs to ring the bell. This is usually a sound or visual effect.
ring_bell,
check_for_updates,
/// Sync with: ghostty_action_tag_e
pub const Key = enum(c_int) {
quit,
@@ -301,6 +303,7 @@ pub const Action = union(Key) {
config_change,
close_window,
ring_bell,
check_for_updates,
};
/// Sync with: ghostty_action_u

View File

@@ -509,6 +509,11 @@ pub const Action = union(enum) {
/// This currently only works on macOS.
toggle_visibility,
/// Check for updates.
///
/// This currently only works on macOS.
check_for_updates,
/// Quit ghostty.
quit,
@@ -791,6 +796,7 @@ pub const Action = union(enum) {
.quit,
.toggle_quick_terminal,
.toggle_visibility,
.check_for_updates,
=> .app,
// These are app but can be special-cased in a surface context.

View File

@@ -364,6 +364,12 @@ fn actionCommands(action: Action.Key) []const Command {
.description = "Toggle secure input mode.",
}},
.check_for_updates => comptime &.{.{
.action = .check_for_updates,
.title = "Check for Updates",
.description = "Check for updates to the application.",
}},
.quit => comptime &.{.{
.action = .quit,
.title = "Quit",