Skip to content

Commit 0a0f660

Browse files
committed
Get backends to compile and update GTK backends
1 parent eac5ec3 commit 0a0f660

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class AppKitBackend: AppBackend {
4343
NSApplication.shared.delegate = appDelegate
4444
}
4545

46-
public func runMainLoop(_ callback: @escaping () -> Void) {
46+
public func runMainLoop(_ callback: @escaping @MainActor () -> Void) {
4747
callback()
4848
NSApplication.shared.activate(ignoringOtherApps: true)
4949
NSApplication.shared.run()
@@ -239,7 +239,7 @@ public final class AppKitBackend: AppBackend {
239239
NSApplication.shared.helpMenu = helpMenu
240240
}
241241

242-
public func runInMainThread(action: @escaping () -> Void) {
242+
public func runInMainThread(action: @escaping @MainActor () -> Void) {
243243
DispatchQueue.main.async {
244244
action()
245245
}

Sources/Gtk3Backend/Gtk3Backend.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public final class Gtk3Backend: AppBackend {
6464
gtkApp.registerSession = true
6565
}
6666

67-
public func runMainLoop(_ callback: @escaping () -> Void) {
67+
public func runMainLoop(_ callback: @escaping @MainActor () -> Void) {
6868
gtkApp.run { window in
6969
self.precreatedWindow = window
7070
callback()
@@ -340,14 +340,14 @@ public final class Gtk3Backend: AppBackend {
340340
}
341341

342342
class ThreadActionContext {
343-
var action: () -> Void
343+
var action: @MainActor () -> Void
344344

345-
init(action: @escaping () -> Void) {
345+
init(action: @escaping @MainActor () -> Void) {
346346
self.action = action
347347
}
348348
}
349349

350-
public func runInMainThread(action: @escaping () -> Void) {
350+
public func runInMainThread(action: @escaping @MainActor () -> Void) {
351351
let action = ThreadActionContext(action: action)
352352
g_idle_add_full(
353353
0,
@@ -356,9 +356,11 @@ public final class Gtk3Backend: AppBackend {
356356
fatalError("Gtk action callback called without context")
357357
}
358358

359-
let action = Unmanaged<ThreadActionContext>.fromOpaque(context)
360-
.takeUnretainedValue()
361-
action.action()
359+
MainActor.assumeIsolated {
360+
let action = Unmanaged<ThreadActionContext>.fromOpaque(context)
361+
.takeUnretainedValue()
362+
action.action()
363+
}
362364

363365
return 0
364366
},
@@ -380,9 +382,11 @@ public final class Gtk3Backend: AppBackend {
380382
fatalError("Gtk action callback called without context")
381383
}
382384

383-
let action = Unmanaged<ThreadActionContext>.fromOpaque(context)
384-
.takeUnretainedValue()
385-
action.action()
385+
MainActor.assumeIsolated {
386+
let action = Unmanaged<ThreadActionContext>.fromOpaque(context)
387+
.takeUnretainedValue()
388+
action.action()
389+
}
386390

387391
// Cancel the recurring timeout after one iteration
388392
return 0

Sources/GtkBackend/GtkBackend.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public final class GtkBackend: AppBackend {
6565

6666
var globalCSSProvider: CSSProvider?
6767

68-
public func runMainLoop(_ callback: @escaping () -> Void) {
68+
public func runMainLoop(_ callback: @escaping @MainActor () -> Void) {
6969
gtkApp.run { window in
7070
self.precreatedWindow = window
7171
callback()
@@ -315,14 +315,14 @@ public final class GtkBackend: AppBackend {
315315
}
316316

317317
class ThreadActionContext {
318-
var action: () -> Void
318+
var action: @MainActor () -> Void
319319

320-
init(action: @escaping () -> Void) {
320+
init(action: @escaping @MainActor () -> Void) {
321321
self.action = action
322322
}
323323
}
324324

325-
public func runInMainThread(action: @escaping () -> Void) {
325+
public func runInMainThread(action: @escaping @MainActor () -> Void) {
326326
let action = ThreadActionContext(action: action)
327327
g_idle_add_full(
328328
0,
@@ -331,9 +331,11 @@ public final class GtkBackend: AppBackend {
331331
fatalError("Gtk action callback called without context")
332332
}
333333

334-
let action = Unmanaged<ThreadActionContext>.fromOpaque(context)
335-
.takeUnretainedValue()
336-
action.action()
334+
MainActor.assumeIsolated {
335+
let action = Unmanaged<ThreadActionContext>.fromOpaque(context)
336+
.takeUnretainedValue()
337+
action.action()
338+
}
337339

338340
return 0
339341
},
@@ -355,9 +357,11 @@ public final class GtkBackend: AppBackend {
355357
fatalError("Gtk action callback called without context")
356358
}
357359

358-
let action = Unmanaged<ThreadActionContext>.fromOpaque(context)
359-
.takeUnretainedValue()
360-
action.action()
360+
MainActor.assumeIsolated {
361+
let action = Unmanaged<ThreadActionContext>.fromOpaque(context)
362+
.takeUnretainedValue()
363+
action.action()
364+
}
361365

362366
// Cancel the recurring timeout after one iteration
363367
return 0

Sources/UIKitBackend/UIKitBackend.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public final class UIKitBackend: AppBackend {
3737
}
3838

3939
public func runMainLoop(
40-
_ callback: @escaping () -> Void
40+
_ callback: @escaping @MainActor () -> Void
4141
) {
4242
Self.onReceiveURL = { url in
4343
Self.queuedURLs.append(url)
@@ -107,7 +107,7 @@ public final class UIKitBackend: AppBackend {
107107
// TODO: Notify when window scale factor changes
108108
}
109109

110-
public func runInMainThread(action: @escaping () -> Void) {
110+
public func runInMainThread(action: @escaping @MainActor () -> Void) {
111111
DispatchQueue.main.async(execute: action)
112112
}
113113

Sources/WinUIBackend/WinUIBackend.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public final class WinUIBackend: AppBackend {
7878
}
7979
}
8080

81-
public func runMainLoop(_ callback: @escaping () -> Void) {
81+
public func runMainLoop(_ callback: @escaping @MainActor () -> Void) {
8282
do {
8383
try Self.attachToParentConsole()
8484
} catch {
@@ -237,7 +237,7 @@ public final class WinUIBackend: AppBackend {
237237
_ = UWP.Launcher.launchUriAsync(WindowsFoundation.Uri(url.absoluteString))
238238
}
239239

240-
public func runInMainThread(action: @escaping () -> Void) {
240+
public func runInMainThread(action: @escaping @MainActor () -> Void) {
241241
_ = try! internalState.dispatcherQueue!.tryEnqueue(.normal) {
242242
action()
243243
}

0 commit comments

Comments
 (0)