[feature-274] Refactoring downloaders service + handle importing Oculus version + logout from steam and oculus in settings + other things

This commit is contained in:
MathieuG-P
2023-10-27 02:00:24 +02:00
parent e9780a60f4
commit 0a1e1efcd9
33 changed files with 794 additions and 597 deletions
@@ -34,6 +34,8 @@ export const ChooseStore: ModalComponent<BsStore> = ({ resolver }) => {
}
})();
// TODO : Translate
return (
<form className="flex flex-col gap-3">
<h1 className="text-3xl uppercase tracking-wide w-full text-center text-gray-800 dark:text-gray-200">{t("which platform ?")}</h1>
@@ -41,7 +43,7 @@ export const ChooseStore: ModalComponent<BsStore> = ({ resolver }) => {
<div className="flex flex-row w-full flex-grow gap-4">
<div className="flex flex-col flex-grow basis-0 gap-2 text-center px-5 pt-3 pb-1 rounded-md border-main-color-3 border-2 cursor-pointer" onMouseEnter={() => setOculusHover(true)} onMouseLeave={() => setOculusHover(false)} onClick={() => chooseStore(BsStore.OCULUS)} style={{backgroundColor: oculusHover ? bg.dim : bg.bright}}>
<OculusIcon className="flex-grow aspect-square text-black bg-white rounded-full p-5"/>
<h2 className="font-bold">Oculus PC</h2>
<h2 className="font-bold">Oculus Store (PC)</h2>
</div>
<div className="flex flex-col flex-grow basis-0 gap-2 text-center px-5 pt-3 pb-1 rounded-md border-main-color-3 border-2 cursor-pointer" onMouseEnter={() => setSteamHover(true)} onMouseLeave={() => setSteamHover(false)} onClick={() => chooseStore(BsStore.STEAM)} style={{backgroundColor: steamHover ? bg.dim : bg.bright}}>
<SteamIcon className="flex-grow"/>
@@ -3,18 +3,34 @@ import { BsmImage } from "renderer/components/shared/bsm-image.component";
import { useTranslation } from "renderer/hooks/use-translation.hook";
import { ModalComponent, ModalExitCode } from "renderer/services/modale.service";
import BeatImpatient from "../../../../../assets/images/apngs/beat-impatient.png";
import { BsmCheckbox } from "renderer/components/shared/bsm-checkbox.component";
import Tippy from "@tippyjs/react";
import { useState } from "react";
import { BsStore } from "shared/models/bs-store.enum";
export const ImportVersionModal: ModalComponent<void> = ({ resolver }) => {
export const ImportVersionModal: ModalComponent<BsStore> = ({ resolver }) => {
const t = useTranslation();
const [isOculus, setIsOculus] = useState(false);
const submit = () => {
resolver({ exitCode: ModalExitCode.COMPLETED, data: isOculus ? BsStore.OCULUS : BsStore.STEAM });
}
return (
<form>
<h1 className="text-3xl uppercase tracking-wide w-full text-center text-gray-800 dark:text-gray-200">{t("modals.bs-import-version.title")}</h1>
<BsmImage className="mx-auto h-20" image={BeatImpatient} />
<p className="max-w-sm text-gray-800 dark:text-gray-200">{t("modals.bs-import-version.description")}</p>
<div className="grid grid-flow-col grid-cols-2 gap-4 mt-4">
<Tippy content="Cocher si c'est une version Oculus" placement="right" arrow={false} className="!bg-neutral-900 font-bold">
<div className="relative flex flex-row items-center gap-1.5 mb-4 mt-3 cursor-help w-fit">
<BsmCheckbox className="relative h-5 w-5 z-[1]" checked={isOculus} onChange={checked => setIsOculus(checked)}/>
<span className="font-bold italic">Version Oculus</span> {/* TODO Translate */}
</div>
</Tippy>
<div className="grid grid-flow-col grid-cols-2 gap-4">
<BsmButton typeColor="cancel" className="rounded-md text-center transition-all" onClick={() => resolver({ exitCode: ModalExitCode.CANCELED })} withBar={false} text="misc.cancel" />
<BsmButton typeColor="primary" className="rounded-md text-center transition-all" onClick={() => resolver({ exitCode: ModalExitCode.COMPLETED })} withBar={false} text="modals.bs-import-version.buttons.submit" />
<BsmButton typeColor="primary" className="rounded-md text-center transition-all" onClick={submit} withBar={false} text="modals.bs-import-version.buttons.submit" />
</div>
</form>
);
@@ -1,6 +1,5 @@
import { BSVersion } from "shared/bs-version.interface";
import { Link, useLocation } from "react-router-dom";
import { SteamDownloaderService } from "renderer/services/bs-downgrade/steam-downloader.service";
import { useState } from "react";
import { distinctUntilChanged, map, of, Subscription, switchMap } from "rxjs";
import { BSLauncherService, LaunchMods } from "renderer/services/bs-launcher.service";
@@ -15,13 +14,17 @@ import Tippy from "@tippyjs/react";
import { useService } from "renderer/hooks/use-service.hook";
import equal from "fast-deep-equal";
import { useOnUpdate } from "renderer/hooks/use-on-update.hook";
import { BsDownloaderService } from "renderer/services/bs-version-download/bs-downloader.service";
import { ProgressBarService } from "renderer/services/progress-bar.service";
export function BsVersionItem(props: { version: BSVersion }) {
const downloaderService = useService(SteamDownloaderService);
const bsDownloader = useService(BsDownloaderService);
const verionManagerService = useService(BSVersionManagerService);
const launcherService = useService(BSLauncherService);
const configService = useService(ConfigurationService);
const bsUninstallerService = useService(BSUninstallerService);
const progressBar = useService(ProgressBarService);
const { state } = useLocation() as { state: BSVersion };
const { fontSize, ref } = useFitText();
@@ -33,14 +36,14 @@ export function BsVersionItem(props: { version: BSVersion }) {
useOnUpdate(() => {
const subs: Subscription[] = []
subs.push(downloaderService.currentBsVersionDownload$.pipe(map(download => equal(download, props.version)), distinctUntilChanged()).subscribe(isDownloading => {
subs.push(bsDownloader.downloadingVersion$.pipe(map(download => equal(download, props.version)), distinctUntilChanged()).subscribe(isDownloading => {
setIsDownloading(() => isDownloading);
}));
subs.push(downloaderService.currentBsVersionDownload$.pipe(
subs.push(bsDownloader.downloadingVersion$.pipe(
map(download => equal(download, props.version)),
distinctUntilChanged(),
switchMap(isDownloading => isDownloading ? downloaderService.downloadProgress$ : of(0)),
switchMap(isDownloading => isDownloading ? progressBar.progress$ : of(0)),
).subscribe(progress => {
setDownloadProgress(() => progress);
}));
@@ -62,9 +65,9 @@ export function BsVersionItem(props: { version: BSVersion }) {
};
const cancel = () => {
const versionDownload = downloaderService.currentBsVersionDownload$.value;
const wasVerification = downloaderService.isVerification;
downloaderService.stopDownload().then(() => {
const versionDownload = bsDownloader.downloadingVersion;
const wasVerification = bsDownloader.isVerifying;
bsDownloader.stopDownload().then(() => {
if(wasVerification){ return; }
bsUninstallerService.uninstall(versionDownload).then(res => res && verionManagerService.askInstalledVersions());
});
@@ -11,15 +11,15 @@ import { useThemeColor } from "renderer/hooks/use-theme-color.hook";
import Tippy from "@tippyjs/react";
import { useTranslation } from "renderer/hooks/use-translation.hook";
import { useService } from "renderer/hooks/use-service.hook";
import { SteamDownloaderService } from "renderer/services/bs-downgrade/steam-downloader.service";
import { distinctUntilChanged } from "rxjs";
import equal from "fast-deep-equal";
import { BsDownloaderService } from "renderer/services/bs-version-download/bs-downloader.service";
export function NavBar() {
const versionManager = useService(BSVersionManagerService);
const versionDownloader = useService(SteamDownloaderService);
const versionDownloader = useService(BsDownloaderService);
const downloadingVersion = useObservable(versionDownloader.currentBsVersionDownload$.pipe(distinctUntilChanged(equal)));
const downloadingVersion = useObservable(versionDownloader.downloadingVersion$.pipe(distinctUntilChanged(equal)));
const installedVersions = useObservable(versionManager.installedVersions$);
const color = useThemeColor("first-color");
@@ -10,6 +10,7 @@ import { LaunchModToogle } from "./launch-mod-toogle.component";
import BSLogo from "../../../../../../assets/images/apngs/bs-logo.png";
import { BsmImage } from "renderer/components/shared/bsm-image.component";
import { useService } from "renderer/hooks/use-service.hook";
import { BsStore } from "shared/models/bs-store.enum";
type Props = { version: BSVersion };
@@ -73,7 +74,7 @@ export function LaunchSlide({ version }: Props) {
<h1 className="relative text-4xl font-bold italic -top-3">{version.name ? `${version.BSVersion} - ${version.name}` : version.BSVersion}</h1>
</div>
<div className="grid grid-flow-col gap-6">
{!version.oculus && <LaunchModToogle infoText="pages.version-viewer.launch-mods.oculus-description" icon="oculus" onClick={() => setMode(LaunchMods.OCULUS_MOD, !oculusMode)} active={oculusMode} text="pages.version-viewer.launch-mods.oculus" />}
{!(version.oculus || version.store === BsStore.OCULUS) && <LaunchModToogle infoText="pages.version-viewer.launch-mods.oculus-description" icon="oculus" onClick={() => setMode(LaunchMods.OCULUS_MOD, !oculusMode)} active={oculusMode} text="pages.version-viewer.launch-mods.oculus" />}
<LaunchModToogle infoText="pages.version-viewer.launch-mods.desktop-description" icon="desktop" onClick={() => setMode(LaunchMods.DESKTOP_MOD, !desktopMode)} active={desktopMode} text="pages.version-viewer.launch-mods.desktop" />
<LaunchModToogle infoText="pages.version-viewer.launch-mods.debug-description" icon="terminal" onClick={() => setMode(LaunchMods.DEBUG_MOD, !debugMode)} active={debugMode} text="pages.version-viewer.launch-mods.debug" />
</div>