Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

previewer: Implement start/stop behaviour #849

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/Previewer/DBusPreviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ async function startProcess(type) {
[executable_name, server.get_client_address()],
Gio.SubprocessFlags.NONE,
);

current_sub_process.wait_async(null).then(() => {
dbus_previewer.onStop?.();
});

current_type = type;

const connection = await new Promise((resolve) => {
Expand Down Expand Up @@ -83,20 +88,22 @@ async function startProcess(type) {
null,
);

proxy.connectSignal("CssParserError", (_proxy, _name_owner, ...args) => {
proxy.connectSignal("CssParserError", (_self, _name_owner, ...args) => {
dbus_previewer.onCssParserError?.(...args);
});

proxy.connectSignal("WindowOpen", (_proxy, _name_owner, ...args) => {
dbus_previewer.onWindowOpen?.(...args);
proxy.connectSignal("WindowOpen", (_self, _name_owner, [open]) => {
if (!open) {
dbus_previewer.stop().catch(console.error);
}
});

return proxy;
}

const dbus_previewer = {
onCssParserError: null, // set in External.js
onWindowOpen: null, // set in External.js
onStop: null,
async getProxy(type) {
if (current_type !== type) {
await this.stop();
Expand Down
13 changes: 3 additions & 10 deletions src/Previewer/External.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import Adw from "gi://Adw";
import dbus_previewer from "./DBusPreviewer.js";

export default function External({ output, builder, onWindowChange }) {
export default function External({ output, builder, onStop }) {
const stack = builder.get_object("stack_preview");
let dbus_proxy;

dbus_previewer.onWindowOpen = ([open]) => {
onWindowChange(open);
};
dbus_previewer.onStop = onStop;

dbus_previewer.onCssParserError = (error) => {
builder
Expand Down Expand Up @@ -46,15 +44,10 @@ export default function External({ output, builder, onWindowChange }) {
console.debug(err);
return;
}
stack.set_visible_child_name("open_window");
}

function stop() {
close()
.then(() => {
return dbus_previewer.stop();
})
.catch(console.error);
close().then(() => dbus_previewer.stop());
}

async function updateXML({ xml, target_id, original_id }) {
Expand Down
9 changes: 3 additions & 6 deletions src/Previewer/Internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function Internal({
dropdown_preview_align,
panel_ui,
session,
onStop,
}) {
const inline_css_scope_target = output.get_parent();
inline_css_scope_target.name = `workbench_output-${session.id}`;
Expand Down Expand Up @@ -51,12 +52,8 @@ export default function Internal({
onWindowChange(true);
}

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

function stop() {
close();
object_root?.close();
if (css_provider) {
Gtk.StyleContext.remove_provider_for_display(
output.get_display(),
Expand All @@ -66,6 +63,7 @@ export default function Internal({
}
object_root?.destroy();
object_root = null;
onStop();
}

function preview(object) {
Expand Down Expand Up @@ -230,7 +228,6 @@ export default function Internal({
return {
async start(_language) {},
open,
close,
stop,
updateXML,
updateCSS,
Expand Down
88 changes: 28 additions & 60 deletions src/Previewer/Previewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ export default function Previewer({
makeDropdownFlat(dropdown_preview_align);

const internal = Internal({
onWindowChange(open) {
if (current !== internal) return;
if (open) {
stack.set_visible_child_name("close_window");
} else {
stack.set_visible_child_name("open_window");
}
onStop() {
console.log("stopping ouin ouin internal");
stack_start_stop.visible_child = button_run;
update(true);
},
output,
builder,
Expand All @@ -67,15 +64,16 @@ export default function Previewer({
panel_ui,
session,
});

const stack_start_stop = builder.get_object("stack_start_stop");
const button_run = builder.get_object("button_run");
// const button_stop = builder.get_object("button_stop");

const external = External({
onWindowChange(open) {
if (current !== external) return;
if (open) {
stack.set_visible_child_name("close_window");
} else {
stack.set_visible_child_name("open_window");
useInternal().catch(console.error);
}
onStop() {
console.log("stoping ouin ouin external");
stack_start_stop.visible_child = button_run;
useInternal().catch(console.error);
},
output,
builder,
Expand All @@ -87,12 +85,6 @@ export default function Previewer({

let handler_id_ui = null;
let handler_id_css = null;
let handler_id_button_open;
let handler_id_button_close;

const stack = builder.get_object("stack_preview");
const button_open = builder.get_object("button_open_preview_window");
const button_close = builder.get_object("button_close_preview_window");

settings.bind(
"preview-align",
Expand All @@ -109,8 +101,19 @@ export default function Previewer({
}
setPreviewAlign();

function clean() {
if (handler_id_ui) {
panel_ui.disconnect(handler_id_ui);
handler_id_ui = null;
}
if (handler_id_css) {
code_view_css.disconnect(handler_id_css);
handler_id_css = null;
}
}

function start() {
stop();
clean();
if (handler_id_ui === null) {
handler_id_ui = panel_ui.connect("updated", () => schedule_update());
}
Expand All @@ -122,14 +125,9 @@ export default function Previewer({
}

function stop() {
if (handler_id_ui) {
panel_ui.disconnect(handler_id_ui);
handler_id_ui = null;
}
if (handler_id_css) {
code_view_css.disconnect(handler_id_css);
handler_id_css = null;
}
console.log("previewer stop");
clean();
current?.stop?.();
}

// Using this custom scope we make sure that previewing UI definitions
Expand Down Expand Up @@ -243,7 +241,6 @@ export default function Previewer({
await setPreviewer(external, language);
}
current_external_language = language;
stack.set_visible_child_name("close_window");
await update(true);
}

Expand All @@ -255,13 +252,6 @@ export default function Previewer({
}

async function setPreviewer(previewer, language) {
if (handler_id_button_open) {
button_open.disconnect(handler_id_button_open);
}
if (handler_id_button_close) {
button_close.disconnect(handler_id_button_close);
}

try {
await current?.closeInspector();
} catch {
Expand All @@ -275,25 +265,6 @@ export default function Previewer({
}

current = previewer;

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

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

try {
await current.start(language);
} catch (err) {
Expand All @@ -315,9 +286,6 @@ export default function Previewer({
open() {
return current.open();
},
close() {
return current.close();
},
openInspector() {
return current.openInspector();
},
Expand Down
6 changes: 4 additions & 2 deletions src/langs/rust/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export default function Compiler({ session }) {
async function run() {
try {
const proxy = await dbus_previewer.getProxy("vala"); // rust uses the Vala previewer.
const sharedLibrary = `${targetPath}/debug/libdemo.so`;
await proxy.RunAsync(sharedLibrary, session.file.get_uri());
await proxy.RunAsync(
`${targetPath}/debug/libdemo.so`,
session.file.get_uri(),
);
} catch (err) {
console.error(err);
return false;
Expand Down
80 changes: 44 additions & 36 deletions src/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,33 @@ Adw.ApplicationWindow window {
}

[end]
Button button_run {
child: Adw.ButtonContent {
icon-name: "media-playback-start-symbolic";
label: _("_Run");
use-underline: true;
};
Stack stack_start_stop {
Button button_run {
child: Adw.ButtonContent {
icon-name: "media-playback-start-symbolic";
label: _("_Run");
use-underline: true;
};

action-name: "win.run";
tooltip-text: _("Run (Ctrl+⏎)");
action-name: "win.run";
tooltip-text: _("Run (Ctrl+⏎)");

styles [
"suggested-action"
]
styles [
"suggested-action"
]
}

Button button_stop {
child: Adw.ButtonContent {
icon-name: "media-playback-stop-symbolic";
label: _("_Stop");
use-underline: true;
};

styles [
"suggested-action"
]
}
}
}

Expand Down Expand Up @@ -417,19 +431,16 @@ Adw.ApplicationWindow window {
title: _("Windowed Preview");
description: _("This interface can only be previewed as a separate window.\nWe recommend using “Always on Top”.");
icon-name: "multitasking-windows-symbolic";

Box {
halign: center;

Button button_open_preview_window {
label: _("Show Preview Window");

styles [
"pill",
"suggested-action"
]
}
}
// Box {
// halign: center;
// Button button_open_preview_window {
// label: _("Show Preview Window");
// styles [
// "pill",
// "suggested-action"
// ]
// }
// }
};
}

Expand All @@ -440,18 +451,15 @@ Adw.ApplicationWindow window {
title: _("Windowed Preview");
description: _("This interface can only be previewed as a separate window.\nWe recommend using “Always on Top”.");
icon-name: "multitasking-windows-symbolic";

Box {
halign: center;

Button button_close_preview_window {
label: _("Close Preview Window");

styles [
"pill"
]
}
}
// Box {
// halign: center;
// Button button_close_preview_window {
// label: _("Close Preview Window");
// styles [
// "pill"
// ]
// }
// }
};
}
}
Expand Down
Loading