Skip to content

Commit

Permalink
feat: init wine prefix if does not exist
Browse files Browse the repository at this point in the history
Not tested but should work after some further tests.
  • Loading branch information
donovanglover committed Jan 11, 2025
1 parent 8b32d58 commit 2b222ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sakaya should be bug free, however contributions are welcome. Although NixOS has
- [x] Reduce compile times
- [x] Notify user if sakaya fails to start an executable
- [x] Choose 32/64-bit automatically based on `IMAGE_FILE_32BIT_MACHINE` in the file headers
- [ ] Automatically run winetricks with sane defaults if prefix does not exist already
- [x] Automatically run winetricks with sane defaults if prefix does not exist already
- [x] Get .ico and convert to .png? Handle abrupt end of files?
- [ ] Write tests
- [x] Terminate sakaya if the server/container cannot be reached
Expand Down
10 changes: 7 additions & 3 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ pub fn exec(address: SocketAddrV4, path: &Path, directory: &str) {
return;
}

if !Path::new(wine_prefix).exists() {
request(address, &container_path, wine_prefix, "init").unwrap();
}

make_desktop_file(file_name, path);

notify(&format!("Starting {file_name}..."), Some(&icon));

if request(address, &container_path, wine_prefix).is_ok() {
if request(address, &container_path, wine_prefix, "open").is_ok() {
notify(&format!("Closed {file_name}."), Some(&icon));
} else {
notify("Error: sakaya server is not accessible.", None);
Expand All @@ -64,10 +68,10 @@ pub fn exec(address: SocketAddrV4, path: &Path, directory: &str) {
}

/// Sends a request to start an application inside a container
pub fn request(address: SocketAddrV4, path: &str, wine_prefix: &str) -> Result<(), minreq::Error> {
pub fn request(address: SocketAddrV4, path: &str, wine_prefix: &str, command: &str) -> Result<(), minreq::Error> {
let opts = Options::new(path, wine_prefix);

let url = format!("http://{address}/open");
let url = format!("http://{address}/{command}");
let response = minreq::post(url).with_json(&opts)?.send()?;

print!("{}", response.as_str()?);
Expand Down

0 comments on commit 2b222ab

Please sign in to comment.