diff --git a/src/lib/config.rs b/src/lib/config.rs index 0fc5103..f05051b 100644 --- a/src/lib/config.rs +++ b/src/lib/config.rs @@ -84,6 +84,25 @@ impl Config { None => None } } + + /// Get environment variables corresponding to used wine sync + pub fn get_wine_sync_env_vars(&self) -> HashMap<&str, &str> { + match self.game.wine.sync.as_str() { + "esync" => HashMap::from([ + ("WINEESYNC", "1") + ]), + "fsync" => HashMap::from([ + ("WINEESYNC", "1"), + ("WINEFSYNC", "1") + ]), + "futex2" => HashMap::from([ + ("WINEESYNC", "1"), + ("WINEFSYNC", "1"), + ("WINEFSYNC_FUTEX2", "1") + ]), + _ => HashMap::new() + } + } } #[derive(Debug, Serialize, Deserialize)] diff --git a/src/lib/game.rs b/src/lib/game.rs index a1ba9b7..687aa52 100644 --- a/src/lib/game.rs +++ b/src/lib/game.rs @@ -4,6 +4,45 @@ use std::process::Command; use super::config; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Terminal { + GnomeTerminal, + Konsole, + Xfce4Terminal +} + +impl Terminal { + pub fn get_command(&self) -> &str { + match self { + Terminal::GnomeTerminal => "gnome-terminal", + Terminal::Konsole => "konsole", + Terminal::Xfce4Terminal => "xfce4-terminal" + } + } + + pub fn iter() -> impl Iterator { + [ + Terminal::GnomeTerminal, + Terminal::Konsole, + Terminal::Xfce4Terminal + ].into_iter() + } +} + +/// Try to get GUI terminal installed in system +pub fn try_get_terminal() -> Option { + for terminal in Terminal::iter() { + if let Ok(output) = Command::new(terminal.get_command()).output() { + if output.status.success() { + return Some(terminal); + } + } + } + + None +} + +/// Try to run the game pub fn run() -> Result<(), Error> { let config = config::get()?; @@ -16,9 +55,12 @@ pub fn run() -> Result<(), Error> { None => return Err(Error::new(ErrorKind::Other, "Couldn't find wine executable")) }; - Command::new(wine_executable) - .env("WINEPREFIX", config.game.wine.prefix) - .envs(config.game.environment) + let mut command = Command::new(wine_executable); + + command.env("WINEPREFIX", &config.game.wine.prefix); + command.envs(config.get_wine_sync_env_vars()); + + command.envs(config.game.environment) .current_dir(config.game.path) .arg("launcher.bat") .spawn()?;