Skip to content

Commit c8289f6

Browse files
committed
feat(api): error handling past startup validation
1 parent e060842 commit c8289f6

4 files changed

Lines changed: 58 additions & 15 deletions

File tree

src/lib/Window.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
/>
115115
{:else if options}
116116
{#if options.start.account}
117-
<MainScreen {client} bind:options />
117+
<MainScreen {client} bind:options bind:error />
118118
{:else}
119119
<LoginScreen bind:options />
120120
{/if}
@@ -144,4 +144,4 @@
144144
background-color: rgba(0, 0, 0, 0.8);
145145
}
146146
}
147-
</style>
147+
</style>

src/lib/main/ButtonLaunchArea.svelte

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@
44
55
export let text;
66
export let active;
7+
export let disabled = false;
78
89
const dispatch = createEventDispatcher();
910
</script>
1011

11-
<button class="button" class:active type="button" on:click={e => dispatch("click", e)}>{text}</button>
12+
<button
13+
class="button"
14+
class:active
15+
type="button"
16+
disabled={disabled}
17+
on:click={e => dispatch("click", e)}
18+
>
19+
{text}
20+
</button>
1221

1322
<style>
1423
.button {
@@ -38,4 +47,9 @@
3847
.button.active:hover {
3948
background-color: #9B2D23;
4049
}
41-
</style>
50+
51+
.button:disabled {
52+
opacity: 0.6;
53+
cursor: not-allowed;
54+
}
55+
</style>

src/lib/main/LaunchArea.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
export let mcVersion;
88
export let lbVersion;
99
export let running;
10+
export let canLaunch = true;
1011
1112
const dispatch = createEventDispatcher();
1213
@@ -43,7 +44,12 @@
4344
<ButtonLaunchArea text="Log" active={false} on:click={() => dispatch("showClientLog")} />
4445
</div>
4546
{:else}
46-
<ButtonLaunchArea text="Launch LiquidBounce" active={false} on:click={() => dispatch("launch")} />
47+
<ButtonLaunchArea
48+
text="Launch LiquidBounce"
49+
active={false}
50+
disabled={!canLaunch}
51+
on:click={() => dispatch("launch")}
52+
/>
4753
{/if}
4854
</div>
4955

@@ -107,4 +113,4 @@
107113
grid-template-columns: 1fr max-content;
108114
column-gap: 10px;
109115
}
110-
</style>
116+
</style>

src/lib/main/MainScreen.svelte

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
export let client;
1818
export let options;
19+
export let error;
1920
2021
let running = false;
2122
@@ -68,11 +69,21 @@
6869
}
6970
7071
async function updateData() {
71-
const newBuilds = await invoke("request_builds", {
72-
client,
73-
branch: options.version.branchName,
74-
release: !options.launcher.showNightlyBuilds
75-
});
72+
let newBuilds;
73+
try {
74+
newBuilds = await invoke("request_builds", {
75+
client,
76+
branch: options.version.branchName,
77+
release: !options.launcher.showNightlyBuilds
78+
});
79+
} catch (e) {
80+
console.error("Failed to request builds:", e);
81+
error = {
82+
message: "Failed to establish connection with LiquidBounce API",
83+
error: e
84+
};
85+
return;
86+
}
7687
7788
newBuilds.forEach(build => {
7889
const date = new Date(build.date);
@@ -131,6 +142,7 @@
131142
}
132143
133144
async function runClientWithWarning() {
145+
if (!versionState.currentBuild) return;
134146
const isWarning = options.version.branchName === "legacy" ||
135147
(options.version.branchName === "nextgen" && options.version.buildId !== -1);
136148
@@ -273,9 +285,19 @@
273285
});
274286
275287
onMount(async () => {
276-
let branchesData = await invoke("request_branches", {
277-
client
278-
});
288+
let branchesData;
289+
try {
290+
branchesData = await invoke("request_branches", {
291+
client
292+
});
293+
} catch (e) {
294+
console.error("Failed to request branches:", e);
295+
error = {
296+
message: "Failed to establish connection with LiquidBounce API",
297+
error: e
298+
};
299+
return;
300+
}
279301
versionState.branches = branchesData.branches.sort((a, b) =>
280302
(a === branchesData.defaultBranch ? -1 : b === branchesData.defaultBranch ? 1 : 0));
281303
@@ -358,6 +380,7 @@
358380
}}
359381
mcVersion={versionState.currentBuild?.mcVersion || "Loading..."}
360382
lbVersion={versionState.currentBuild?.lbVersion || "Loading..."}
383+
canLaunch={!!versionState.currentBuild}
361384
{running}
362385
on:showVersionSelect={() => versionSelectShown = true}
363386
on:showClientLog={() => logShown = true}
@@ -366,4 +389,4 @@
366389
/>
367390
<NewsArea {client} />
368391
</ContentWrapper>
369-
</VerticalFlexWrapper>
392+
</VerticalFlexWrapper>

0 commit comments

Comments
 (0)