From 56a03c5689681cb8778acc78c8ab60ad208a510d Mon Sep 17 00:00:00 2001 From: hanna Date: Fri, 19 Jul 2024 10:04:48 -0700 Subject: [PATCH] refactor: attempted autoupdate configuration --- include/ghostty.h | 1 + macos/Sources/App/macOS/AppDelegate.swift | 6 ++++++ macos/Sources/Ghostty/Ghostty.Config.swift | 11 +++++++++++ src/config/Config.zig | 14 ++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/include/ghostty.h b/include/ghostty.h index d81e3d19a..d53cce21f 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -12,6 +12,7 @@ extern "C" { #endif +#include #include #include diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index 8b6b064a9..7fd30e5c6 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -109,6 +109,12 @@ class AppDelegate: NSObject, // Initial config loading configDidReload(ghostty) + updaterController.updater.updateCheckInterval = 60 + updaterController.updater.automaticallyChecksForUpdates = + ghostty.config.autoUpdates == "check" || ghostty.config.autoUpdates == "download" + updaterController.updater.automaticallyDownloadsUpdates = + ghostty.config.autoUpdates == "download" + // Register our service provider. This must happen after everything is initialized. NSApp.servicesProvider = ServiceProvider() diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index ab583e956..5edaabdb2 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -331,5 +331,16 @@ extension Ghostty { let newColor = isLightBackground ? backgroundColor.darken(by: 0.08) : backgroundColor.darken(by: 0.4) return Color(newColor) } + + var autoUpdates: String { + let defaultValue = "off" + guard let config = self.config else { return defaultValue } + + let key = "auto-updates" + var value: UnsafePointer? = nil + guard ghostty_config_get(config, &value, key, UInt(key.count)) else { return defaultValue } + guard let pointer = value else { return defaultValue } + return String(cString: pointer) + } } } diff --git a/src/config/Config.zig b/src/config/Config.zig index 6f780bb33..2250d23c6 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1161,6 +1161,13 @@ term: []const u8 = "xterm-ghostty", /// running. Defaults to an empty string if not set. @"enquiry-response": []const u8 = "", +/// This controls the automatic update functionality on macOS by setting the +/// properties on the Squirrel automatic update component. By default this is +/// set to "off" which doesn't do anything. The "check" option will automatically +/// check for updates but will NOT download them, while as the "download" option +/// will both check AND download updates automatically for the user. +@"auto-updates": AutoUpdates = .off, + /// This is set by the CLI parser for deinit. _arena: ?ArenaAllocator = null, @@ -3640,3 +3647,10 @@ pub const LinuxCgroup = enum { always, @"single-instance", }; + +/// See auto-updates +pub const AutoUpdates = enum { + check, + download, + off, +};