Skip to content

Commit 0d5471d

Browse files
committed
Refactor modpack handling to support multiple modpacks and improve error handling in JSON responses
1 parent 1f8e4b2 commit 0d5471d

File tree

6 files changed

+34
-19
lines changed

6 files changed

+34
-19
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tacxtv/miratopia-launcher",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"description": "Launcher officiel du serveur Minecraft Miratopia",
55
"main": "dist-electron/main.js",
66
"repository": "https://github.com/tacxtv/miratopia-launcher.git",
@@ -52,4 +52,4 @@
5252
"peerDependencies": {
5353
"vue": "^3.4"
5454
}
55-
}
55+
}

src/app.vue

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,29 @@ export default defineNuxtComponent({
1818
},
1919
})
2020
).data
21-
const modpack: Modpack = (
22-
await axios.get('https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/modpacks/mirasurvie/modpack.json', {
23-
headers: {
24-
'Content-Type': 'application/json',
25-
},
26-
})
27-
).data
21+
22+
let modpack
23+
const modpacks = []
24+
for await (const mp of launcher?.config?.modpacks) {
25+
const mpk: Modpack = (
26+
await axios.get(`https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/modpacks/${mp}/modpack.json`, {
27+
headers: {
28+
'Content-Type': 'application/json',
29+
},
30+
})
31+
).data
32+
modpacks.push(mpk)
33+
}
2834
2935
return {
3036
launcher,
31-
modpack,
37+
modpacks,
3238
}
3339
},
3440
provide() {
3541
return {
3642
'global-launcher': this.launcher,
37-
'global-modpacks': [this.modpack],
43+
'global-modpacks': this.modpacks,
3844
}
3945
},
4046
mounted() {},

src/components/modpack/display.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ div.fit.flex(:style='{flexFlow: "column"}')
33
div.fit.q-px-md.text-center.q-mt-lg
44
q-img.q-ma-sm(src="https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/launcher/logo.png" height="auto" width="20%")
55
q-img.q-ma-sm.q-mt-xl(src="https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/launcher/title.png" height="auto" width="70%")
6-
//- h1.text-h4.text-center.q-mb-md(v-text='modpack.name')
7-
//- small.text-center.q-mb-md(v-text='modpack.description')
6+
h1.text-h4.text-center.q-mb-md(v-text='modpack.name')
7+
small.text-center.q-mb-md(v-text='modpack.description')
88
q-toolbar.q-mb-lg
99
q-space
1010
q-btn.q-mx-sm(icon='mdi-cog' flat dense @click='openSettings')
@@ -46,8 +46,8 @@ export default defineNuxtComponent({
4646
}),
4747
methods: {
4848
openSettings() {
49-
(this['settings-dialog'] as { data: boolean }).data = true;
50-
(this['settings-tab'] as { data: string }).data = this.modpack.name;
49+
;(this['settings-dialog'] as { data: boolean }).data = true
50+
;(this['settings-tab'] as { data: string }).data = this.modpack.name
5151
},
5252
launchMinecraft() {
5353
this.logsDisplay = true
@@ -67,7 +67,7 @@ export default defineNuxtComponent({
6767
this.$nextTick(() => {
6868
const target = (this.$refs.chatScroll as InstanceType<typeof QScrollArea>)?.getScrollTarget()
6969
if (!target) return
70-
; (this.$refs.chatScroll as InstanceType<typeof QScrollArea>)?.setScrollPosition('vertical', target.scrollHeight, 0)
70+
;(this.$refs.chatScroll as InstanceType<typeof QScrollArea>)?.setScrollPosition('vertical', target.scrollHeight, 0)
7171
})
7272
})
7373
window.electron.onMinecraftStartup(() => {

src/electron/services/minecraft.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ export class MinecraftService {
2222
headers: {
2323
'Content-Type': 'application/json',
2424
},
25-
}).then((res) => res.json())
26-
return list
25+
}).then(async (res) => {
26+
try {
27+
return await res.json()
28+
} catch (e) {
29+
return []
30+
}
31+
})
32+
33+
return [...list]
2734
}
2835

2936
public async registerEvents(): Promise<void> {

src/pages/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import type { Modpack } from '~~/types/modpack.type'
4646
export default defineNuxtComponent({
4747
inject: ['global-launcher', 'global-modpacks'],
4848
data: () => ({
49-
tab: ref(''),
5049
videoPlayer: ref<HTMLVideoElement | null>(null),
5150
selectedVideo: '',
5251
settingsDialog: reactive({
@@ -73,6 +72,7 @@ export default defineNuxtComponent({
7372
},
7473
},
7574
setup() {
75+
const tab = ref('')
7676
const videos = [
7777
{
7878
name: '/videos/Bateau_pirate.mp4',
@@ -166,6 +166,7 @@ export default defineNuxtComponent({
166166
const splitter = ref(25)
167167
168168
return {
169+
tab,
169170
videos,
170171
splitter,
171172
packageVersion: runtimeConfig.app.packageVersion,

types/launcher.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export type Launcher = {
1414
background: string
1515
}
1616
}
17+
modpacks: string[]
1718
}
1819
}

0 commit comments

Comments
 (0)