TDKCandidates // Make CandidatePool into an ObservableObject.

This commit is contained in:
ShikiSuen 2023-06-05 00:07:17 +08:00
parent 6ed08e5355
commit fe78a5c292
3 changed files with 15 additions and 1 deletions

View File

@ -142,6 +142,14 @@ public extension CandidatePool {
case vertical
}
func update() {
if #available(macOS 10.15, *) {
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
///
/// - Parameter isBackward:
/// - Returns:
@ -418,3 +426,8 @@ private extension CandidatePool {
}
}
}
// MARK: - Turn CandidatePool into an ObservableObject.
@available(macOS 10.15, *)
extension CandidatePool: ObservableObject {}

View File

@ -117,6 +117,7 @@ public class CtlCandidateTDK: CtlCandidate, NSWindowDelegate {
Self.currentView = theViewCocoa
break viewCheck
}
Self.thePool.update()
Self.currentView = NSHostingView(rootView: theView)
} else {
Self.currentView = theViewCocoa

View File

@ -17,7 +17,7 @@ import SwiftUIBackports
public struct VwrCandidateTDK: View {
public weak var controller: CtlCandidateTDK?
@Environment(\.colorScheme) var colorScheme
@State public var thePool: CandidatePool
@Backport.StateObject public var thePool: CandidatePool
@State public var forceCatalinaCompatibility: Bool = false
var tooltip: String { thePool.tooltip }
var reverseLookupResult: [String] { thePool.reverseLookupResult }