Skip to content

Commit

Permalink
Add warning for existing client mod
Browse files Browse the repository at this point in the history
  • Loading branch information
asportnoy committed Feb 20, 2023
1 parent 303f8c6 commit 7db8f5d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "./App.css";
import { ChooseAction, ChoosePlatform, Download, License, Progress } from "./steps";
import logo from "../../assets/logo.png";
import { useEffect, useState } from "react";
import { DiscordPlatform } from "./types";
import { DiscordPlatform, PlatformData } from "./types";
import { getPlatforms } from "./util";

function Header(): React.ReactElement {
Expand All @@ -18,24 +18,25 @@ function Header(): React.ReactElement {
export default function App(): React.ReactElement {
const [action, setAction] = useState<"plug" | "unplug">("plug");
const [platforms, setPlatforms] = useState<DiscordPlatform[]>([]);
const [availablePlatforms, setAvailablePlatforms] = useState<DiscordPlatform[]>([]);
const [platformData, setPlatformData] = useState<Record<DiscordPlatform, PlatformData> | null>(
null,
);

const init = async (reset = false): Promise<void> => {
if (reset) {
setAction("plug");
setPlatforms([]);
setAvailablePlatforms([]);
setPlatformData(null);
}

const data = await getPlatforms();
const platforms = Object.entries(data)
.filter(([, value]) => value.installed)
setPlatformData(data);

const unplugged = Object.entries(data)
.filter(([, value]) => value.installed && !value.plugged)
.map(([key]) => key as DiscordPlatform);

setAvailablePlatforms(platforms);
if (platforms[0]) {
setPlatforms([platforms[0]]);
}
setPlatforms(unplugged);
};

useEffect(() => {
Expand All @@ -58,7 +59,7 @@ export default function App(): React.ReactElement {
path="/platform"
element={
<ChoosePlatform
availablePlatforms={availablePlatforms}
platformData={platformData}
platforms={platforms}
setPlatforms={setPlatforms}
init={init}
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/steps/ChoosePlatform.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
background-color: var(--blurple);
}

.platform-warning {
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
margin-top: 10px;
border: 1px solid rgba(240, 178, 50, 1);
border-radius: 5px;
padding: 10px;
background-color: rgba(240, 178, 50, 0.1);
}

.platform-bottom {
width: 100%;
margin-top: 10px;
Expand Down
32 changes: 29 additions & 3 deletions src/renderer/steps/ChoosePlatform.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
import { Link } from "react-router-dom";
import { DiscordPlatform } from "../types";
import { DiscordPlatform, PlatformData } from "../types";
import "./ChoosePlatform.css";
import "../App.css";
import { PLATFORM_LABELS } from "../util";
import { useState } from "react";

export function ChoosePlatform({
availablePlatforms,
platformData,
platforms,
setPlatforms,
init,
}: {
availablePlatforms: DiscordPlatform[];
platformData: Record<DiscordPlatform, PlatformData> | null;
platforms: DiscordPlatform[];
setPlatforms: (platforms: DiscordPlatform[]) => void;
init: (reset?: boolean) => Promise<void>;
}): React.ReactElement {
const [isFetchingPlatforms, setIsFetchingPlatforms] = useState(false);

const availablePlatforms = (
platformData
? Object.entries(platformData)
.filter(([, v]) => v.installed)
.map((x) => x[0])
: []
) as DiscordPlatform[];

const pluggedPlatforms = (
platformData
? Object.entries(platformData)
.filter(([, v]) => v.plugged)
.map((x) => x[0])
: []
) as DiscordPlatform[];

const hasAlreadyPluggedPlatform = platforms.some((platform) =>
pluggedPlatforms.includes(platform),
);

const togglePlatform = (platform: DiscordPlatform): void => {
if (platforms.includes(platform)) {
setPlatforms(platforms.filter((p) => p !== platform));
Expand Down Expand Up @@ -52,6 +72,12 @@ export function ChoosePlatform({
))}
</div>
<div className="platform-note">Please quit Discord before continuing.</div>
{hasAlreadyPluggedPlatform && (
<div className="platform-warning">
One of the selected platforms is already plugged or has another client mod installed.
Plugging it again will overwrite the existing mod.
</div>
)}
<div className="platform-bottom">
<Link to="/action" className="button button-secondary">
Back
Expand Down

0 comments on commit 7db8f5d

Please sign in to comment.