Skip to content

Commit

Permalink
Open install folder button
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Jan 2, 2024
1 parent 0672fed commit cadbe14
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ directories = "5.0.1"
sevenz-rust = { version = "0.4.3", features = ["aes256"] }
window-shadows = "0.2.1"
minisign = "0.7.5"
opener = "0.6.1"
opener = { version = "0.6.1", features = ["reveal"] }
async-trait = "0.1.74"

[features]
Expand Down
4 changes: 4 additions & 0 deletions src-tauri/src/app_profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ pub trait AppProfile {
fn launch(
&self
) -> Result<(), String>;

fn reveal_folder(
&self
) -> Result<(), String>;
}
6 changes: 6 additions & 0 deletions src-tauri/src/app_profile/official_setlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,10 @@ impl AppProfile for OfficialSetlistProfile {
) -> Result<(), String> {
Err("Cannot launch the setlist!".to_string())
}

fn reveal_folder(
&self
) -> Result<(), String> {
Err("Cannot reveal the setlist folder!".to_string())
}
}
23 changes: 21 additions & 2 deletions src-tauri/src/app_profile/yarg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ pub struct YARGAppProfile {
}

impl YARGAppProfile {
fn get_folder(
&self
) -> PathBuf {
self.root_folder.join(&self.profile).join(&self.version)
}

fn get_exec(
&self
) -> Result<PathBuf, String> {
let mut path = self.root_folder.join(&self.profile).join(&self.version);
let mut path = self.get_folder();

// Each OS has a different executable
path = match std::env::consts::OS.to_string().as_str() {
Expand Down Expand Up @@ -136,7 +142,7 @@ impl AppProfile for YARGAppProfile {
fn exists(
&self
) -> bool {
Path::new(&self.root_folder.join(&self.profile).join(&self.version)).exists()
Path::new(&self.get_folder()).exists()
}

fn launch(
Expand All @@ -148,4 +154,17 @@ impl AppProfile for YARGAppProfile {
.map_err(|e| format!("Failed to start YARG. Is it installed?\n{:?}", e))?;
Ok(())
}

fn reveal_folder(
&self
) -> Result<(), String> {
if !self.exists() {
return Err("Cannot reveal something that doesn't exist!".to_string());
}

opener::reveal(self.get_folder())
.map_err(|e| format!("Failed to reveal folder. Is it installed?\n{:?}", e))?;

Ok(())
}
}
18 changes: 18 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,23 @@ fn launch(
app_profile.launch()
}

#[tauri::command(async)]
fn reveal_folder(
state: tauri::State<'_, State>,
app_name: String,
version: String,
profile: String
) -> Result<(), String> {
let app_profile = create_app_profile(
app_name,
&state,
version,
profile
)?;

app_profile.reveal_folder()
}

#[tauri::command]
fn get_os() -> String {
std::env::consts::OS.to_string()
Expand Down Expand Up @@ -304,6 +321,7 @@ fn main() {
uninstall,
exists,
launch,
reveal_folder,

get_os,
is_dir_empty,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Launch/LaunchButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export function LaunchButton(props: LaunchButtonProps) {
<DropdownItem onClick={() => version.uninstall()}>
Uninstall
</DropdownItem>
<DropdownItem onClick={() => version.revealFolder()}>
Open Install Folder
</DropdownItem>
</>;

return <DropdownButton
Expand Down
19 changes: 18 additions & 1 deletion src/hooks/useYARGVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type YARGVersion = {
play: () => Promise<void>,
download: () => Promise<void>,
uninstall: () => Promise<void>,
revealFolder: () => Promise<void>,
payload?: TaskPayload
}

Expand Down Expand Up @@ -54,6 +55,7 @@ export const useYARGVersion = (releaseData: ExtendedReleaseData | undefined, pro
play: async () => {},
download: async () => {},
uninstall: async () => {},
revealFolder: async () => {},
};
}

Expand Down Expand Up @@ -142,5 +144,20 @@ export const useYARGVersion = (releaseData: ExtendedReleaseData | undefined, pro
}
};

return { state, play, download, uninstall, payload };
const revealFolder = async () => {
if (!releaseData) return;

try {
await invoke("reveal_folder", {
appName: "yarg",
version: releaseData.tag_name,
profile: profileName
});
} catch (e) {
showErrorDialog(e as string);
console.error(e);
}
};

return { state, play, download, uninstall, revealFolder, payload };
};

0 comments on commit cadbe14

Please sign in to comment.