Skip to content

Commit 933657a

Browse files
committed
Fix UI race condition
1 parent 217aed7 commit 933657a

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

src/PanelUI.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,17 @@ export default function PanelUI({
131131
function start() {
132132
stop();
133133
lang = getLanguage(dropdown_ui_lang.selected_item.string);
134-
handler_id_xml = code_view_xml.connect("changed", () =>
135-
onXML(code_view_xml.buffer.text),
136-
);
134+
handler_id_xml = code_view_xml.connect("changed", () => {
135+
if (lang.id !== "xml") return;
136+
onXML(code_view_xml.buffer.text);
137+
});
137138
handler_id_blueprint = code_view_blueprint.connect("changed", onBlueprint);
138139
blueprint.lspc.connect(
139140
"notification::textDocument/x-blueprintcompiler/publishCompiled",
140-
(_self, { xml }) => onXML(xml),
141+
(_self, { xml }) => {
142+
if (lang.id !== "blueprint") return;
143+
onXML(xml);
144+
},
141145
);
142146
}
143147

src/Previewer/External.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function Previewer({ output, builder, onWindowChange }) {
3434
builder.get_object("button_screenshot").visible = false;
3535
}
3636

37-
function open() {
37+
async function open() {
3838
updateColorScheme();
3939
stack.set_visible_child_name("close_window");
4040
try {
@@ -47,7 +47,7 @@ export default function Previewer({ output, builder, onWindowChange }) {
4747
}
4848
}
4949

50-
function close() {
50+
async function close() {
5151
try {
5252
dbus_proxy.CloseWindowSync();
5353
} catch (err) {

src/Previewer/Internal.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import GObject from "gi://GObject";
99
import Adw from "gi://Adw";
1010
import Gio from "gi://Gio";
1111

12+
import { once } from "../../troll/src/util.js";
13+
1214
import { portal } from "../util.js";
1315

16+
const { addSignalMethods } = imports.signals;
17+
1418
export default function Internal({
1519
onWindowChange,
1620
output,
@@ -20,6 +24,9 @@ export default function Internal({
2024
dropdown_preview_align,
2125
panel_ui,
2226
}) {
27+
const bus = {};
28+
addSignalMethods(bus);
29+
2330
const stack = builder.get_object("stack_preview");
2431

2532
let css_provider = null;
@@ -36,18 +43,18 @@ export default function Internal({
3643
if (!object_root) {
3744
try {
3845
await panel_ui.update();
46+
await once(bus, "object_root", { timeout: 5000 });
3947
} catch (err) {
4048
logError(err);
4149
return;
4250
}
43-
if (!object_root) return;
4451
}
4552

4653
object_root.present_with_time(Gdk.CURRENT_TIME);
4754
onWindowChange(true);
4855
}
4956

50-
function close() {
57+
async function close() {
5158
object_root?.close();
5259
}
5360

@@ -99,6 +106,7 @@ export default function Internal({
99106
object_root = null;
100107
onWindowChange(false);
101108
});
109+
bus.emit("object_root");
102110
}
103111

104112
function updateBuilderRoot(object_preview) {

src/Previewer/Previewer.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,22 @@ export default function Previewer({
234234
current?.closeInspector();
235235
current = previewer;
236236

237-
handler_id_button_open = button_open.connect("clicked", () => {
238-
current.open();
239-
stack.set_visible_child_name("close_window");
237+
handler_id_button_open = button_open.connect("clicked", async () => {
238+
try {
239+
await current.open();
240+
stack.set_visible_child_name("close_window");
241+
} catch (err) {
242+
logError(err);
243+
}
240244
});
241245

242-
handler_id_button_close = button_close.connect("clicked", () => {
243-
current.close();
244-
stack.set_visible_child_name("open_window");
246+
handler_id_button_close = button_close.connect("clicked", async () => {
247+
try {
248+
await current.close();
249+
stack.set_visible_child_name("open_window");
250+
} catch (err) {
251+
logError(err);
252+
}
245253
});
246254

247255
current.start();

0 commit comments

Comments
 (0)