Skip to content

Commit

Permalink
chore: ui for setting steam install path complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Aug 19, 2023
1 parent a783ee4 commit 8be49ee
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 39 deletions.
4 changes: 3 additions & 1 deletion src/Stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const steamGridDBKey = writable("");
export const needsSteamKey = writable(true);
export const steamKey = writable("");

export const needsSteamInstallPath = writable(true);
export const steamInstallPath = writable("");

export const selectedResultPage = writable(0);
Expand Down Expand Up @@ -107,6 +106,9 @@ export const cleanConflicts: Writable<CleanConflict[]> = writable([]);
export const showUpdateModal = writable(false);
export const updateManifest: Writable<UpdateManifest> = writable(null);

export const showSteamPathModal = writable(false);
export const steamPathModalClose = writable(async () => {});

export const showDialogModal = writable(false);
export const dialogModalTitle = writable("");
export const dialogModalMessage = writable("");
Expand Down
35 changes: 35 additions & 0 deletions src/components/interactables/FileButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script lang="ts">
import type { Placement } from "tippy.js";
import IconButton from "./IconButton.svelte";
import { dialog } from "@tauri-apps/api";
export let label: string;
export let tooltipPosition: Placement = "top-end";
export let width = "22px";
export let height = "22px";
export let onChange: (filepath: string) => void;
export let disabled = false;
export let highlight = false;
export let warn = false;
async function onClick(e: MouseEvent) {
const path = await dialog.open({
title: "Select your steam install",
directory: true,
multiple: false
});
if (path && path != "") onChange(path as string);
}
</script>

<!-- svelte-ignore a11y-click-events-have-key-events -->
<IconButton label={label} tooltipPosition={tooltipPosition} width={width} height={height} onClick={onClick} disabled={disabled} highlight={highlight} warn={warn}>
<svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512">
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path d="M8 256a56 56 0 1 1 112 0A56 56 0 1 1 8 256zm160 0a56 56 0 1 1 112 0 56 56 0 1 1 -112 0zm216-56a56 56 0 1 1 0 112 56 56 0 1 1 0-112z"/>
</svg>
</IconButton>

<style>
</style>
2 changes: 1 addition & 1 deletion src/components/modals/DialogModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{:else}
<svg xmlns="http://www.w3.org/2000/svg" height="3em" viewBox="0 0 512 512" fill="#e24a4a">
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm0-384c13.3 0 24 10.7 24 24V264c0 13.3-10.7 24-24 24s-24-10.7-24-24V152c0-13.3 10.7-24 24-24zM224 352a32 32 0 1 1 64 0 32 32 0 1 1 -64 0z"/>
<path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z"/>
</svg>
{/if}
</div>
Expand Down
77 changes: 77 additions & 0 deletions src/components/modals/SteamPathModal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<script lang="ts">
import { steamInstallPath, steamPathModalClose } from "../../Stores";
import { LogController } from "../../lib/controllers/LogController";
import { ToastController } from "../../lib/controllers/ToastController";
import { SettingsManager } from "../../lib/utils/SettingsManager";
import Button from "../interactables/Button.svelte";
import VerticalSpacer from "../spacers/VerticalSpacer.svelte";
import ModalBody from "./modal-utils/ModalBody.svelte";
import SettingsFilePathEntry from "./settings/SettingsFilePathEntry.svelte";
let canSave = false;
let steamInstallLocation = $steamInstallPath;
async function saveInstallLocation() {
LogController.log("Setting Steam Install Location...");
$steamInstallPath = steamInstallLocation;
await SettingsManager.updateSetting("steamInstallPath", steamInstallLocation);
LogController.log("Steam Install Location set.");
canSave = false;
ToastController.showSuccessToast("Steam Install Location saved!");
await $steamPathModalClose();
}
/**
* Function to run on steam install location change.
* @param path The updated installation path.
*/
function onInstallLocationChange(path: string): void {
steamInstallLocation = path;
canSave = true;
}
</script>

<ModalBody title={"Choose Your Steam Install Path"} canClose={false}>
<div class="content">
<VerticalSpacer />
<VerticalSpacer />
<SettingsFilePathEntry
label="Steam Install Path"
description={`The root of your Steam installation. The default on Windows is <b>C:/Program Files (x86)/Steam</b> and <b>~/.steam/Steam</b> on Linux.`}
value={steamInstallLocation}
onChange={onInstallLocationChange}
required
/>

<div class="buttons">
<Button label="Save Changes" onClick={saveInstallLocation} width="100%" disabled={!canSave} />
</div>
</div>
</ModalBody>

<style>
.content {
width: 600px;
height: calc(100% - 60px);
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
}
.buttons {
margin-top: 14px;
margin-bottom: 7px;
width: calc(100% - 14px);
display: flex;
justify-content: space-around;
justify-self: flex-end;
}
</style>
84 changes: 84 additions & 0 deletions src/components/modals/settings/SettingsFilePathEntry.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<script lang="ts">
import { open } from "@tauri-apps/api/shell";
import TextInput from "../../interactables/TextInput.svelte";
import VerticalSpacer from "../../spacers/VerticalSpacer.svelte";
import FileButton from "../../interactables/FileButton.svelte";
import HorizontalSpacer from "../../spacers/HorizontalSpacer.svelte";
export let label: string;
export let description: string;
export let required: boolean = false;
export let value: string;
export let notes: string = "";
export let onChange: (path: string) => void = () => {};
function changeWrapper(e: Event) {
onChange((e.currentTarget as HTMLInputElement).value);
}
/**
* Handles click events to redirect to the browser.
* @param e The click event.
*/
function clickListener(e: Event) {
const origin = (e.target as Element).closest(`a`);
if (origin) {
e.preventDefault();
const href = origin.href;
open(href);
}
}
</script>

<div class="setting">
<h1 class="label">{label}</h1>
<div class="inputs">
<TextInput placeholder={"~/something/something"} onInput={changeWrapper} width="{188}" bind:value={value} />
<HorizontalSpacer />
<FileButton label="Select Folder" tooltipPosition={"right"} onChange={onChange} />
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="description" on:click={clickListener}>
<b>Usage:</b><br/>
{@html description}<br/>

{#if notes != ""}
<VerticalSpacer />
<b>Notes:</b><br/>
{@html notes}
{/if}

<VerticalSpacer />
<b>Required:</b> {required ? "Yes" : "No"}<br/>
</div>
</div>

<style>
.setting {
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 0px 14px;
background-color: var(--background-dark);
padding: 6px;
border-radius: 4px;
}
.label {
margin-top: 0px;
font-size: 18px;
}
.inputs {
display: flex;
align-items: center;
}
.description {
line-height: 18px;
font-size: 14px;
margin: 7px 0px;
}
</style>
26 changes: 25 additions & 1 deletion src/components/modals/settings/SettingsModal.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<script lang="ts">
import { steamKey, steamGridDBKey, needsSteamKey, needsSGDBAPIKey, activeUserId } from "../../../Stores";
import { steamKey, steamGridDBKey, needsSteamKey, needsSGDBAPIKey, activeUserId, steamInstallPath } from "../../../Stores";
import { LogController } from "../../../lib/controllers/LogController";
import { ToastController } from "../../../lib/controllers/ToastController";
import { SettingsManager } from "../../../lib/utils/SettingsManager";
import Button from "../../interactables/Button.svelte";
import VerticalSpacer from "../../spacers/VerticalSpacer.svelte";
import ModalBody from "../modal-utils/ModalBody.svelte";
import SettingsEntry from "./SettingsEntry.svelte";
import SettingsFilePathEntry from "./SettingsFilePathEntry.svelte";
export let onClose: () => void;
let canSave = false;
let steamGridKey = $steamGridDBKey;
let steamAPIKey = $steamKey;
let steamInstallLocation = $steamInstallPath;
async function saveSettings() {
LogController.log("Saving settings...");
Expand All @@ -30,6 +32,10 @@
steamUserKeyMap[$activeUserId] = steamAPIKey;
await SettingsManager.updateSetting("steamApiKeyMap", steamUserKeyMap);
$steamInstallPath = steamInstallLocation !== "" ? steamInstallLocation : $steamInstallPath;
if (steamInstallLocation !== "") await SettingsManager.updateSetting("steamInstallPath", steamInstallLocation);
LogController.log("Saved settings.");
canSave = false;
Expand Down Expand Up @@ -79,10 +85,28 @@
canSave = true;
}
}
/**
* Function to run on steam install location change.
* @param path The updated installation path.
*/
function onInstallLocationChange(path: string): void {
steamInstallLocation = path;
canSave = true;
}
</script>

<ModalBody title={"Settings"} onClose={onClose}>
<div class="content">
<VerticalSpacer />
<VerticalSpacer />
<SettingsFilePathEntry
label="Steam Install Path"
description={`The root of your Steam installation. The default on Windows is <b>C:/Program Files (x86)/Steam</b> and <b>~/.steam/Steam</b> on Linux. You must restart after changing this.`}
value={steamInstallLocation}
onChange={onInstallLocationChange}
required
/>
<VerticalSpacer />
<VerticalSpacer />
<SettingsEntry
Expand Down
78 changes: 43 additions & 35 deletions src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ToastController } from "./ToastController";
import { SettingsManager } from "../utils/SettingsManager";
import { LogController } from "./LogController";
import { get } from "svelte/store";
import { GridTypes, Platforms, activeUserId, appLibraryCache, canSave, cleanConflicts, currentPlatform, customGameNames, gridModalInfo, gridType, hiddenGameIds, isOnline, loadingGames, manualSteamGames, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalLogoPositions, originalSteamShortcuts, requestTimeoutLength, selectedGameAppId, selectedGameName, showCleanConflictDialog, showDialogModal, showGridModal, showSettingsModal, steamGames, steamGridDBKey, steamInstallPath, steamKey, steamLogoPositions, steamShortcuts, steamUsers, theme, unfilteredLibraryCache } from "../../Stores";
import { GridTypes, Platforms, activeUserId, appLibraryCache, canSave, cleanConflicts, currentPlatform, customGameNames, gridModalInfo, gridType, hiddenGameIds, isOnline, loadingGames, manualSteamGames, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalLogoPositions, originalSteamShortcuts, requestTimeoutLength, selectedGameAppId, selectedGameName, showCleanConflictDialog, showDialogModal, showGridModal, showSettingsModal, showSteamPathModal, steamGames, steamGridDBKey, steamInstallPath, steamKey, steamLogoPositions, steamPathModalClose, steamShortcuts, steamUsers, theme, unfilteredLibraryCache } from "../../Stores";
import { CacheController } from "./CacheController";
import { RustInterop } from "./RustInterop";
import type { SGDBImage } from "../models/SGDB";
Expand Down Expand Up @@ -76,41 +76,49 @@ function getIdFromGridName(gridName: string): [string, string] {
}
}

/**
* Handles showing the Steam install path selection dialog.
*/
async function steamDialogSequence(): Promise<void> {
return new Promise<void>(async (resolve) => {
const hasSteamInstalled = await DialogController.ask("Steam Not Found", "WARNING", "SARM could not locate Steam. Do you have it installed?", "Yes", "No");

if (hasSteamInstalled) {
showSteamPathModal.set(true);
steamPathModalClose.set(async () => resolve());
} else {
await DialogController.message("SARM Could Not Initialize", "ERROR", "Please install Steam and login once, then restart SARM.", "Ok");
await exit(0);
resolve()
}
});
}

/**
* Handles determining the Steam installation path.
* @param savedInstallPath The current saved install path.
*/
async function findSteamPath(savedInstallPath: string): Promise<void> {
const returnedInstallPath = await RustInterop.addSteamToScope();

// ! for some reason this is really slow. maybe the fs.exists? May also be that my wifi is shit
// if (savedInstallPath !== "") {
// if (await fs.exists(savedInstallPath)) {
// const steamInstallPathAdded = await RustInterop.addPathToScope(savedInstallPath);

// if (steamInstallPathAdded) {
// steamInstallPath.set(savedInstallPath);
// } else {
// // TODO: figure out what to do here. path exists but failed to add it to scope
// }
// } else {
// // * show modal and proceed accordingly
// }
// } else {
// const returnedInstallPath = await RustInterop.addSteamToScope();

// if (returnedInstallPath === "") {
// // TODO: figure out what to do here. path exists but failed to add it to scope
// } else if (returnedInstallPath === "DNE") {
// // let hit_ok = MessageDialogBuilder::new("SARM Initialization Error", "Steam was not found on your PC. Steam needs to be installed for SARM to work.")
// // .buttons(MessageDialogButtons::Ok)
// // .show();

// // if hit_ok {
// // exit(1);
// // }
// // TODO: prompt user saying steam was not found, and ask if steam is installed. if yes, show custom field, otherwise, ask to install then exit app.
// } else {
// steamInstallPath.set(returnedInstallPath);
// await SettingsManager.updateSetting("steamInstallPath", returnedInstallPath);
// }
// }
if (savedInstallPath !== "") {
const steamInstallPathAdded = await RustInterop.addPathToScope(savedInstallPath);
if (steamInstallPathAdded && await fs.exists(savedInstallPath)) {
steamInstallPath.set(savedInstallPath);
} else {
await steamDialogSequence();
}
} else {
const returnedInstallPath = await RustInterop.addSteamToScope();

if (returnedInstallPath === "") {
await DialogController.message("Unrecoverable Error", "ERROR", "A Steam installation was found but could not be added to scope. Please restart, and if the problem persists, open an issue on SARM's GitHub repository.", "Ok");
await exit(0);
} else if (returnedInstallPath === "DNE") {
await steamDialogSequence();
} else {
steamInstallPath.set(returnedInstallPath);
await SettingsManager.updateSetting("steamInstallPath", returnedInstallPath);
}
}
}

/**
Expand Down
Loading

0 comments on commit 8be49ee

Please sign in to comment.