Skip to content

Commit 1450b26

Browse files
runner: Add a method to get underlying wine runner to the trait
1 parent f668b2e commit 1450b26

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

src/runner/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ impl RunnerInfo {
9696
}
9797

9898
pub trait Runner {
99+
/// Get the Wine runner associated with this runner
100+
///
101+
/// This is possible because all runners are built on top of Wine
102+
fn wine(&self) -> &Wine;
103+
99104
/// Get the common runner information
100105
fn info(&self) -> &RunnerInfo;
101106

src/runner/proton.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Runner, RunnerInfo};
1+
use super::{Runner, RunnerInfo, Wine};
22
use std::path::{Path, PathBuf};
33

44
// TODO: These need to be set to use proton outside steam
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
77
#[derive(Debug)]
88
pub struct Proton {
99
info: RunnerInfo,
10+
wine: Wine,
1011
}
1112

1213
impl TryFrom<&Path> for Proton {
@@ -15,11 +16,16 @@ impl TryFrom<&Path> for Proton {
1516
fn try_from(path: &Path) -> Result<Self, Self::Error> {
1617
let executable = PathBuf::from("./proton");
1718
let info = RunnerInfo::try_from(path, &executable)?;
18-
Ok(Proton { info })
19+
let mut wine = Wine::try_from(path.join("files").as_path())?;
20+
Ok(Proton { wine, info })
1921
}
2022
}
2123

2224
impl Runner for Proton {
25+
fn wine(&self) -> &Wine {
26+
&self.wine
27+
}
28+
2329
fn info(&self) -> &RunnerInfo {
2430
&self.info
2531
}

src/runner/umu.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
use super::{Runner, RunnerInfo};
1+
use super::{Proton, Runner, RunnerInfo, Wine};
22
use std::path::{Path, PathBuf};
33

44
#[derive(Debug)]
55
pub struct UMU {
66
info: RunnerInfo,
7-
proton_path: Option<PathBuf>,
7+
proton: Option<Proton>,
88
}
99

10-
impl TryFrom<&Path> for UMU {
11-
type Error = Box<dyn std::error::Error>;
12-
13-
fn try_from(path: &Path) -> Result<Self, Self::Error> {
10+
impl UMU {
11+
pub fn try_from(
12+
path: &Path,
13+
proton: Option<Proton>,
14+
) -> Result<Self, Box<dyn std::error::Error>> {
1415
let executable = PathBuf::from("./umu-run");
1516
let mut info = RunnerInfo::try_from(path, &executable)?;
1617
let pretty_version = info
@@ -20,14 +21,16 @@ impl TryFrom<&Path> for UMU {
2021
.unwrap_or("unknown")
2122
.to_string();
2223
info.version = pretty_version;
23-
Ok(UMU {
24-
info,
25-
proton_path: None,
26-
})
24+
Ok(UMU { info, proton })
2725
}
2826
}
2927

3028
impl Runner for UMU {
29+
fn wine(&self) -> &Wine {
30+
// TODO: Make sure an unwrap is possible
31+
self.proton.as_ref().unwrap().wine()
32+
}
33+
3134
fn info(&self) -> &RunnerInfo {
3235
&self.info
3336
}

src/runner/wine.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ impl TryFrom<&Path> for Wine {
2828
}
2929

3030
impl Runner for Wine {
31+
fn wine(&self) -> &Wine {
32+
self
33+
}
34+
3135
fn info(&self) -> &RunnerInfo {
3236
&self.info
3337
}

0 commit comments

Comments
 (0)