mirror of
https://github.com/winapps-org/winapps.git
synced 2025-06-06 15:17:19 +02:00
feat: stopping the vm
This commit is contained in:
parent
984fcc8da7
commit
6b730e8cb1
@ -1,6 +1,6 @@
|
|||||||
use clap::Command;
|
use clap::Command;
|
||||||
use winapps::freerdp::freerdp_back::Freerdp;
|
use winapps::freerdp::freerdp_back::Freerdp;
|
||||||
use winapps::quickemu::{create_vm, run_vm};
|
use winapps::quickemu::{create_vm, kill_vm, start_vm};
|
||||||
use winapps::RemoteClient;
|
use winapps::RemoteClient;
|
||||||
|
|
||||||
fn cli() -> Command {
|
fn cli() -> Command {
|
||||||
@ -11,8 +11,16 @@ fn cli() -> Command {
|
|||||||
.allow_external_subcommands(true)
|
.allow_external_subcommands(true)
|
||||||
.subcommand(Command::new("check").about("Checks remote connection"))
|
.subcommand(Command::new("check").about("Checks remote connection"))
|
||||||
.subcommand(Command::new("connect").about("Connects to remote"))
|
.subcommand(Command::new("connect").about("Connects to remote"))
|
||||||
.subcommand(Command::new("create-vm").about("Create a windows 10 vm using quickemu"))
|
.subcommand(
|
||||||
.subcommand(Command::new("run-vm").about("Start the vm using quickemu"))
|
Command::new("vm")
|
||||||
|
.about("Manage a windows 10 vm using quickemu")
|
||||||
|
.subcommand_required(true)
|
||||||
|
.arg_required_else_help(true)
|
||||||
|
.allow_external_subcommands(true)
|
||||||
|
.subcommand(Command::new("create").about("Create a windows 10 vm using quickget"))
|
||||||
|
.subcommand(Command::new("start").about("Start the vm"))
|
||||||
|
.subcommand(Command::new("kill").about("Kill the running VM")),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -34,14 +42,32 @@ fn main() {
|
|||||||
let config = winapps::load_config(None);
|
let config = winapps::load_config(None);
|
||||||
client.run_app(config, "explorer");
|
client.run_app(config, "explorer");
|
||||||
}
|
}
|
||||||
Some(("create-vm", _)) => {
|
|
||||||
|
Some(("vm", command)) => {
|
||||||
|
match command.subcommand() {
|
||||||
|
Some(("create", _)) => {
|
||||||
println!("Creating windows 10 vm..");
|
println!("Creating windows 10 vm..");
|
||||||
create_vm();
|
create_vm();
|
||||||
}
|
}
|
||||||
Some(("run-vm", _)) => {
|
Some(("start", _)) => {
|
||||||
println!("Starting vm..");
|
println!("Starting vm..");
|
||||||
run_vm();
|
start_vm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some(("kill", _)) => {
|
||||||
|
println!("Killing vm..");
|
||||||
|
kill_vm();
|
||||||
|
}
|
||||||
|
|
||||||
|
Some((_, _)) => {
|
||||||
|
cli.about("Command not found, try existing ones!")
|
||||||
|
.print_help()
|
||||||
|
.expect("Couldn't print help");
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Some((_, _)) => {
|
Some((_, _)) => {
|
||||||
cli.about("Command not found, try existing ones!")
|
cli.about("Command not found, try existing ones!")
|
||||||
.print_help()
|
.print_help()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use home::home_dir;
|
use home::home_dir;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
@ -51,17 +52,15 @@ pub fn create_vm() {
|
|||||||
println!("{}", String::from_utf8_lossy(&output.stdout));
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_vm() {
|
pub fn start_vm() {
|
||||||
let data_dir = get_data_dir();
|
let data_dir = get_data_dir();
|
||||||
|
|
||||||
let output = match Command::new("quickemu")
|
let command = match Command::new("quickemu")
|
||||||
.current_dir(data_dir)
|
.current_dir(data_dir)
|
||||||
.args(["--vm", "windows-10-22H2.conf", "--display", "none"])
|
.args(["--vm", "windows-10-22H2.conf", "--display", "none"])
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap()
|
|
||||||
.wait_with_output()
|
|
||||||
{
|
{
|
||||||
Ok(o) => o,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to execute quickemu: {}", e);
|
println!("Failed to execute quickemu: {}", e);
|
||||||
println!("Please make sure quickemu is installed and in your PATH");
|
println!("Please make sure quickemu is installed and in your PATH");
|
||||||
@ -69,5 +68,38 @@ pub fn run_vm() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let output = match command.wait_with_output() {
|
||||||
|
Ok(o) => o,
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to gather output from quickemu: {}", e);
|
||||||
|
println!("Please make sure quickemu is installed and in your PATH");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
println!("{}", String::from_utf8_lossy(&output.stdout));
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn kill_vm() {
|
||||||
|
let data_dir = get_data_dir();
|
||||||
|
|
||||||
|
match fs::read_to_string(data_dir.join("windows-10/windows-10-22H2.pid")) {
|
||||||
|
Ok(pid) => {
|
||||||
|
let pid = pid.trim();
|
||||||
|
|
||||||
|
println!("Killing VM with PID {}", pid);
|
||||||
|
|
||||||
|
match Command::new("kill").arg(pid).spawn() {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to kill VM: {}", e);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to read PID file: {}", e);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user