-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from yep-tf2/tauri_configurable-demos-dir
Add UI for configuring the demos directory
- Loading branch information
Showing
10 changed files
with
255 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use serde::Serialize; | ||
use steamlocate::SteamDir; | ||
use tauri::State; | ||
|
||
use crate::AppState; | ||
|
||
#[derive(Clone, Debug, Serialize)] | ||
pub enum TF2DirError { | ||
/// Could not find Steam installed on the current system | ||
SteamNotFound, | ||
/// Found Steam, but could not find TF2 within the Steam installation directory | ||
Tf2NotFound, | ||
} | ||
|
||
#[tauri::command] | ||
pub fn get_tf2_dir(_state: State<'_, AppState>) -> Result<String, TF2DirError> { | ||
const TF2_ID: u32 = 440; | ||
|
||
let mut steam_dir = SteamDir::locate().ok_or(TF2DirError::SteamNotFound)?; | ||
let tf2_dir = steam_dir.app(&TF2_ID).ok_or(TF2DirError::Tf2NotFound)?; | ||
|
||
Ok(String::from(tf2_dir.path.to_string_lossy())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod demos; | ||
pub mod files; | ||
pub mod rcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,62 @@ | ||
import { Link } from "react-router-dom"; | ||
import useStore from "../../hooks/useStore"; | ||
import { Button, createStyles, ScrollArea, TextInput } from "@mantine/core"; | ||
import { open as dialogOpen } from "@tauri-apps/api/dialog"; | ||
|
||
const useStyles = createStyles({ | ||
root: { | ||
margin: "12px", | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: "8px", | ||
height: "100%" | ||
}, | ||
row: { | ||
display: "flex", | ||
flexDirection: "row", | ||
gap: "8px", | ||
}, | ||
rowLabel: { | ||
width: 160, | ||
fontSize: "16pt", | ||
}, | ||
}); | ||
|
||
export default function SettingsView() { | ||
const [demoPath, setDemoPath] = useStore("demoPath"); | ||
|
||
const { classes } = useStyles(); | ||
|
||
return ( | ||
<div> | ||
<div className={classes.root}> | ||
<h1>Settings</h1> | ||
<div> | ||
<Link to="/">Back</Link> | ||
</div> | ||
|
||
<ScrollArea> | ||
<span className={classes.row}> | ||
<span className={classes.rowLabel}> | ||
<label>Demos Folder</label> | ||
</span> | ||
<Button | ||
onClick={() => { | ||
dialogOpen({ | ||
directory: true, | ||
defaultPath: demoPath, | ||
title: "Select Demo Storage Folder", | ||
}) | ||
.then((value) => { | ||
if (value !== null && value !== "") { | ||
// Don't set the path if the user cancelled the dialog | ||
setDemoPath(value as string); | ||
} | ||
return; | ||
}) | ||
.catch((error) => console.error(error)); | ||
}} | ||
> | ||
Select a folder... | ||
</Button> | ||
<TextInput value={demoPath ?? ""} disabled={true}></TextInput> | ||
</span> | ||
</ScrollArea> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { homeDir, join } from "@tauri-apps/api/path"; | ||
import { getTf2Dir } from "../../api"; | ||
|
||
/** | ||
* Gets the default platform-specific demo file storage directory, assuming Steam and TF2 are installed on the local | ||
* machine. Falls back to the user's home directory if neither is found. | ||
*/ | ||
export async function getDefaultDemosDir(): Promise<string> { | ||
const userHomeDir = await homeDir(); | ||
|
||
// Try getting the TF2 game directory, falling back to the user home directory if it couldn't be found | ||
return await getTf2Dir() | ||
.then((tf2Dir) => join(tf2Dir, "tf", "demos")) | ||
.catch((_error) => userHomeDir); | ||
} |