Skip to content

Commit

Permalink
feat: Add client-side logic for automatic wine prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
donovanglover committed Oct 29, 2023
1 parent 5a0bfda commit c16193a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ pub struct Cli {
#[arg(short, long, default_value = "/home/user/containers/wine")]
pub directory: PathBuf,

/// $WINE_PREFIX for 32-bit applications (i386)
#[arg(short, long, default_value = "/mnt/wine32")]
pub wine32: String,

/// $WINE_PREFIX for 64-bit applications (amd64)
#[arg(short = 'W', long, default_value = "/mnt/wine64")]
pub wine64: String,

#[command(subcommand)]
pub command: Option<Commands>,
}
Expand Down
21 changes: 18 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use clap::Parser;
use crate::cli::Cli;
use home::home_dir;
use pelite::{FileMap, PeFile};
use sakaya::notify;
Expand Down Expand Up @@ -27,17 +29,30 @@ pub fn exec(address: SocketAddrV4, path: &Path, directory: &str) {
let container_path = path.replace(directory, "mnt");
let icon = make_icon(path, file_name);

let Cli { wine32, wine64, .. } = Cli::parse();
let wine_prefix = match get_target_machine(path) {
32 => &wine32,
64 => &wine64,
_ => "",
};

if wine_prefix == "" {
notify("Exiting since 32/64-bit could not be determined. Please report this issue.", Some(&icon));
return;
}

make_desktop_file(file_name, path);
notify(&format!("Starting {file_name}..."), Some(&icon));
request(address, &container_path).unwrap();
request(address, &container_path, wine_prefix).unwrap();
notify(&format!("Closed {file_name}."), Some(&icon));
}
}

/// Sends a request to start an application inside a container
pub fn request(address: SocketAddrV4, path: &str) -> Result<(), minreq::Error> {
pub fn request(address: SocketAddrV4, path: &str, wine_prefix: &str) -> Result<(), minreq::Error> {
let path = encode(path);
let response = minreq::get(format!("http://{address}/{path}")).send()?;
let wine_prefix = encode(wine_prefix);
let response = minreq::get(format!("http://{address}/{path}/{wine_prefix}")).send()?;
print!("{}", response.as_str()?);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod server;
/// to starting a `sakaya-server` if ran inside a systemd-nspawn container.
fn main() {
#[rustfmt::skip]
let Cli { address, command, file, directory } = Cli::parse();
let Cli { address, command, file, directory, .. } = Cli::parse();

let server = command == Some(Commands::Server {});

Expand Down

0 comments on commit c16193a

Please sign in to comment.