Skip to content

Commit

Permalink
Update backends to not run actions on main thread on non Apple platfo…
Browse files Browse the repository at this point in the history
…rms; Fix typo in QtBackend
  • Loading branch information
sirlan-ff00ff committed Oct 19, 2023
1 parent 501599f commit 5191fb1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 6 additions & 2 deletions Sources/CursesBackend/CursesBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ public struct CursesBackend: AppBackend {
}

public func runInMainThread(action: @escaping () -> Void) {
DispatchQueue.main.async {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
DispatchQueue.main.async {
action()
}
#else
action()
}
#endif
}

public func show(_ widget: Widget) {
Expand Down
8 changes: 6 additions & 2 deletions Sources/LVGLBackend/LVGLBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ public struct LVGLBackend: AppBackend {
}

public func runInMainThread(action: @escaping () -> Void) {
DispatchQueue.main.async {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
DispatchQueue.main.async {
action()
}
#else
action()
}
#endif
}

public func show(_ widget: Widget) {}
Expand Down
10 changes: 7 additions & 3 deletions Sources/QtBackend/QtBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct QtBackend: AppBackend {

private class InternalState {
var buttonClickActions: [ObjectIdentifier: () -> Void] = [:]
var sliderChangeAction: [ObjectIdentifier: (Double) -> Void] = [:]
var sliderChangeActions: [ObjectIdentifier: (Double) -> Void] = [:]
var paddingContainerChildren: [ObjectIdentifier: Widget] = [:]
}

Expand Down Expand Up @@ -39,9 +39,13 @@ public struct QtBackend: AppBackend {
}

public func runInMainThread(action: @escaping () -> Void) {
DispatchQueue.main.async {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
DispatchQueue.main.async {
action()
}
#else
action()
}
#endif
}

public func show(_ widget: Widget) {
Expand Down

0 comments on commit 5191fb1

Please sign in to comment.