-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UI for configuring the demos directory #35
Merged
Narcha
merged 16 commits into
DemomanApp:tauri
from
yep-tf2:tauri_configurable-demos-dir
May 5, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7398926
Add UI for configuring the demos directory
yep-tf2 1dac5ef
Platform-specific storage directory defaults
yep-tf2 76a1772
Formatting with prettier
yep-tf2 edf18ac
Use steamlocate crate for retrieving TF2's installation directory
yep-tf2 21fe1d5
Use tauri dialog for demo folder selection
yep-tf2 b9531f7
Use native tauri `join` method
yep-tf2 3a8b19b
Remove now-redundant back button in settings page
yep-tf2 2358ed5
Correct method signature for getDefaultDemosDir
yep-tf2 a380e38
Re-add error type on IO error when scanning for demo files
yep-tf2 ca79541
Set demoPath on startup if not already set
yep-tf2 4531c5f
Remove redundant state
yep-tf2 74bd99c
Remove unused import
yep-tf2 5e4fda7
Simplify styles
yep-tf2 667a1da
Fix settings scrolling
yep-tf2 1724299
Remove unused import
yep-tf2 f88f80c
Formatting
Narcha File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required so the tauri fs API has access to read files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? I thought
"all": true
enables everything.I intend to reduce the allowed scopes before release, but I believe that with the current settings everything is allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tauri was raising permissions errors on file reads without adding this. Maybe "all" only applies to top-level permissions within the scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's odd, but I suppose you're right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it sufficient to specify the scope?