@@ -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
0 commit comments