Skip to content

Commit 85d5993

Browse files
committed
Add @mainactor and Sendable annotations
1 parent 51ab079 commit 85d5993

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+199
-110
lines changed

Sources/SwiftCrossUI/App.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22

33
/// An application.
4+
@MainActor
45
public protocol App {
56
/// The backend used to render the app.
67
associatedtype Backend: AppBackend

Sources/SwiftCrossUI/Backend/AppBackend.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import Foundation
4040
/// code between the `create` and `update` methods of the various widgets
4141
/// (since the `update` method is always called between calling `create`
4242
/// and actually displaying the widget anyway).
43+
@MainActor
4344
public protocol AppBackend {
4445
associatedtype Window
4546
associatedtype Widget
@@ -118,7 +119,7 @@ public protocol AppBackend {
118119
/// setup function is passed to `Gtk` as a callback to run once the main
119120
/// run loop starts.
120121
func runMainLoop(
121-
_ callback: @escaping () -> Void
122+
_ callback: @escaping @MainActor () -> Void
122123
)
123124
/// Creates a new window. For some backends it may make sense for this
124125
/// method to return the application's root window the first time its
@@ -172,7 +173,7 @@ public protocol AppBackend {
172173
/// Runs an action in the app's main thread if required to perform UI updates
173174
/// by the backend. Predominantly used by ``Publisher`` to publish changes to a thread
174175
/// compatible with dispatching UI updates. Can be synchronous or asynchronous (for now).
175-
func runInMainThread(action: @escaping () -> Void)
176+
nonisolated func runInMainThread(action: @escaping @MainActor () -> Void)
176177

177178
/// Computes the root environment for an app (e.g. by checking the system's current
178179
/// theme). May fall back on the provided defaults where reasonable.

Sources/SwiftCrossUI/Backend/ResolvedMenu.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct ResolvedMenu {
1616
/// A menu item.
1717
public enum Item {
1818
/// A button. A `nil` action means that the button is disabled.
19-
case button(_ label: String, _ action: (() -> Void)?)
19+
case button(_ label: String, _ action: (@MainActor () -> Void)?)
2020
/// A named submenu.
2121
case submenu(Submenu)
2222
}

Sources/SwiftCrossUI/Environment/Actions/OpenURLAction.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
/// Opens a URL with the default application. May present an application picker
44
/// if multiple applications are registered for the given URL protocol.
55
public struct OpenURLAction {
6-
let action: (URL) -> Void
6+
let action: @MainActor (URL) -> Void
77

88
init<Backend: AppBackend>(backend: Backend) {
99
action = { url in
@@ -15,6 +15,7 @@ public struct OpenURLAction {
1515
}
1616
}
1717

18+
@MainActor
1819
public func callAsFunction(_ url: URL) {
1920
action(url)
2021
}

Sources/SwiftCrossUI/Environment/Actions/RevealFileAction.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22

33
/// Reveals a file in the system's file manager. This opens
44
/// the file's enclosing directory and highlighting the file.
5+
@MainActor
56
public struct RevealFileAction {
67
let action: (URL) -> Void
78

Sources/SwiftCrossUI/Environment/EnvironmentValues.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct EnvironmentValues {
3333

3434
/// Called when a text field gets submitted (usually due to the user
3535
/// pressing Enter/Return).
36-
public var onSubmit: (() -> Void)?
36+
public var onSubmit: (@MainActor () -> Void)?
3737

3838
/// The scale factor of the current window.
3939
public var windowScaleFactor: Double
@@ -55,7 +55,7 @@ public struct EnvironmentValues {
5555
/// change and end up changing size. Each view graph node sets its own
5656
/// handler when passing the environment on to its children, setting up
5757
/// a bottom-up update chain up which resize events can propagate.
58-
var onResize: (_ newSize: ViewSize) -> Void
58+
var onResize: @MainActor (_ newSize: ViewSize) -> Void
5959

6060
/// The style of list to use.
6161
package var listStyle: ListStyle
@@ -74,6 +74,7 @@ public struct EnvironmentValues {
7474

7575
/// Brings the current window forward, not guaranteed to always bring
7676
/// the window to the top (due to focus stealing prevention).
77+
@MainActor
7778
func bringWindowForward() {
7879
func activate<Backend: AppBackend>(with backend: Backend) {
7980
backend.activate(window: window as! Backend.Window)
@@ -140,6 +141,7 @@ public struct EnvironmentValues {
140141
///
141142
/// `nil` on platforms that don't support revealing files, e.g.
142143
/// iOS.
144+
@MainActor
143145
public var revealFile: RevealFileAction? {
144146
return RevealFileAction(
145147
backend: backend

Sources/SwiftCrossUI/Layout/LayoutSystem.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public enum LayoutSystem {
7575
/// if all of its children have it set to true. This allows views such as
7676
/// ``Group`` to avoid changing stack layout participation (since ``Group``
7777
/// is meant to appear completely invisible to the layout system).
78+
@MainActor
7879
public static func updateStackLayout<Backend: AppBackend>(
7980
container: Backend.Widget,
8081
children: [LayoutableChild],

Sources/SwiftCrossUI/Scenes/SceneGraphNode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
///
44
/// Treat scenes as basic data structures that simply encode the structure of the app;
55
/// the actual rendering and logic is handled by the node.
6+
@MainActor
67
public protocol SceneGraphNode: AnyObject {
78
/// The type of scene managed by this node.
89
associatedtype NodeScene: Scene where NodeScene.Node == Self

Sources/SwiftCrossUI/Values/Alignment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// The 2d alignment of a view.
2-
public struct Alignment: Hashable {
2+
public struct Alignment: Hashable, Sendable {
33
/// Centered in both dimensions.
44
public static let center = Self(horizontal: .center, vertical: .center)
55

Sources/SwiftCrossUI/Values/Axis.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// An axis in a 2D coordinate system.
2-
public enum Axis {
2+
public enum Axis: Sendable {
33
/// The horizontal axis.
44
case horizontal
55
/// The vertical axis.

0 commit comments

Comments
 (0)