Skip to content

Commit bbe3bb5

Browse files
committed
refactor: tidy up mac-specific error handling
1 parent f23d9ce commit bbe3bb5

File tree

5 files changed

+48
-61
lines changed

5 files changed

+48
-61
lines changed

frontend/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ dist/
22
node_modules/
33

44
# Auto generated Wails bindings
5-
wailsjs/
5+
wailsjs/
6+
package.json.md5

frontend/src/components/installer/Actions.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
verb: getOpPastTense(op)
4141
},
4242
{
43-
title: "Success",
43+
title: "Woohoo!",
4444
width: 400,
4545
height: 510
4646
}
@@ -59,7 +59,7 @@
5959
onAction
6060
},
6161
{
62-
title: "MASSIVE FAILURE !!!",
62+
title: "Uh oh!",
6363
width: 450,
6464
height: 200
6565
}

frontend/src/components/installer/FailureModal.svelte

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
-->
66

77
<script lang="ts">
8-
import { Environment, BrowserOpenURL } from "../../../wailsjs/runtime/runtime.js";
98
import * as Installer from "../../../wailsjs/go/installer/Installer.js";
109
import SuccessModal from "./SuccessModal.svelte";
1110
import Heading from "../text/Heading.svelte";
1211
import Button from "../Button.svelte";
1312
import { closeWindow, openWindow } from "../windows/index.js";
13+
import { BrowserOpenURL } from "../../../wailsjs/runtime/runtime.js";
1414
1515
type IPCCall = (typeof Installer)["Patch" | "Repair" | "Unpatch" | "InstallOpenAsar" | "UninstallOpenAsar"];
1616
@@ -19,75 +19,59 @@
1919
export let op: IPCCall;
2020
export let getOpPastTense: (IPCCall) => string;
2121
export let onAction: () => void;
22+
export let _windowId: string;
2223
2324
async function runAndShowSuccess() {
24-
await op(path);
25-
openWindow(
26-
SuccessModal,
27-
{
28-
verb: getOpPastTense(op)
29-
},
30-
{
31-
title: "Success",
32-
width: 400,
33-
height: 510
34-
}
35-
);
36-
// closeWindow(id);
37-
onAction();
38-
}
25+
if (!await Installer.PromptForChown(path)) return;
3926
40-
let buttonPress: () => void;
27+
closeWindow(_windowId);
4128
42-
function waitForButton() {
43-
return new Promise<void>(res => {
44-
buttonPress = res;
29+
setTimeout(async () => {
30+
await op(path);
31+
openWindow(
32+
SuccessModal,
33+
{
34+
verb: getOpPastTense(op)
35+
},
36+
{
37+
title: "Woohoo!",
38+
width: 400,
39+
height: 510
40+
}
41+
);
42+
onAction();
4543
});
4644
}
4745
</script>
4846

4947
<section role="dialog">
5048
<Heading tag="h6" --color="var(--accent-red)">Oh no!</Heading>
51-
<p>Unable to do the thing u were trying to do :&lpar;&lpar;&lpar;&lpar;&lpar;</p>
49+
<p>Something went wrong!</p>
5250
{#if message}
5351
{#if message.includes("file exists") || message.includes("permission denied")}
5452
{#await Installer.CheckForOwnershipDarwin(path)}
5553
<p>{message}</p>
5654
{:then isOwned}
5755
{#if !isOwned}
58-
{#await Environment()}
59-
<p>{message}</p>
60-
{:then env}
61-
{#if env.platform === "darwin"}
62-
{#await waitForButton()}
63-
<p>Please allow vencord to fix discord's permissions</p>
64-
<Button on:click={buttonPress}>Try again as admin</Button>
65-
{:then}
66-
{#await Installer.PromptForChown(path)}
67-
<p>Please allow vencord to fix discord's permissions</p>
68-
<Button on:click={() => {}}>Try again as admin</Button>
69-
{:then}
70-
{#await runAndShowSuccess()}
71-
<p>Working...</p>
72-
{:then}
73-
<p>Success! You can close this window</p>
74-
{:catch}
75-
<p>Please grant the installer full disk access</p>
76-
<Button
77-
on:click={() =>
78-
BrowserOpenURL(
79-
"x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"
80-
)}>Open Security Settings</Button
81-
>
82-
{/await}
83-
{:catch error}
84-
<p>{error}</p>
85-
{/await}
86-
{/await}
87-
{:else}
88-
<p>{message}</p>
89-
{/if}
90-
{/await}
56+
<p>Hmm... seems like you've encountered a Mac-specific problem! Usually, this is one of two things:</p>
57+
<ul>
58+
<li>
59+
<p>
60+
Your Discord installation's permissions appear to be broken. Luckily, we offer a simple
61+
tool to fix this.
62+
</p>
63+
<Button on:click={runAndShowSuccess}>Repair Permissions</Button>
64+
</li>
65+
<li>
66+
<p>
67+
Sometimes the installer needs Full Disk Access, though usually the above should suffice.
68+
</p>
69+
<Button on:click={() =>
70+
BrowserOpenURL("x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles")}>
71+
Open Security Settings
72+
</Button>
73+
</li>
74+
</ul>
9175
{:else}
9276
<p>{message}</p>
9377
{/if}

frontend/src/components/installer/SuccessModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</script>
1313

1414
<section role="dialog">
15-
<Heading tag="h6" --color="var(--accent-green)">Successfully {verb}!!</Heading>
15+
<Heading tag="h6" --color="var(--accent-green)">Successfully {verb}!</Heading>
1616
<p>Enjoy this shiggy:</p>
1717
<img src="https://media.discordapp.net/stickers/1039992459209490513.png?size=240" alt="shiggy" />
1818
</section>

frontend/src/components/windows/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,23 @@ export const windowStore = writable<Record<string, WindowInstance>>({});
2222

2323
export const openWindow = <T extends SvelteComponent>(
2424
component: Constructor<T>,
25-
props: ComponentProps<T>,
25+
props: Omit<ComponentProps<T>, "_windowId">,
2626
windowOptions: SetOptional<ComponentProps<Window>, "id">
2727
) => {
28+
const id = Math.random().toString(36).substring(7);
2829
const newWindow: WindowInstance<T> = {
2930
props: {
30-
id: Math.random().toString(36).substring(7),
31+
id,
3132
...windowOptions
3233
},
3334
content: component,
34-
contentProps: props
35+
contentProps: { ...props, _windowId: id } as ComponentProps<T>
3536
};
3637
windowStore.update(windows => {
3738
windows[newWindow.props.id] = newWindow;
3839
return windows;
3940
});
41+
return newWindow.props.id;
4042
};
4143

4244
export const closeWindow = (id: string) => {

0 commit comments

Comments
 (0)