macOS: fix swift warnings (#13762)

Rework for #12764
This commit is contained in:
Mitchell Hashimoto
2026-08-12 08:09:56 -07:00
committed by GitHub
6 changed files with 24 additions and 28 deletions

View File

@@ -24,10 +24,10 @@ struct UpdatePill: View {
.onChange(of: model.state) { newState in
resetTask?.cancel()
if case .notFound(let notFound) = newState {
resetTask = Task { [weak model] in
resetTask = Task {
try? await Task.sleep(for: .seconds(5))
guard !Task.isCancelled, case .notFound? = model?.state else { return }
model?.state = .idle
guard !Task.isCancelled, case .notFound = model.state else { return }
model.state = .idle
notFound.acknowledgement()
}
} else {

View File

@@ -6,7 +6,9 @@ extension Ghostty {
///
/// Wraps a `ghostty_inspector_t`
final class Inspector: Sendable {
private let inspector: ghostty_inspector_t
/// A inspector is sendable because it is just a reference type. Using the inspector in parameters
/// may be unsafe but the value itself is safe to send across threads.
nonisolated(unsafe) private let inspector: ghostty_inspector_t
/// Read the underlying C value for this inspector. This is unsafe because the value will be
/// freed when the Inspector class is deinitialized.

View File

@@ -10,7 +10,9 @@ extension Ghostty {
///
/// Wraps a `ghostty_surface_t`
final class Surface: Sendable {
private let surface: ghostty_surface_t
/// A surface is sendable because it is just a reference type. Using the surface in parameters
/// may be unsafe but the value itself is safe to send across threads.
nonisolated(unsafe) private let surface: ghostty_surface_t
/// Read the underlying C value for this surface. This is unsafe because the value will be
/// freed when the Surface class is deinitialized.

View File

@@ -4,13 +4,6 @@ import GhosttyKit
// MARK: C Extensions
/// A command is fully self-contained so it is Sendable.
extension ghostty_command_s: @unchecked @retroactive Sendable {}
/// A surface is sendable because it is just a reference type. Using the surface in parameters
/// may be unsafe but the value itself is safe to send across threads.
extension ghostty_surface_t: @unchecked @retroactive Sendable {}
extension Ghostty {
// The user notification category identifier
static let userNotificationCategory = "com.mitchellh.ghostty.userNotification"

View File

@@ -138,9 +138,9 @@ extension Ghostty.OSSurfaceView {
init(
from startSearch: Ghostty.Action.StartSearch,
pasteboard: NSPasteboard = NSPasteboard.find
pasteboard: NSPasteboard? = nil
) {
self.pasteboard = pasteboard
self.pasteboard = pasteboard ?? .find
if let needle = startSearch.needle, !needle.isEmpty {
setNeedle(needle)
writePasteboardNeedle()

View File

@@ -1787,26 +1787,25 @@ extension Ghostty {
// Note the callback may be executed on a background thread as documented
// so we need @MainActor since we're reading/writing view state.
UNUserNotificationCenter.current().add(request) { @MainActor error in
if let error = error {
AppDelegate.logger.error("Error scheduling user notification: \(error, privacy: .public)")
return
}
Task { @MainActor in
do {
try await UNUserNotificationCenter.current().add(request)
// We need to keep track of this notification so we can remove it
// under certain circumstances
self.notificationIdentifiers.insert(uuid)
// We need to keep track of this notification so we can remove it
// under certain circumstances
notificationIdentifiers.insert(uuid)
// If we're focused then we schedule to remove the notification
// after a few seconds. If we gain focus we automatically remove it
// in focusDidChange.
if self.focused {
Task { @MainActor [weak self] in
// If we're focused then we schedule to remove the notification
// after a few seconds. If we gain focus we automatically remove it
// in focusDidChange.
if self.focused {
try await Task.sleep(for: .seconds(3))
self?.notificationIdentifiers.remove(uuid)
notificationIdentifiers.remove(uuid)
UNUserNotificationCenter.current()
.removeDeliveredNotifications(withIdentifiers: [uuid])
}
} catch {
AppDelegate.logger.error("Error scheduling user notification: \(error, privacy: .public)")
}
}
}