Skip to content

Commit f334f84

Browse files
authored
refactor: misc changes (#5)
1 parent 399ecac commit f334f84

File tree

8 files changed

+131
-120
lines changed

8 files changed

+131
-120
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: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import FailureModal from "./FailureModal.svelte";
1111
import SuccessModal from "./SuccessModal.svelte";
1212
13-
import * as Installer from "../../../wailsjs/go/installer/Installer";
13+
import * as IPC from "./ipc";
1414
15-
type IPCCall = (typeof Installer)["Patch" | "Repair" | "Unpatch" | "InstallOpenAsar" | "UninstallOpenAsar"];
15+
import * as Installer from "../../../wailsjs/go/installer/Installer";
1616
1717
export let path: string;
1818
export let isOpenAsar: boolean = false;
@@ -21,54 +21,10 @@
2121
2222
export let busy = false;
2323
24-
function getOpPastTense(op: IPCCall) {
25-
if (op === Installer.Patch) return "installed";
26-
if (op === Installer.Repair) return "repaired";
27-
if (op === Installer.Unpatch) return "uninstalled";
28-
if (op === Installer.InstallOpenAsar) return "installed OpenAsar";
29-
if (op === Installer.UninstallOpenAsar) return "uninstalled OpenAsar";
30-
return "did something?";
31-
}
32-
33-
async function doAction(op: IPCCall) {
24+
async function doAction(op: IPC.IPCCall) {
3425
busy = true;
35-
await op(path)
36-
.then(() => {
37-
openWindow(
38-
SuccessModal,
39-
{
40-
verb: getOpPastTense(op)
41-
},
42-
{
43-
title: "Success",
44-
width: 400,
45-
height: 510
46-
}
47-
);
48-
})
49-
.catch(error => {
50-
const message = typeof error === "string" ? error : null;
51-
if (!message) console.error(error);
52-
openWindow(
53-
FailureModal,
54-
{
55-
message,
56-
path,
57-
op,
58-
getOpPastTense,
59-
onAction
60-
},
61-
{
62-
title: "MASSIVE FAILURE !!!",
63-
width: 450,
64-
height: 200
65-
}
66-
);
67-
})
68-
.finally(() => {
69-
busy = false;
70-
onAction?.();
71-
});
26+
await IPC.doAction(op, path, onAction);
27+
busy = false;
7228
}
7329
</script>
7430

frontend/src/components/installer/FailureModal.svelte

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,65 @@
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";
10-
import SuccessModal from "./SuccessModal.svelte";
119
import Heading from "../text/Heading.svelte";
1210
import Button from "../Button.svelte";
13-
import { closeWindow, openWindow } from "../windows/index.js";
11+
import { closeWindow, resizeWindow } from "../windows/index.js";
12+
import { BrowserOpenURL } from "../../../wailsjs/runtime/runtime.js";
1413
15-
type IPCCall = (typeof Installer)["Patch" | "Repair" | "Unpatch" | "InstallOpenAsar" | "UninstallOpenAsar"];
14+
import * as IPC from "./ipc";
1615
1716
export let message: string | null = null;
1817
export let path: string = "";
19-
export let op: IPCCall;
20-
export let getOpPastTense: (IPCCall) => string;
18+
export let op: IPC.IPCCall;
2119
export let onAction: () => void;
20+
export let _windowId: string;
2221
2322
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();
23+
if (!await Installer.PromptForChown(path)) return;
24+
25+
closeWindow(_windowId);
26+
27+
setTimeout(() => IPC.doAction(op, path, onAction));
3828
}
3929
40-
let buttonPress: () => void;
30+
let isOwned = true;
31+
32+
// svelte hacks...
33+
async function CheckOwnership() {
34+
isOwned = await Installer.CheckForOwnershipDarwin(path);
35+
}
4136
42-
function waitForButton() {
43-
return new Promise<void>(res => {
44-
buttonPress = res;
45-
});
37+
$: if (!isOwned) {
38+
resizeWindow(_windowId, 450, 410);
39+
} else {
40+
resizeWindow(_windowId, 450, 200);
4641
}
4742
</script>
4843

4944
<section role="dialog">
5045
<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>
46+
<p>Something went wrong!</p>
5247
{#if message}
5348
{#if message.includes("file exists") || message.includes("permission denied")}
54-
{#await Installer.CheckForOwnershipDarwin(path)}
49+
{#await CheckOwnership()}
5550
<p>{message}</p>
56-
{:then isOwned}
51+
{:then}
5752
{#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}
53+
<p>Hmm... seems like you've encountered a Mac-specific problem! Usually, this is one of two things:</p>
54+
<p>
55+
Your Discord installation's permissions appear to be broken. Luckily, we offer a simple
56+
tool to fix this.
57+
</p>
58+
<Button on:click={runAndShowSuccess}>Repair Permissions</Button>
59+
<p>
60+
Sometimes the installer needs Full Disk Access, though usually the above should suffice.
61+
</p>
62+
<Button on:click={() =>
63+
BrowserOpenURL("x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles")}>
64+
Open Security Settings
65+
</Button>
66+
<p>Or sometimes it's both! Try enabling Full Disk Access, then repairing permissions.</p>
9167
{:else}
9268
<p>{message}</p>
9369
{/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>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import FailureModal from "./FailureModal.svelte";
2+
import SuccessModal from "./SuccessModal.svelte";
3+
4+
import { openWindow } from "../windows";
5+
6+
import * as Installer from "../../../wailsjs/go/installer/Installer";
7+
8+
export type IPCCall = (typeof Installer)["Patch" | "Repair" | "Unpatch" | "InstallOpenAsar" | "UninstallOpenAsar"];
9+
10+
export function getOpPastTense(op: IPCCall) {
11+
if (op === Installer.Patch) return "installed";
12+
if (op === Installer.Repair) return "repaired";
13+
if (op === Installer.Unpatch) return "uninstalled";
14+
if (op === Installer.InstallOpenAsar) return "installed OpenAsar";
15+
if (op === Installer.UninstallOpenAsar) return "uninstalled OpenAsar";
16+
return "did something?";
17+
}
18+
19+
export async function doAction(op: IPCCall, path: string, onAction: () => void) {
20+
await op(path)
21+
.then(() => {
22+
openWindow(
23+
SuccessModal,
24+
{
25+
verb: getOpPastTense(op)
26+
},
27+
{
28+
title: "Woohoo!",
29+
width: 400,
30+
height: 510
31+
}
32+
);
33+
})
34+
.catch(error => {
35+
const message = typeof error === "string" ? error : null;
36+
if (!message) console.error(error);
37+
openWindow(
38+
FailureModal,
39+
{
40+
message,
41+
path,
42+
op,
43+
onAction
44+
},
45+
{
46+
title: "Uh oh!",
47+
width: 450,
48+
height: 200
49+
}
50+
);
51+
})
52+
.finally(() => {
53+
onAction?.();
54+
});
55+
}

frontend/src/components/windows/Window.svelte

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@
114114
<div class="frame" class:maximized use:resize on:mousedown={onFocus} {style} in:transition out:transition>
115115
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
116116
<div class="titlebar" role="application" on:mousedown={onDragStart}>
117-
<div class="icon">
118-
{#if icon}
117+
{#if icon}
118+
<div class="icon">
119119
<svelte:component this={icon} />
120-
{/if}
121-
</div>
120+
</div>
121+
{/if}
122122
<div class="title body sm">{title}</div>
123123
<div class="spacer"></div>
124124
<!-- svelte-ignore a11y-no-static-element-interactions -->
@@ -185,6 +185,16 @@
185185
height: 1.25rem;
186186
margin: 0 1rem;
187187
}
188+
189+
.title {
190+
margin-left: 1rem;
191+
}
192+
193+
/* don't add margin if icon exists, as the icon will do it */
194+
.icon + .title {
195+
margin-left: 0;
196+
}
197+
188198
.frame.maximized .icon,
189199
.frame.maximized .title {
190200
opacity: 0;

frontend/src/components/windows/index.ts

Lines changed: 13 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) => {
@@ -46,6 +48,14 @@ export const closeWindow = (id: string) => {
4648
});
4749
};
4850

51+
export const resizeWindow = (id: string, w: number, h: number) => {
52+
windowStore.update(windows => {
53+
windows[id].props.width = w;
54+
windows[id].props.height = h;
55+
return windows;
56+
});
57+
}
58+
4959
let zIndex = 0;
5060
export const getFocusZIndex = () => {
5161
zIndex++;

installer/find_discord_windows.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os/exec"
1414
path "path/filepath"
1515
"strings"
16+
"syscall"
1617
)
1718

1819
var windowsNames = map[string]string{
@@ -88,7 +89,9 @@ func PreparePatch(di *DiscordInstall) {
8889
name := windowsNames[di.branch]
8990
fmt.Println("Killing " + name + "...")
9091

91-
_ = exec.Command("powershell", "Stop-Process -Name "+name).Run()
92+
kill_cmd := exec.Command("powershell", "Stop-Process -Name "+name)
93+
kill_cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
94+
kill_cmd.Run()
9295
}
9396

9497
func FixOwnership(_ string) error {

0 commit comments

Comments
 (0)