Skip to content

Commit 700c327

Browse files
authored
Fix blank preview on no code demos (#865)
Fixes #812 Closes #820 This is the culprit https://github.com/workbenchdev/Workbench/blob/58b40d9802d14cbcc613a4f25489858783b808b2/src/window.js#L268-L272C6 For that particular code path (javascript selected, demo without js) it wouldn't update the preview One of the issue is that demos without code shouldn't have `autorun: true`. I will fix that. But in any case - I don't want Workbench to misbehave even if the demo json is incorrect.
1 parent 58b40d9 commit 700c327

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

src/Library/Library.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,23 @@ async function openDemo({ application, demo_name, language }) {
9292
session.settings.set_boolean("show-code", true);
9393
}
9494

95+
const { autorun, languages } = demo;
96+
9597
// Override the user preferred language if the demo doesn't support it
9698
const lang = session.getCodeLanguage();
97-
if (demo.languages.length > 0 && !demo.languages.includes(lang.id)) {
99+
if (languages.length > 0 && !languages.includes(lang.id)) {
98100
session.settings.set_int(
99101
"code-language",
100102
getLanguage(demo.languages[0]).index,
101103
);
102104
}
103105

104-
const run = demo.autorun && session.getCodeLanguage().id === "javascript";
105-
const { load } = Window({ application, session });
106-
await load({ run });
106+
const { load, runCode } = Window({ application, session });
107+
await load();
108+
109+
const code_language = session.getCodeLanguage();
110+
const run = autorun && code_language.id === "javascript";
111+
if (run) {
112+
await runCode();
113+
}
107114
}

src/about.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ${getBlueprintVersion()}
3333
copyright: "© 2022 Sonny Piers",
3434
license_type: Gtk.License.GPL_3_0_ONLY,
3535
version: pkg.version,
36-
website: "https://workbench.sonny.re",
36+
website: "https://apps.gnome.org/Workbench",
3737
application_icon: pkg.name,
3838
issue_url: "https://github.com/workbenchdev/Workbench/issues",
3939
debug_info,

src/application.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ application.connect("open", (_self, files, hint) => {
3636
application,
3737
session,
3838
});
39-
load({ run: false }).catch(console.error);
39+
load().catch(console.error);
4040
});
4141

4242
application.connect("startup", () => {
@@ -59,7 +59,9 @@ application.connect("activate", () => {
5959
}
6060
});
6161

62-
application.set_option_context_description("<https://workbench.sonny.re>");
62+
application.set_option_context_description(
63+
"<https://apps.gnome.org/Workbench>",
64+
);
6365

6466
Actions({ application });
6567

@@ -87,7 +89,7 @@ function restoreSessions() {
8789
application,
8890
session,
8991
});
90-
load({ run: false }).catch(console.error);
92+
load().catch(console.error);
9193
});
9294
}
9395
}
@@ -106,7 +108,7 @@ function bootstrap() {
106108
session,
107109
});
108110
window.maximize();
109-
load({ run: false }).catch(console.error);
111+
load().catch(console.error);
110112
settings.set_boolean("first-run", false);
111113
}
112114

src/window.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export default function Window({ application, session }) {
230230
let compiler_rust = null;
231231
let builder_python = null;
232232

233-
async function runCode({ format }) {
233+
async function runCode() {
234234
button_run.set_sensitive(false);
235235

236236
term_console.clear();
@@ -240,9 +240,7 @@ export default function Window({ application, session }) {
240240
try {
241241
await panel_ui.update();
242242

243-
if (format) {
244-
await formatCode();
245-
}
243+
await formatCode();
246244

247245
await compile();
248246
} catch (err) {
@@ -346,7 +344,7 @@ export default function Window({ application, session }) {
346344
name: "run",
347345
});
348346
action_run.connect("activate", () => {
349-
runCode({ format: true }).catch(console.error);
347+
runCode().catch(console.error);
350348
});
351349
window.add_action(action_run);
352350
application.set_accels_for_action("win.run", ["<Control>Return"]);
@@ -380,7 +378,7 @@ export default function Window({ application, session }) {
380378
window.present();
381379

382380
const documents = Object.values(langs).map((lang) => lang.document);
383-
async function load({ run }) {
381+
async function load() {
384382
panel_ui.stop();
385383
previewer.stop();
386384
documents.forEach((document) => document.stop());
@@ -397,15 +395,11 @@ export default function Window({ application, session }) {
397395

398396
await previewer.useInternal();
399397

400-
if (run) {
401-
await runCode({ format: false });
402-
} else {
403-
term_console.clear();
404-
panel_ui.start();
405-
await panel_ui.update();
406-
previewer.start();
407-
await previewer.update(true);
408-
}
398+
term_console.clear();
399+
panel_ui.start();
400+
await panel_ui.update();
401+
previewer.start();
402+
await previewer.update(true);
409403

410404
documents.forEach((document) => {
411405
document.start();
@@ -414,7 +408,7 @@ export default function Window({ application, session }) {
414408
term_console.scrollToEnd();
415409
}
416410

417-
return { load, window };
411+
return { load, window, runCode };
418412
}
419413

420414
async function setGtk4PreferDark(dark) {

0 commit comments

Comments
 (0)