Skip to content

Commit

Permalink
Made the uninstall button work!
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Jan 1, 2024
1 parent 296134e commit d752d6f
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 34 deletions.
7 changes: 5 additions & 2 deletions src/components/DropdownButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ const DropdownButton: React.FC<DropdownProps> = (props: DropdownProps) => {
</DropdownMenu.Root>;
};

type ItemProps = React.PropsWithChildren;
type ItemProps = React.PropsWithChildren<{
onClick?: React.MouseEventHandler<HTMLDivElement>,
}>;

const DropdownItem: React.FC<ItemProps> = (props: ItemProps) => {
const {
children,
onClick
} = props;

return <DropdownMenu.Item className={styles.dropdown_item}>
return <DropdownMenu.Item className={styles.dropdown_item} onClick={onClick}>
{children}
</DropdownMenu.Item>;
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Launch/LaunchButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function LaunchButton(props: LaunchButtonProps) {
</>;

const dropdownChildren = <>
<DropdownItem>
<DropdownItem onClick={() => version.uninstall()}>
Uninstall
</DropdownItem>
</>;
Expand Down
8 changes: 4 additions & 4 deletions src/components/Queue/QueueEntry/Setlist.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { SetlistDownload } from "@app/tasks/Processors/Setlist";
import { SetlistTask } from "@app/tasks/Processors/Setlist";
import BaseQueue from "./base";
import SetlistIcon from "@app/assets/SourceIcons/Official.png";

interface Props {
downloader: SetlistDownload,
setlistTask: SetlistTask,
bannerMode: boolean,
}

const SetlistQueue: React.FC<Props> = ({ downloader, bannerMode }: Props) => {
const SetlistQueue: React.FC<Props> = ({ setlistTask, bannerMode }: Props) => {
return <BaseQueue
name="YARG Setlist"
icon={<img src={SetlistIcon} />}
versionChannel={downloader.version}
versionChannel={setlistTask.version}
bannerMode={bannerMode}
/>;
};
Expand Down
12 changes: 6 additions & 6 deletions src/components/Queue/QueueEntry/YARG.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { YARGDownload } from "@app/tasks/Processors/YARG";
import { YARGTask } from "@app/tasks/Processors/YARG";
import BaseQueue from "./base";
import StableYARGIcon from "@app/assets/StableYARGIcon.png";
import NightlyYARGIcon from "@app/assets/NightlyYARGIcon.png";
import { YARGChannels } from "@app/hooks/useYARGRelease";

interface Props {
downloader: YARGDownload,
yargTask: YARGTask,
bannerMode: boolean,
}

const YARGQueue: React.FC<Props> = ({ downloader, bannerMode }: Props) => {
const YARGQueue: React.FC<Props> = ({ yargTask, bannerMode }: Props) => {
const channelIconPath: { [key in YARGChannels]: string } = {
"stable": StableYARGIcon,
"nightly": NightlyYARGIcon
};

return <BaseQueue
name="YARG"
icon={<img src={channelIconPath[downloader.channel]} />}
version={downloader.version}
versionChannel={downloader.channel.toUpperCase()}
icon={<img src={channelIconPath[yargTask.channel]} />}
version={yargTask.version}
versionChannel={yargTask.channel.toUpperCase()}
bannerMode={bannerMode}
/>;
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Setlist/SetlistButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function SetlistButton(props: SetlistButtonProps) {
</>;

const dropdownChildren = <>
<DropdownItem>
<DropdownItem onClick={() => version.uninstall()}>
Uninstall
</DropdownItem>
</>;
Expand Down
30 changes: 28 additions & 2 deletions src/hooks/useSetlistData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSetlistState } from "@app/stores/SetlistStateStore";
import { SetlistData } from "./useSetlistRelease";
import { SetlistDownload } from "@app/tasks/Processors/Setlist";
import { SetlistDownload, SetlistUninstall } from "@app/tasks/Processors/Setlist";
import { useEffect } from "react";
import { invoke } from "@tauri-apps/api/tauri";
import { showErrorDialog, showInstallFolderDialog } from "@app/dialogs/dialogUtil";
Expand All @@ -18,6 +18,7 @@ export enum SetlistStates {
export type SetlistVersion = {
state: SetlistStates,
download: () => Promise<void>,
uninstall: () => Promise<void>,
payload?: TaskPayload
}

Expand Down Expand Up @@ -47,6 +48,7 @@ export const useSetlistData = (setlistData: SetlistData | undefined, setlistId:
return {
state,
download: async () => {},
uninstall: async () => {},
};
}

Expand Down Expand Up @@ -78,5 +80,29 @@ export const useSetlistData = (setlistData: SetlistData | undefined, setlistId:
}
};

return { state, download, payload };
const uninstall = async () => {
if (!setlistData || state === SetlistStates.DOWNLOADING) return;

// You can't uninstall if the launcher is not initialized
if (!await invoke("is_initialized")) return;

setState(SetlistStates.DOWNLOADING);

try {
const downloader = new SetlistUninstall(
setlistData.id,
setlistData.version,
() => { setState(SetlistStates.NEW_UPDATE); }
);

addTask(downloader);
} catch (e) {
setState(SetlistStates.ERROR);

showErrorDialog(e as string);
console.error(e);
}
};

return { state, download, uninstall, payload };
};
31 changes: 29 additions & 2 deletions src/hooks/useYARGVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExtendedReleaseData, getYARGReleaseZip, getYARGReleaseSigFromZipURL, YA
import { invoke } from "@tauri-apps/api/tauri";
import { type } from "@tauri-apps/api/os";
import { useYARGState } from "@app/stores/YARGStateStore";
import { YARGDownload } from "@app/tasks/Processors/YARG";
import { YARGDownload, YARGUninstall } from "@app/tasks/Processors/YARG";
import { showErrorDialog, showInstallFolderDialog } from "@app/dialogs/dialogUtil";
import { addTask, useTask } from "@app/tasks";
import { usePayload, TaskPayload } from "@app/tasks/payload";
Expand All @@ -21,6 +21,7 @@ export type YARGVersion = {
state: YARGStates,
play: () => Promise<void>,
download: () => Promise<void>,
uninstall: () => Promise<void>,
payload?: TaskPayload
}

Expand Down Expand Up @@ -52,6 +53,7 @@ export const useYARGVersion = (releaseData: ExtendedReleaseData | undefined, pro
state,
play: async () => {},
download: async () => {},
uninstall: async () => {},
};
}

Expand Down Expand Up @@ -115,5 +117,30 @@ export const useYARGVersion = (releaseData: ExtendedReleaseData | undefined, pro
}
};

return { state, play, download, payload };
const uninstall = async () => {
if (!releaseData || state === YARGStates.DOWNLOADING) return;

// You can't uninstall if the launcher is not initialized
if (!await invoke("is_initialized")) return;

setState(YARGStates.DOWNLOADING);

try {
const downloader = new YARGUninstall(
releaseData.channel,
releaseData.tag_name,
profileName,
() => { setState(YARGStates.NEW_UPDATE); }
);

addTask(downloader);
} catch (e) {
setState(YARGStates.ERROR);

showErrorDialog(e as string);
console.error(e);
}
};

return { state, play, download, uninstall, payload };
};
34 changes: 28 additions & 6 deletions src/tasks/Processors/Setlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@ import { invoke } from "@tauri-apps/api/tauri";
import { BaseTask, IBaseTask } from "./base";
import SetlistQueue from "@app/components/Queue/QueueEntry/Setlist";

export class SetlistDownload extends BaseTask implements IBaseTask {
zipUrls: string[];
export abstract class SetlistTask extends BaseTask {
profile: string;
version: string;
onFinish: () => void;

constructor(zipUrls: string[], profile: string, version: string, onFinish: () => void) {
constructor(profile: string, version: string, onFinish: () => void) {
super("setlist", profile);

this.zipUrls = zipUrls;
this.profile = profile;
this.version = version;
this.onFinish = onFinish;
}

getQueueEntry(bannerMode: boolean): React.ReactNode {
return <SetlistQueue setlistTask={this} bannerMode={bannerMode} />;
}
}

export class SetlistDownload extends SetlistTask implements IBaseTask {
zipUrls: string[];

constructor(zipUrls: string[], profile: string, version: string, onFinish: () => void) {
super(profile, version, onFinish);

this.zipUrls = zipUrls;
}

async start(): Promise<void> {
return await invoke("download_and_install", {
appName: "official_setlist",
Expand All @@ -26,8 +38,18 @@ export class SetlistDownload extends BaseTask implements IBaseTask {
sigUrls: [],
});
}
}

getQueueEntry(bannerMode: boolean): React.ReactNode {
return <SetlistQueue downloader={this} bannerMode={bannerMode} />;
export class SetlistUninstall extends SetlistTask implements IBaseTask {
constructor(profile: string, version: string, onFinish: () => void) {
super(profile, version, onFinish);
}

async start(): Promise<void> {
return await invoke("uninstall", {
appName: "official_setlist",
version: this.version,
profile: this.profile
});
}
}
42 changes: 32 additions & 10 deletions src/tasks/Processors/YARG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@ import { BaseTask, IBaseTask } from "./base";
import YARGQueue from "@app/components/Queue/QueueEntry/YARG";
import { YARGChannels } from "@app/hooks/useYARGRelease";

export class YARGDownload extends BaseTask implements IBaseTask {
zipUrl: string;
sigUrl?: string;
export abstract class YARGTask extends BaseTask {
channel: YARGChannels;
version: string;
profile: string;
onFinish: () => void;

constructor(zipUrl: string, sigUrl: string | undefined, channel: YARGChannels, version: string,
profile: string, onFinish: () => void) {

constructor(channel: YARGChannels, version: string, profile: string, onFinish: () => void) {
super("yarg", profile);

this.zipUrl = zipUrl;
this.sigUrl = sigUrl;
this.channel = channel;
this.version = version;
this.profile = profile;
this.onFinish = onFinish;
}

getQueueEntry(bannerMode: boolean): React.ReactNode {
return <YARGQueue yargTask={this} bannerMode={bannerMode} />;
}
}

export class YARGDownload extends YARGTask implements IBaseTask {
zipUrl: string;
sigUrl?: string;

constructor(zipUrl: string, sigUrl: string | undefined, channel: YARGChannels, version: string,
profile: string, onFinish: () => void) {

super(channel, version, profile, onFinish);

this.zipUrl = zipUrl;
this.sigUrl = sigUrl;
}

async start(): Promise<void> {
let sigUrls: string[] = [];
if (this.sigUrl != null) {
Expand All @@ -38,8 +50,18 @@ export class YARGDownload extends BaseTask implements IBaseTask {
sigUrls: sigUrls,
});
}
}

getQueueEntry(bannerMode: boolean): React.ReactNode {
return <YARGQueue downloader={this} bannerMode={bannerMode} />;
export class YARGUninstall extends YARGTask implements IBaseTask {
constructor(channel: YARGChannels, version: string, profile: string, onFinish: () => void) {
super(channel, version, profile, onFinish);
}

async start(): Promise<void> {
return await invoke("uninstall", {
appName: "yarg",
version: this.version,
profile: this.profile
});
}
}

0 comments on commit d752d6f

Please sign in to comment.