From d752d6f22f1b1a44ed271fe63249c2ce11e04e89 Mon Sep 17 00:00:00 2001 From: EliteAsian <29520859+EliteAsian123@users.noreply.github.com> Date: Mon, 1 Jan 2024 14:33:58 -0500 Subject: [PATCH] Made the uninstall button work! --- src/components/DropdownButton/index.tsx | 7 +++- src/components/Launch/LaunchButton/index.tsx | 2 +- src/components/Queue/QueueEntry/Setlist.tsx | 8 ++-- src/components/Queue/QueueEntry/YARG.tsx | 12 +++--- .../Setlist/SetlistButton/index.tsx | 2 +- src/hooks/useSetlistData.ts | 30 ++++++++++++- src/hooks/useYARGVersion.ts | 31 +++++++++++++- src/tasks/Processors/Setlist.tsx | 34 ++++++++++++--- src/tasks/Processors/YARG.tsx | 42 ++++++++++++++----- 9 files changed, 134 insertions(+), 34 deletions(-) diff --git a/src/components/DropdownButton/index.tsx b/src/components/DropdownButton/index.tsx index 1daf8f4..557e868 100644 --- a/src/components/DropdownButton/index.tsx +++ b/src/components/DropdownButton/index.tsx @@ -42,14 +42,17 @@ const DropdownButton: React.FC = (props: DropdownProps) => { ; }; -type ItemProps = React.PropsWithChildren; +type ItemProps = React.PropsWithChildren<{ + onClick?: React.MouseEventHandler, +}>; const DropdownItem: React.FC = (props: ItemProps) => { const { children, + onClick } = props; - return + return {children} ; }; diff --git a/src/components/Launch/LaunchButton/index.tsx b/src/components/Launch/LaunchButton/index.tsx index bc48125..d063433 100644 --- a/src/components/Launch/LaunchButton/index.tsx +++ b/src/components/Launch/LaunchButton/index.tsx @@ -50,7 +50,7 @@ export function LaunchButton(props: LaunchButtonProps) { ; const dropdownChildren = <> - + version.uninstall()}> Uninstall ; diff --git a/src/components/Queue/QueueEntry/Setlist.tsx b/src/components/Queue/QueueEntry/Setlist.tsx index 6a554d1..f9aafe2 100644 --- a/src/components/Queue/QueueEntry/Setlist.tsx +++ b/src/components/Queue/QueueEntry/Setlist.tsx @@ -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 = ({ downloader, bannerMode }: Props) => { +const SetlistQueue: React.FC = ({ setlistTask, bannerMode }: Props) => { return } - versionChannel={downloader.version} + versionChannel={setlistTask.version} bannerMode={bannerMode} />; }; diff --git a/src/components/Queue/QueueEntry/YARG.tsx b/src/components/Queue/QueueEntry/YARG.tsx index 9e43cf6..48e2759 100644 --- a/src/components/Queue/QueueEntry/YARG.tsx +++ b/src/components/Queue/QueueEntry/YARG.tsx @@ -1,15 +1,15 @@ -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 = ({ downloader, bannerMode }: Props) => { +const YARGQueue: React.FC = ({ yargTask, bannerMode }: Props) => { const channelIconPath: { [key in YARGChannels]: string } = { "stable": StableYARGIcon, "nightly": NightlyYARGIcon @@ -17,9 +17,9 @@ const YARGQueue: React.FC = ({ downloader, bannerMode }: Props) => { return } - version={downloader.version} - versionChannel={downloader.channel.toUpperCase()} + icon={} + version={yargTask.version} + versionChannel={yargTask.channel.toUpperCase()} bannerMode={bannerMode} />; }; diff --git a/src/components/Setlist/SetlistButton/index.tsx b/src/components/Setlist/SetlistButton/index.tsx index bcb68cf..b29beea 100644 --- a/src/components/Setlist/SetlistButton/index.tsx +++ b/src/components/Setlist/SetlistButton/index.tsx @@ -49,7 +49,7 @@ export function SetlistButton(props: SetlistButtonProps) { ; const dropdownChildren = <> - + version.uninstall()}> Uninstall ; diff --git a/src/hooks/useSetlistData.ts b/src/hooks/useSetlistData.ts index a03b052..f6ed470 100644 --- a/src/hooks/useSetlistData.ts +++ b/src/hooks/useSetlistData.ts @@ -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"; @@ -18,6 +18,7 @@ export enum SetlistStates { export type SetlistVersion = { state: SetlistStates, download: () => Promise, + uninstall: () => Promise, payload?: TaskPayload } @@ -47,6 +48,7 @@ export const useSetlistData = (setlistData: SetlistData | undefined, setlistId: return { state, download: async () => {}, + uninstall: async () => {}, }; } @@ -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 }; }; \ No newline at end of file diff --git a/src/hooks/useYARGVersion.ts b/src/hooks/useYARGVersion.ts index 4d0680c..87b143e 100644 --- a/src/hooks/useYARGVersion.ts +++ b/src/hooks/useYARGVersion.ts @@ -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"; @@ -21,6 +21,7 @@ export type YARGVersion = { state: YARGStates, play: () => Promise, download: () => Promise, + uninstall: () => Promise, payload?: TaskPayload } @@ -52,6 +53,7 @@ export const useYARGVersion = (releaseData: ExtendedReleaseData | undefined, pro state, play: async () => {}, download: async () => {}, + uninstall: async () => {}, }; } @@ -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 }; }; \ No newline at end of file diff --git a/src/tasks/Processors/Setlist.tsx b/src/tasks/Processors/Setlist.tsx index 55d6b91..b3cf974 100644 --- a/src/tasks/Processors/Setlist.tsx +++ b/src/tasks/Processors/Setlist.tsx @@ -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 ; + } +} + +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 { return await invoke("download_and_install", { appName: "official_setlist", @@ -26,8 +38,18 @@ export class SetlistDownload extends BaseTask implements IBaseTask { sigUrls: [], }); } +} - getQueueEntry(bannerMode: boolean): React.ReactNode { - return ; +export class SetlistUninstall extends SetlistTask implements IBaseTask { + constructor(profile: string, version: string, onFinish: () => void) { + super(profile, version, onFinish); + } + + async start(): Promise { + return await invoke("uninstall", { + appName: "official_setlist", + version: this.version, + profile: this.profile + }); } } \ No newline at end of file diff --git a/src/tasks/Processors/YARG.tsx b/src/tasks/Processors/YARG.tsx index b019c9a..455db5a 100644 --- a/src/tasks/Processors/YARG.tsx +++ b/src/tasks/Processors/YARG.tsx @@ -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 ; + } +} + +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 { let sigUrls: string[] = []; if (this.sigUrl != null) { @@ -38,8 +50,18 @@ export class YARGDownload extends BaseTask implements IBaseTask { sigUrls: sigUrls, }); } +} - getQueueEntry(bannerMode: boolean): React.ReactNode { - return ; +export class YARGUninstall extends YARGTask implements IBaseTask { + constructor(channel: YARGChannels, version: string, profile: string, onFinish: () => void) { + super(channel, version, profile, onFinish); + } + + async start(): Promise { + return await invoke("uninstall", { + appName: "yarg", + version: this.version, + profile: this.profile + }); } } \ No newline at end of file