From 82b35d9dbcbaa43317b9826b7ca87f8799a1e87a Mon Sep 17 00:00:00 2001 From: Fingercomp Date: Thu, 23 Jan 2025 02:08:01 +0300 Subject: [PATCH] Load workspaces in the main thread Fixes #147. --- src/main/scala/ocelot/desktop/OcelotDesktop.scala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/scala/ocelot/desktop/OcelotDesktop.scala b/src/main/scala/ocelot/desktop/OcelotDesktop.scala index 255f077..0bb9a6f 100644 --- a/src/main/scala/ocelot/desktop/OcelotDesktop.scala +++ b/src/main/scala/ocelot/desktop/OcelotDesktop.scala @@ -404,13 +404,16 @@ object OcelotDesktop val selectedFile = Option.when(chooser.showDialog(null, null) == JFileChooser.APPROVE_OPTION)(chooser.getSelectedFile) - val result = f(selectedFile) - - result match { - case f @ Failure(_) => showFailureMessage(f) - case Success(_) => - } + // users of [showFileChooserDialog] expect that the continuation is run on the main thread. + // let's meet this expectation. + UiHandler.UiThreadTasks.add(() => { + val result = f(selectedFile) + result match { + case f@Failure(_) => showFailureMessage(f) + case Success(_) => + } + }) }).start() }