Skip to content

Commit 01f9585

Browse files
committed
Cleanup and give exit option in error dialog
1 parent 268b601 commit 01f9585

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/components/LoadingScreen/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { OfflineDialog } from "@app/dialogs/Dialogs/OfflineDialog";
1616
import { remove } from "@tauri-apps/plugin-fs";
1717
import { appConfigDir, join } from "@tauri-apps/api/path";
1818
import CheckForUpdates from "@app/components/Updater";
19+
import {exit} from "@tauri-apps/plugin-process";
1920

2021
const appWindow = getCurrentWebviewWindow();
2122

@@ -94,17 +95,26 @@ const LoadingScreen: React.FC<Props> = (props: Props) => {
9495
if (directories.downloadLocationInvalid) {
9596
do {
9697
result = await showErrorDialog("The download location is invalid. This is likely because your download location is on a removable drive or the launcher does not have permission to write to it. If you are using a removable drive, please plug it in and click retry. Otherwise, click Okay to restart the onboarding process.",
97-
true);
98+
true, true);
9899

99100
if (result == "retry") {
100101
await directories.setDirs(downloadLocation);
101102
directories = useDirectories.getState();
102103
}
103-
} while (result === "retry");
104+
105+
if (result == "close") {
106+
await exit();
107+
}
108+
} while (result === "retry" && directories.downloadLocationInvalid);
104109

105110
// User gave up retrying and download location is still invalid, so restart onboarding
106111
if (directories.downloadLocationInvalid) {
107-
await showErrorDialog("Due to an invalid download location the launcher will be reinitialized. Once you click Okay all settings will be lost and you will restart the onboarding process. If your launcher was previously working and you want to attempt recovery, do not click Okay and instead close the launcher.");
112+
result = await showErrorDialog("Due to an invalid download location the launcher will be reinitialized. Once you click Okay all settings will be lost and you will restart the onboarding process. If you want to attempt recovery, do not click Okay and instead close the launcher.\nLast Error: " + directories.lastError,
113+
false, true);
114+
115+
if (result == "close") {
116+
await exit();
117+
}
108118

109119
try {
110120
await remove(await join(await appConfigDir(), "settings.json"));

src/dialogs/Dialogs/ErrorDialog.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export class ErrorDialog extends BaseDialog<Record<string, never>> {
4949
{ this.props.showRetry &&
5050
<Button color={ButtonColor.GREEN} rounded onClick={() => closeDialog("retry")}>Retry</Button>
5151
}
52+
{ this.props.showClose &&
53+
<Button color={ButtonColor.RED} rounded onClick={() => closeDialog("close")}>Close</Button>
54+
}
5255
</>;
5356
}
5457
}

src/dialogs/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ export const setDialogOpen = (open: boolean) => {
5252
};
5353

5454
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55-
export async function showErrorDialog(error: any, showRetry = false): Promise<string | undefined> {
56-
return await createAndShowDialog(ErrorDialog, { error, showRetry });
55+
export async function showErrorDialog(error: any, showRetry = false, showClose = false): Promise<string | undefined> {
56+
return await createAndShowDialog(ErrorDialog, { error, showRetry, showClose });
5757
}

src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect, useState} from "react";
1+
import React, {useState} from "react";
22
import ReactDOM from "react-dom/client";
33
import "./styles.css";
44
import TitleBar from "./components/TitleBar";

src/profiles/directories.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface DirectoriesStore {
1818
importantDirs?: ImportantDirs,
1919
customDirs?: CustomDirs,
2020
downloadLocationInvalid: boolean,
21+
lastError?: string,
2122

2223
setDirs: (downloadLocation?: string) => Promise<void>;
2324
}
@@ -44,13 +45,16 @@ export const useDirectories = create<DirectoriesStore>()((set) => ({
4445

4546
set({
4647
importantDirs,
47-
customDirs
48+
customDirs,
49+
downloadLocationInvalid: false,
50+
lastError: undefined
4851
});
4952
} catch (e) {
5053
set({
5154
importantDirs,
5255
customDirs: undefined,
53-
downloadLocationInvalid: true
56+
downloadLocationInvalid: true,
57+
lastError: e as string
5458
});
5559
}
5660
}

0 commit comments

Comments
 (0)