mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-01 15:15:54 +00:00
feat: can start and stop stardust
This commit is contained in:
parent
f94734f3be
commit
74a5474194
3 changed files with 72 additions and 16 deletions
|
@ -1,4 +1,8 @@
|
|||
use crate::{build_tools::git::Git, paths::get_data_dir, ui::job_worker::job::WorkerJob};
|
||||
use crate::{
|
||||
build_tools::git::Git,
|
||||
paths::{get_data_dir, get_stardust_base_dir, get_stardust_prefix},
|
||||
ui::job_worker::job::WorkerJob,
|
||||
};
|
||||
use std::{collections::VecDeque, path::PathBuf};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -35,10 +39,10 @@ pub fn get_build_stardust_jobs(
|
|||
|
||||
let server_git = Git {
|
||||
repo: server_spec.repo,
|
||||
dir: get_data_dir() + "/stardust/stardust-xr-server",
|
||||
dir: get_stardust_base_dir() + "/stardust-xr-server",
|
||||
default_branch: server_spec.branch,
|
||||
};
|
||||
let prefix = get_data_dir() + "/stardust/prefix";
|
||||
let prefix = get_stardust_prefix();
|
||||
jobs.extend(server_git.get_pre_build_jobs(update));
|
||||
jobs.push_back(WorkerJob::new_cmd(
|
||||
None,
|
||||
|
|
|
@ -83,6 +83,14 @@ pub fn get_cache_dir() -> String {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn get_stardust_base_dir() -> String {
|
||||
get_data_dir() + "/stardust"
|
||||
}
|
||||
|
||||
pub fn get_stardust_prefix() -> String {
|
||||
get_stardust_base_dir() + "/prefix"
|
||||
}
|
||||
|
||||
pub fn get_backup_dir() -> String {
|
||||
let p_s = format!("{data}/backups", data = get_data_dir());
|
||||
let p = Path::new(&p_s);
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
use std::{collections::VecDeque, path::Path};
|
||||
|
||||
use crate::{
|
||||
builders::build_stardust::{get_build_stardust_jobs, StardustServerSpec},
|
||||
dependencies::stardust_deps::get_missing_stardust_deps,
|
||||
linux_distro::get_distro,
|
||||
paths::get_stardust_prefix,
|
||||
stardust_config::StardustConfig,
|
||||
stateless_action,
|
||||
ui::{
|
||||
alert::alert,
|
||||
build_window::{BuildStatus, BuildWindow, BuildWindowMsg, BuildWindowOutMsg},
|
||||
job_worker::{internal_worker::JobWorkerOut, JobWorker},
|
||||
job_worker::{internal_worker::JobWorkerOut, job::WorkerJob, JobWorker},
|
||||
},
|
||||
withclones,
|
||||
};
|
||||
|
@ -24,9 +27,12 @@ pub enum StardustViewMsg {
|
|||
BuildStardust { update: bool },
|
||||
OnBuildLog(Vec<String>),
|
||||
OnBuildExit(i32),
|
||||
StartClicked,
|
||||
StopClicked,
|
||||
RestartClicked,
|
||||
Start,
|
||||
Stop,
|
||||
Restart,
|
||||
|
||||
OnStardustLog(Vec<String>),
|
||||
OnStardustExit(i32),
|
||||
|
||||
AutostartChanged(bool),
|
||||
StartAsOvelayChanged(bool),
|
||||
|
@ -55,6 +61,8 @@ pub struct StardustViewInit {
|
|||
pub struct StardustView {
|
||||
stardust_service_active: bool,
|
||||
#[tracker::do_not_track]
|
||||
stardust_worker: Option<JobWorker>,
|
||||
#[tracker::do_not_track]
|
||||
build_window: Controller<BuildWindow>,
|
||||
#[tracker::do_not_track]
|
||||
root_win: gtk::Window,
|
||||
|
@ -104,7 +112,7 @@ impl SimpleComponent for StardustView {
|
|||
set_label: "Start",
|
||||
set_hexpand: true,
|
||||
connect_clicked[sender] => move |_| {
|
||||
sender.input(Self::Input::StartClicked);
|
||||
sender.input(Self::Input::Start);
|
||||
},
|
||||
},
|
||||
gtk::MenuButton {
|
||||
|
@ -125,14 +133,14 @@ impl SimpleComponent for StardustView {
|
|||
set_label: "Stop",
|
||||
set_hexpand: true,
|
||||
connect_clicked[sender] => move |_| {
|
||||
sender.input(Self::Input::StopClicked);
|
||||
sender.input(Self::Input::Stop);
|
||||
},
|
||||
},
|
||||
gtk::Button {
|
||||
set_icon_name: "view-refresh-symbolic",
|
||||
set_tooltip_text: Some("Restart"),
|
||||
connect_clicked[sender] => move |_| {
|
||||
sender.input(Self::Input::RestartClicked);
|
||||
sender.input(Self::Input::Restart);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -254,6 +262,14 @@ impl SimpleComponent for StardustView {
|
|||
self.reset();
|
||||
|
||||
match message {
|
||||
Self::Input::OnStardustLog(rows) => {
|
||||
// TODO?
|
||||
}
|
||||
Self::Input::OnStardustExit(code) => {
|
||||
// TODO
|
||||
self.set_stardust_service_active(false);
|
||||
self.stardust_worker = None;
|
||||
}
|
||||
Self::Input::BuildStardust { update } => {
|
||||
let missing_deps = get_missing_stardust_deps();
|
||||
if !missing_deps.is_empty() {
|
||||
|
@ -322,15 +338,42 @@ impl SimpleComponent for StardustView {
|
|||
}))
|
||||
}
|
||||
Self::Input::CancelBuild => {
|
||||
println!("Cancel Build");
|
||||
if let Some(worker) = self.build_worker.as_ref() {
|
||||
worker.stop();
|
||||
}
|
||||
Self::Input::StartClicked => {
|
||||
println!("Start");
|
||||
}
|
||||
Self::Input::StopClicked => {
|
||||
println!("Stop");
|
||||
Self::Input::Start => {
|
||||
let exec = get_stardust_prefix() + "/bin/stardust-xr-server";
|
||||
if !Path::new(&exec).is_file() {
|
||||
alert(
|
||||
"You need to build Stardust XR before starting it",
|
||||
None,
|
||||
Some(&self.root_win),
|
||||
);
|
||||
return;
|
||||
}
|
||||
Self::Input::RestartClicked => {
|
||||
if let Some(w) = self.stardust_worker.as_ref() {
|
||||
if w.exit_code().is_none() {
|
||||
eprintln!("Stardust is still running!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
let mut jobs = VecDeque::new();
|
||||
jobs.push_back(WorkerJob::new_cmd(None, exec, None));
|
||||
self.set_stardust_service_active(true);
|
||||
let worker = JobWorker::new(jobs, sender.input_sender(), |msg| match msg {
|
||||
JobWorkerOut::Log(rows) => Self::Input::OnStardustLog(rows),
|
||||
JobWorkerOut::Exit(code) => Self::Input::OnStardustExit(code),
|
||||
});
|
||||
worker.start();
|
||||
self.stardust_worker = Some(worker);
|
||||
}
|
||||
Self::Input::Stop => {
|
||||
if let Some(w) = self.stardust_worker.as_ref() {
|
||||
w.stop();
|
||||
}
|
||||
}
|
||||
Self::Input::Restart => {
|
||||
println!("Restart");
|
||||
}
|
||||
Self::Input::AutostartChanged(val) => {
|
||||
|
@ -417,6 +460,7 @@ impl SimpleComponent for StardustView {
|
|||
BuildWindowOutMsg::CancelBuild => Self::Input::CancelBuild,
|
||||
}),
|
||||
stardust_config: StardustConfig::get_config(),
|
||||
stardust_worker: None,
|
||||
build_worker: None,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue