Skip to content

Commit

Permalink
Fix UI race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Jan 22, 2023
1 parent 217aed7 commit 933657a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/PanelUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ export default function PanelUI({
function start() {
stop();
lang = getLanguage(dropdown_ui_lang.selected_item.string);
handler_id_xml = code_view_xml.connect("changed", () =>
onXML(code_view_xml.buffer.text),
);
handler_id_xml = code_view_xml.connect("changed", () => {
if (lang.id !== "xml") return;
onXML(code_view_xml.buffer.text);
});
handler_id_blueprint = code_view_blueprint.connect("changed", onBlueprint);
blueprint.lspc.connect(
"notification::textDocument/x-blueprintcompiler/publishCompiled",
(_self, { xml }) => onXML(xml),
(_self, { xml }) => {
if (lang.id !== "blueprint") return;
onXML(xml);
},
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Previewer/External.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function Previewer({ output, builder, onWindowChange }) {
builder.get_object("button_screenshot").visible = false;
}

function open() {
async function open() {
updateColorScheme();
stack.set_visible_child_name("close_window");
try {
Expand All @@ -47,7 +47,7 @@ export default function Previewer({ output, builder, onWindowChange }) {
}
}

function close() {
async function close() {
try {
dbus_proxy.CloseWindowSync();
} catch (err) {
Expand Down
12 changes: 10 additions & 2 deletions src/Previewer/Internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import GObject from "gi://GObject";
import Adw from "gi://Adw";
import Gio from "gi://Gio";

import { once } from "../../troll/src/util.js";

import { portal } from "../util.js";

const { addSignalMethods } = imports.signals;

export default function Internal({
onWindowChange,
output,
Expand All @@ -20,6 +24,9 @@ export default function Internal({
dropdown_preview_align,
panel_ui,
}) {
const bus = {};
addSignalMethods(bus);

const stack = builder.get_object("stack_preview");

let css_provider = null;
Expand All @@ -36,18 +43,18 @@ export default function Internal({
if (!object_root) {
try {
await panel_ui.update();
await once(bus, "object_root", { timeout: 5000 });
} catch (err) {
logError(err);
return;
}
if (!object_root) return;
}

object_root.present_with_time(Gdk.CURRENT_TIME);
onWindowChange(true);
}

function close() {
async function close() {
object_root?.close();
}

Expand Down Expand Up @@ -99,6 +106,7 @@ export default function Internal({
object_root = null;
onWindowChange(false);
});
bus.emit("object_root");
}

function updateBuilderRoot(object_preview) {
Expand Down
20 changes: 14 additions & 6 deletions src/Previewer/Previewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,22 @@ export default function Previewer({
current?.closeInspector();
current = previewer;

handler_id_button_open = button_open.connect("clicked", () => {
current.open();
stack.set_visible_child_name("close_window");
handler_id_button_open = button_open.connect("clicked", async () => {
try {
await current.open();
stack.set_visible_child_name("close_window");
} catch (err) {
logError(err);
}
});

handler_id_button_close = button_close.connect("clicked", () => {
current.close();
stack.set_visible_child_name("open_window");
handler_id_button_close = button_close.connect("clicked", async () => {
try {
await current.close();
stack.set_visible_child_name("open_window");
} catch (err) {
logError(err);
}
});

current.start();
Expand Down

0 comments on commit 933657a

Please sign in to comment.