[feat-578] setup protonFolder on startup

This commit is contained in:
silentrald
2024-09-22 15:21:19 +08:00
parent 0398a957ad
commit de7a054f89
19 changed files with 275 additions and 16 deletions
@@ -0,0 +1,99 @@
import { lastValueFrom } from "rxjs";
import { useState } from "react";
import { useTranslation } from "renderer/hooks/use-translation.hook";
import { useService } from "renderer/hooks/use-service.hook";
import { IpcService } from "renderer/services/ipc.service";
import { ModalComponent, ModalExitCode } from "renderer/services/modale.service";
import { NotificationService } from "renderer/services/notification.service";
import { StaticConfigurationService } from "renderer/services/static-configuration.service";
import { BsmButton } from "renderer/components/shared/bsm-button.component";
import { SettingContainer } from "renderer/components/settings/setting-container.component";
export const LinuxSetupModal: ModalComponent<{}, {}> = ({ resolver }) => {
const t = useTranslation();
const ipcService = useService(IpcService);
const notificationService = useService(NotificationService);
const staticConfigService = useService(StaticConfigurationService);
const [protonFolder, setProtonFolder] = useState("");
const validateFields = () => {
return !!protonFolder;
}
const selectProtonPath = async () => {
const response = await lastValueFrom(ipcService.sendV2("choose-folder"));
if (response.canceled || !response.filePaths?.length) {
return;
}
const path = response.filePaths[0];
try {
await staticConfigService.set("proton-folder", path);
setProtonFolder(path);
validateFields();
} catch (error: any) {
notificationService.notifyError({
title: "pages.settings.proton-folder.errors.title",
desc: ["invalid-folder"].includes(error?.code)
? `pages.settings.proton-folder.errors.${error.code}`
: "misc.unknown"
});
}
}
const onConfirmButtonPressed = async () => {
resolver({
exitCode: ModalExitCode.COMPLETED
});
}
return (
<form
className="max-w-xl w-max"
onSubmit={event => {
event.preventDefault();
onConfirmButtonPressed();
}}>
<h1 className="tracking-wide w-full uppercase text-3xl text-center mb-4">
{t("modals.linux-setup.title")}
</h1>
<SettingContainer
os="linux"
title="modals.linux-setup.proton-folder"
description="modals.linux-setup.proton-folder-description"
>
<div className="relative flex items-center justify-between w-full h-8 bg-light-main-color-1 dark:bg-main-color-1 rounded-md pl-2 py-1">
<span
className="block text-ellipsis overflow-hidden min-w-0 whitespace-nowrap"
title={protonFolder}
>
{protonFolder}
</span>
<BsmButton
onClick={selectProtonPath}
className="shrink-0 whitespace-nowrap mr-2 px-2 font-bold italic text-sm rounded-md"
text="modals.linux-setup.choose-folder"
withBar={false}
/>
</div>
</SettingContainer>
<div className="h-8 grid grid-flow-col grid-cols-1">
<BsmButton
typeColor="primary"
className="rounded-md text-center transition-all"
type="submit"
withBar={false}
text="misc.confirm"
disabled={!validateFields()}
/>
</div>
</form>
)
}
+22 -1
View File
@@ -6,7 +6,8 @@ import { InstallationLocationService } from "./installation-location.service";
import { IpcService } from "./ipc.service";
import { ModalService } from "./modale.service";
import { AskInstallPathModal } from "renderer/components/modal/modal-types/ask-install-path.component";
import { AskInstallPathModal } from "renderer/components/modal/modal-types/setup/ask-install-path.component";
import { LinuxSetupModal } from "renderer/components/modal/modal-types/setup/linux-setup-modal.component";
// Handle setup modals/prompts, ordering of the modals/prompts may be done here
export class SetupService {
@@ -35,6 +36,10 @@ export class SetupService {
try {
// NOTE: for modal sequencing
await this.checkInstallationPath();
if (window.electron.platform === "linux") {
await this.checkProtonFolder();
}
} catch (error) {
logRenderError(error);
}
@@ -61,4 +66,20 @@ export class SetupService {
}
}
private async checkProtonFolder(): Promise<void> {
try {
const valid = await lastValueFrom(this.ipcService.sendV2("linux.verify-proton-folder"));
if (valid) {
return;
}
await this.modalService.openModal(
LinuxSetupModal,
{ closable: false }
);
} catch (error) {
logRenderError(error);
}
}
}