Skip to content

Commit 126355f

Browse files
committed
Fix autorun when overriding the user preferred language
Introduced in #689
1 parent 3c4fe7d commit 126355f

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/Library/Library.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
demos_dir,
77
getLanguage,
88
settings as global_settings,
9-
languages,
109
} from "../util.js";
1110
import Window from "../window.js";
1211

@@ -86,18 +85,16 @@ async function openDemo({ application, demo_name, language }) {
8685
session.settings.set_boolean("show-code", true);
8786
}
8887

89-
const code_languge = session.settings.get_int("code-language");
90-
const lang = languages.find((lang) => lang.index === code_languge);
91-
9288
// Override the user preferred language if the demo doesn't support it
89+
const lang = session.getCodeLanguage();
9390
if (demo.languages.length > 0 && !demo.languages.includes(lang.id)) {
9491
session.settings.set_int(
9592
"code-language",
9693
getLanguage(demo.languages[0]).index,
9794
);
9895
}
9996

100-
const run = demo.autorun && lang.id === "javascript";
97+
const run = demo.autorun && session.getCodeLanguage().id === "javascript";
10198
const { load } = Window({ application, session });
10299
await load({ run });
103100
}

src/sessions.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
rust_template_dir,
1111
settings as global_settings,
1212
encode,
13+
languages,
1314
} from "./util.js";
1415

1516
export const sessions_dir = data_dir.get_child("sessions");
@@ -142,9 +143,14 @@ export class Session {
142143
});
143144
}
144145

145-
is_project() {
146+
isProject() {
146147
return !this.file.get_parent().equal(sessions_dir);
147148
}
149+
150+
getCodeLanguage() {
151+
const code_languge = this.settings.get_int("code-language");
152+
return languages.find((lang) => lang.index === code_languge);
153+
}
148154
}
149155

150156
function migrateStateToSession() {

src/window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ async function setGtk4PreferDark(dark) {
463463
}
464464

465465
async function onCloseSession({ session, window }) {
466-
if (session.is_project()) {
466+
if (session.isProject()) {
467467
window.destroy();
468468
return;
469469
}

0 commit comments

Comments
 (0)