Skip to content

Commit fdd4ec2

Browse files
committed
LSP: Initialize platform before reader thread
Closes slint-ui#10274
1 parent 5e8734f commit fdd4ec2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tools/lsp/preview/connector/native.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,29 @@ impl Default for RemoteControlledPreviewToLsp {
196196
}
197197

198198
impl RemoteControlledPreviewToLsp {
199-
/// Creates a RemoteConfrolledPreviewToLsp connector.
199+
/// Creates a RemoteControlledPreviewToLsp connector.
200200
///
201201
/// This means the applications lifetime is bound to the lifetime of the
202202
/// application's STDIN: We quit as soon as that gets fishy or closed.
203203
///
204204
/// It also means we do not need to join the reader thread: The OS will clean
205205
/// that one up for us anyway.
206+
///
207+
/// Note: If the Slint backend has not been set yet, this will set a backend with the
208+
/// default Slint BackendSelector.
206209
pub fn new() -> Self {
207210
let _ = Self::process_input();
208211
Self {}
209212
}
210213

211214
fn process_input() -> std::thread::JoinHandle<std::result::Result<(), String>> {
215+
// Ensure the backend is set up before the reader thread starts. This fixes
216+
// bug #10274 on macOS where a race condition was causing the reader thread to already
217+
// process messages before the event loop was running.
218+
//
219+
// Use .ok() to ignore any errors, as the backend might already be set by the user and that's fine.
220+
slint::BackendSelector::new().select().ok();
221+
212222
std::thread::spawn(move || -> Result<(), String> {
213223
let reader = std::io::BufReader::new(std::io::stdin().lock());
214224
for line in reader.lines() {

0 commit comments

Comments
 (0)