mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-07 00:28:48 +00:00
feat: stardust config, wire up settings in stardust view
This commit is contained in:
parent
8b1583a973
commit
bca785d05a
3 changed files with 148 additions and 24 deletions
|
@ -40,6 +40,7 @@ pub mod profile;
|
|||
pub mod profiles;
|
||||
pub mod runner;
|
||||
pub mod runner_pipeline;
|
||||
pub mod stardust_config;
|
||||
pub mod steamvr_utils;
|
||||
pub mod ui;
|
||||
pub mod xr_devices;
|
||||
|
|
68
src/stardust_config.rs
Normal file
68
src/stardust_config.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{constants::CMD_NAME, file_utils::get_writer, paths::get_config_dir};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct StardustExternalClient {
|
||||
pub executable: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct StardustConfig {
|
||||
pub autostart: bool,
|
||||
pub start_as_overlay: bool,
|
||||
pub overlay_priority: u32,
|
||||
pub disable_controller: bool,
|
||||
pub repo: String,
|
||||
pub branch: String,
|
||||
pub debug: bool,
|
||||
|
||||
pub flatland_enabled: bool,
|
||||
pub flatland_repo: String,
|
||||
pub flatland_branch: String,
|
||||
|
||||
pub external_clients: Vec<StardustExternalClient>,
|
||||
}
|
||||
|
||||
impl Default for StardustConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
autostart: false,
|
||||
start_as_overlay: false,
|
||||
overlay_priority: 0,
|
||||
disable_controller: false,
|
||||
repo: "https://github.com/StardustXR/server".into(),
|
||||
branch: "main".into(),
|
||||
debug: false,
|
||||
|
||||
flatland_enabled: true,
|
||||
flatland_repo: "https://github.com/StardustXR/flatland".into(),
|
||||
flatland_branch: "main".into(),
|
||||
|
||||
external_clients: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StardustConfig {
|
||||
fn file_path() -> String {
|
||||
format!("{}/{}.stardust.json", get_config_dir(), CMD_NAME)
|
||||
}
|
||||
|
||||
pub fn get_config() -> Self {
|
||||
if let Ok(file) = File::open(Self::file_path()) {
|
||||
let reader = BufReader::new(file);
|
||||
if let Ok(conf) = serde_json::from_reader(reader) {
|
||||
return conf;
|
||||
}
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn save(&self) -> Result<(), serde_json::Error> {
|
||||
let writer = get_writer(&Self::file_path());
|
||||
serde_json::to_writer_pretty(writer, self)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
use crate::{
|
||||
builders::build_stardust::{get_build_stardust_jobs, StardustServerSpec},
|
||||
stardust_config::StardustConfig,
|
||||
stateless_action,
|
||||
ui::build_window::{BuildWindow, BuildWindowMsg, BuildWindowOutMsg},
|
||||
withclones,
|
||||
|
@ -24,6 +26,8 @@ pub enum StardustViewMsg {
|
|||
OverlayPriorityChanged(u32),
|
||||
DisableControllerChanged(bool),
|
||||
RepoChanged(String),
|
||||
DebugChanged(bool),
|
||||
|
||||
FlatlandEnabledChanged(bool),
|
||||
FlatlandRepoChanged(String),
|
||||
|
||||
|
@ -45,6 +49,8 @@ pub struct StardustView {
|
|||
stardust_service_active: bool,
|
||||
#[tracker::do_not_track]
|
||||
build_window: Controller<BuildWindow>,
|
||||
|
||||
stardust_config: StardustConfig,
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
|
@ -124,16 +130,14 @@ impl SimpleComponent for StardustView {
|
|||
set_selection_mode: gtk::SelectionMode::None,
|
||||
adw::SwitchRow {
|
||||
set_title: "Autostart with XR Service",
|
||||
// TODO: settings
|
||||
// set_active: model.settings.autostart,
|
||||
set_active: model.stardust_config.autostart,
|
||||
connect_active_notify[sender] => move |row| {
|
||||
sender.input(Self::Input::AutostartChanged(row.is_active()));
|
||||
}
|
||||
},
|
||||
adw::SwitchRow {
|
||||
set_title: "Start as an overlay",
|
||||
// TODO: settings
|
||||
// set_active: model.settings.overlay,
|
||||
set_active: model.stardust_config.start_as_overlay,
|
||||
connect_active_notify[sender] => move |row| {
|
||||
sender.input(Self::Input::StartAsOvelayChanged(row.is_active()));
|
||||
}
|
||||
|
@ -142,8 +146,6 @@ impl SimpleComponent for StardustView {
|
|||
set_title: "Overlay priority",
|
||||
set_digits: 0,
|
||||
set_snap_to_ticks: true,
|
||||
// TODO: settings -- here or in adj?
|
||||
// set_value: model.settings.priority,
|
||||
#[wrap(Some)]
|
||||
set_adjustment: overlay_priority_adj = >k::Adjustment {
|
||||
set_lower: 0.0,
|
||||
|
@ -151,8 +153,7 @@ impl SimpleComponent for StardustView {
|
|||
set_value: 0.0,
|
||||
set_page_increment: 10.0,
|
||||
set_step_increment: 1.0,
|
||||
// TODO: settings
|
||||
// set_value: model.settings.priority,
|
||||
set_value: model.stardust_config.overlay_priority.into(),
|
||||
},
|
||||
set_range: (0.0, f64::from(u32::MAX)),
|
||||
connect_value_notify[sender] => move |row| {
|
||||
|
@ -164,17 +165,21 @@ impl SimpleComponent for StardustView {
|
|||
set_title: "Disable controller",
|
||||
set_subtitle_lines: 0,
|
||||
set_subtitle: "Necessary if you plan on using hand tracking",
|
||||
// TODO: settings
|
||||
// set_active: model.settings.autostart,
|
||||
set_active: model.stardust_config.disable_controller,
|
||||
connect_active_notify[sender] => move |row| {
|
||||
sender.input(Self::Input::DisableControllerChanged(row.is_active()));
|
||||
}
|
||||
},
|
||||
adw::SwitchRow {
|
||||
set_title: "Debug symbols",
|
||||
set_active: model.stardust_config.debug,
|
||||
connect_active_notify[sender] => move |row| {
|
||||
sender.input(Self::Input::DebugChanged(row.is_active()));
|
||||
}
|
||||
},
|
||||
adw::EntryRow {
|
||||
set_title: "Repository#git ref",
|
||||
// TODO: settings
|
||||
// set_text: model.settings.repo,
|
||||
set_text: "https://github.com/StardustXR/server#main",
|
||||
set_text: &format!("{}#{}", model.stardust_config.repo, model.stardust_config.branch),
|
||||
connect_changed[sender] => move |row| {
|
||||
sender.input(Self::Input::RepoChanged(row.text().into()));
|
||||
}
|
||||
|
@ -199,6 +204,7 @@ impl SimpleComponent for StardustView {
|
|||
set_valign: gtk::Align::Center,
|
||||
set_hexpand: false,
|
||||
set_vexpand: false,
|
||||
set_active: model.stardust_config.flatland_enabled,
|
||||
connect_activate[sender] => move |sw| {
|
||||
sender.input(Self::Input::FlatlandEnabledChanged(sw.is_active()));
|
||||
},
|
||||
|
@ -207,9 +213,7 @@ impl SimpleComponent for StardustView {
|
|||
bind_property: ("enable-expansion", &flatland_switch, "active"),
|
||||
add_row: flatland_repo_entryrow = &adw::EntryRow {
|
||||
set_title: "Repository#git ref",
|
||||
// TODO: settings
|
||||
// set_text: model.settings.clients.builtin.flatland.repo,
|
||||
set_text: "https://github.com/StardustXR/flatland#main",
|
||||
set_text: &format!("{}#{}", model.stardust_config.flatland_repo, model.stardust_config.flatland_branch),
|
||||
connect_changed[sender] => move |row| {
|
||||
sender.input(Self::Input::FlatlandRepoChanged(row.text().into()));
|
||||
},
|
||||
|
@ -241,6 +245,15 @@ impl SimpleComponent for StardustView {
|
|||
match message {
|
||||
Self::Input::BuildStardust => {
|
||||
println!("Build");
|
||||
get_build_stardust_jobs(
|
||||
StardustServerSpec {
|
||||
repo: self.stardust_config.repo.clone(),
|
||||
branch: self.stardust_config.branch.clone(),
|
||||
debug: self.stardust_config.debug,
|
||||
wayland_support: true,
|
||||
},
|
||||
&vec![],
|
||||
);
|
||||
self.build_window.sender().emit(BuildWindowMsg::Present);
|
||||
}
|
||||
Self::Input::UpdateStardust => {
|
||||
|
@ -260,25 +273,66 @@ impl SimpleComponent for StardustView {
|
|||
println!("Restart");
|
||||
}
|
||||
Self::Input::AutostartChanged(val) => {
|
||||
println!("Autostart: {}", val);
|
||||
self.stardust_config.autostart = val;
|
||||
self.stardust_config.save();
|
||||
}
|
||||
Self::Input::StartAsOvelayChanged(val) => {
|
||||
println!("StartAsOvelayChanged: {}", val);
|
||||
self.stardust_config.start_as_overlay = val;
|
||||
self.stardust_config.save();
|
||||
}
|
||||
Self::Input::OverlayPriorityChanged(val) => {
|
||||
println!("OverlayPriorityChanged: {}", val);
|
||||
self.stardust_config.overlay_priority = val;
|
||||
self.stardust_config.save();
|
||||
}
|
||||
Self::Input::DisableControllerChanged(val) => {
|
||||
println!("DisableControllerChanged: {}", val);
|
||||
self.stardust_config.disable_controller = val;
|
||||
self.stardust_config.save();
|
||||
}
|
||||
Self::Input::RepoChanged(val) => {
|
||||
println!("RepoChanged: {}", val);
|
||||
let def = StardustConfig::default();
|
||||
let split = val
|
||||
.split('#')
|
||||
.map(str::trim)
|
||||
.map(String::from)
|
||||
.collect::<Vec<String>>();
|
||||
let repo = split.get(0).unwrap_or_else(|| &def.repo).clone();
|
||||
let branch = split.get(1).unwrap_or_else(|| &def.branch).clone();
|
||||
self.stardust_config.repo = if repo.is_empty() { def.repo } else { repo };
|
||||
self.stardust_config.branch = if branch.is_empty() {
|
||||
def.branch
|
||||
} else {
|
||||
branch
|
||||
};
|
||||
self.stardust_config.save();
|
||||
}
|
||||
Self::Input::DebugChanged(val) => {
|
||||
self.stardust_config.debug = val;
|
||||
self.stardust_config.save();
|
||||
}
|
||||
Self::Input::FlatlandRepoChanged(val) => {
|
||||
println!("FlatlandRepoChanged: {}", val);
|
||||
let def = StardustConfig::default();
|
||||
let split = val
|
||||
.split('#')
|
||||
.map(str::trim)
|
||||
.map(String::from)
|
||||
.collect::<Vec<String>>();
|
||||
let repo = split.get(0).unwrap_or_else(|| &def.flatland_repo).clone();
|
||||
let branch = split.get(1).unwrap_or_else(|| &def.flatland_branch).clone();
|
||||
self.stardust_config.flatland_repo = if repo.is_empty() {
|
||||
def.flatland_repo
|
||||
} else {
|
||||
repo
|
||||
};
|
||||
self.stardust_config.flatland_branch = if branch.is_empty() {
|
||||
def.flatland_branch
|
||||
} else {
|
||||
branch
|
||||
};
|
||||
self.stardust_config.save();
|
||||
}
|
||||
Self::Input::FlatlandEnabledChanged(val) => {
|
||||
println!("FlatlandEnabledChanged: {}", val);
|
||||
self.stardust_config.flatland_enabled = val;
|
||||
self.stardust_config.save();
|
||||
}
|
||||
Self::Input::AddClient => {
|
||||
println!("AddClient");
|
||||
|
@ -292,6 +346,7 @@ impl SimpleComponent for StardustView {
|
|||
sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let model = Self {
|
||||
tracker: 0,
|
||||
stardust_service_active: false,
|
||||
build_window: BuildWindow::builder()
|
||||
.transient_for(init.root_win)
|
||||
|
@ -299,7 +354,7 @@ impl SimpleComponent for StardustView {
|
|||
.forward(sender.input_sender(), |msg| match msg {
|
||||
BuildWindowOutMsg::CancelBuild => Self::Input::CancelBuild,
|
||||
}),
|
||||
tracker: 0,
|
||||
stardust_config: StardustConfig::get_config(),
|
||||
};
|
||||
|
||||
let widgets = view_output!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue