Skip to content

Commit f894dbe

Browse files
Improve launcher #1438
1 parent 5491f7e commit f894dbe

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/main/resources/assets/js/ConfigResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export const resolveHomeToolConfig = (): JSONObject => {
55
if (!appConfigEl) {
66
throw Error('Could not find tool config');
77
}
8-
return JSON.parse(appConfigEl.innerText);
8+
return JSON.parse(appConfigEl.innerText) as JSONObject;
99
}

src/main/resources/assets/js/launcher/main.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ let i18nStore: Map<string, string>;
1313

1414
const i18n = (key: string): string => i18nStore.has(key) ? i18nStore.get(key) : `#${key}#`;
1515

16+
const getLauncherJsonConfig = (launcherMainContainerEl: HTMLElement): JSONObject => {
17+
const scriptTagElement: HTMLScriptElement = launcherMainContainerEl.getElementsByTagName('script')[0];
18+
if (!scriptTagElement || scriptTagElement.getAttribute('id') !== 'launcher-config-json') {
19+
throw Error('Could not find launcher config');
20+
}
21+
return JSON.parse(scriptTagElement.innerText) as JSONObject;
22+
};
23+
24+
const initI18NStore = (config: JSONObject): void => {
25+
const phrases: JSONObject = JSON.parse(config['phrases']) as JSONObject;
26+
27+
i18nStore = new Map<string, string>();
28+
for (const key in phrases) {
29+
if (Object.prototype.hasOwnProperty.call(phrases, key)) {
30+
i18nStore.set(key, phrases[key]);
31+
}
32+
}
33+
};
34+
1635
class Launcher {
1736
private launcherPanel: HTMLElement;
1837
private launcherButton: HTMLElement;
@@ -602,25 +621,6 @@ const getLauncherScriptConfig = (): JSONObject => {
602621
};
603622
};
604623

605-
const getLauncherJsonConfig = (launcherMainContainerEl: HTMLElement): JSONObject => {
606-
const scriptTagElement: HTMLScriptElement = launcherMainContainerEl.getElementsByTagName('script')[0];
607-
if (!scriptTagElement || scriptTagElement.getAttribute('id') !== 'launcher-config-json') {
608-
throw Error('Could not find launcher config');
609-
}
610-
return JSON.parse(scriptTagElement.innerText);
611-
};
612-
613-
const initI18NStore = (config: JSONObject): void => {
614-
const phrases: JSONObject = JSON.parse(config['phrases']);
615-
616-
i18nStore = new Map<string, string>();
617-
for (let key in phrases) {
618-
if (phrases.hasOwnProperty(key)) {
619-
i18nStore.set(key, phrases[key]);
620-
}
621-
}
622-
};
623-
624624
const init = (): void => {
625625
const launcherConfig: JSONObject = getLauncherScriptConfig();
626626
new Launcher(launcherConfig);

0 commit comments

Comments
 (0)