Skip to content

Commit

Permalink
refactor: tidy up mac-specific error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisakura committed Aug 29, 2023
1 parent f23d9ce commit bbe3bb5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 61 deletions.
3 changes: 2 additions & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ dist/
node_modules/

# Auto generated Wails bindings
wailsjs/
wailsjs/
package.json.md5
4 changes: 2 additions & 2 deletions frontend/src/components/installer/Actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
verb: getOpPastTense(op)
},
{
title: "Success",
title: "Woohoo!",
width: 400,
height: 510
}
Expand All @@ -59,7 +59,7 @@
onAction
},
{
title: "MASSIVE FAILURE !!!",
title: "Uh oh!",
width: 450,
height: 200
}
Expand Down
92 changes: 38 additions & 54 deletions frontend/src/components/installer/FailureModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
-->

<script lang="ts">
import { Environment, BrowserOpenURL } from "../../../wailsjs/runtime/runtime.js";
import * as Installer from "../../../wailsjs/go/installer/Installer.js";
import SuccessModal from "./SuccessModal.svelte";
import Heading from "../text/Heading.svelte";
import Button from "../Button.svelte";
import { closeWindow, openWindow } from "../windows/index.js";
import { BrowserOpenURL } from "../../../wailsjs/runtime/runtime.js";
type IPCCall = (typeof Installer)["Patch" | "Repair" | "Unpatch" | "InstallOpenAsar" | "UninstallOpenAsar"];
Expand All @@ -19,75 +19,59 @@
export let op: IPCCall;
export let getOpPastTense: (IPCCall) => string;
export let onAction: () => void;
export let _windowId: string;
async function runAndShowSuccess() {
await op(path);
openWindow(
SuccessModal,
{
verb: getOpPastTense(op)
},
{
title: "Success",
width: 400,
height: 510
}
);
// closeWindow(id);
onAction();
}
if (!await Installer.PromptForChown(path)) return;
let buttonPress: () => void;
closeWindow(_windowId);
function waitForButton() {
return new Promise<void>(res => {
buttonPress = res;
setTimeout(async () => {
await op(path);
openWindow(
SuccessModal,
{
verb: getOpPastTense(op)
},
{
title: "Woohoo!",
width: 400,
height: 510
}
);
onAction();
});
}
</script>

<section role="dialog">
<Heading tag="h6" --color="var(--accent-red)">Oh no!</Heading>
<p>Unable to do the thing u were trying to do :&lpar;&lpar;&lpar;&lpar;&lpar;</p>
<p>Something went wrong!</p>
{#if message}
{#if message.includes("file exists") || message.includes("permission denied")}
{#await Installer.CheckForOwnershipDarwin(path)}
<p>{message}</p>
{:then isOwned}
{#if !isOwned}
{#await Environment()}
<p>{message}</p>
{:then env}
{#if env.platform === "darwin"}
{#await waitForButton()}
<p>Please allow vencord to fix discord's permissions</p>
<Button on:click={buttonPress}>Try again as admin</Button>
{:then}
{#await Installer.PromptForChown(path)}
<p>Please allow vencord to fix discord's permissions</p>
<Button on:click={() => {}}>Try again as admin</Button>
{:then}
{#await runAndShowSuccess()}
<p>Working...</p>
{:then}
<p>Success! You can close this window</p>
{:catch}
<p>Please grant the installer full disk access</p>
<Button
on:click={() =>
BrowserOpenURL(
"x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"
)}>Open Security Settings</Button
>
{/await}
{:catch error}
<p>{error}</p>
{/await}
{/await}
{:else}
<p>{message}</p>
{/if}
{/await}
<p>Hmm... seems like you've encountered a Mac-specific problem! Usually, this is one of two things:</p>
<ul>
<li>
<p>
Your Discord installation's permissions appear to be broken. Luckily, we offer a simple
tool to fix this.
</p>
<Button on:click={runAndShowSuccess}>Repair Permissions</Button>
</li>
<li>
<p>
Sometimes the installer needs Full Disk Access, though usually the above should suffice.
</p>
<Button on:click={() =>
BrowserOpenURL("x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles")}>
Open Security Settings
</Button>
</li>
</ul>
{:else}
<p>{message}</p>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/installer/SuccessModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>

<section role="dialog">
<Heading tag="h6" --color="var(--accent-green)">Successfully {verb}!!</Heading>
<Heading tag="h6" --color="var(--accent-green)">Successfully {verb}!</Heading>
<p>Enjoy this shiggy:</p>
<img src="https://media.discordapp.net/stickers/1039992459209490513.png?size=240" alt="shiggy" />
</section>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/components/windows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ export const windowStore = writable<Record<string, WindowInstance>>({});

export const openWindow = <T extends SvelteComponent>(
component: Constructor<T>,
props: ComponentProps<T>,
props: Omit<ComponentProps<T>, "_windowId">,
windowOptions: SetOptional<ComponentProps<Window>, "id">
) => {
const id = Math.random().toString(36).substring(7);
const newWindow: WindowInstance<T> = {
props: {
id: Math.random().toString(36).substring(7),
id,
...windowOptions
},
content: component,
contentProps: props
contentProps: { ...props, _windowId: id } as ComponentProps<T>
};
windowStore.update(windows => {
windows[newWindow.props.id] = newWindow;
return windows;
});
return newWindow.props.id;
};

export const closeWindow = (id: string) => {
Expand Down

0 comments on commit bbe3bb5

Please sign in to comment.