mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-25 18:58:38 +00:00
feat: move runtime switcher box (steam vs rex) to its own component
This commit is contained in:
parent
9705f3d7e3
commit
acafbac9d9
4 changed files with 126 additions and 67 deletions
|
@ -14,12 +14,6 @@ use crate::dependencies::basalt_deps::get_missing_basalt_deps;
|
||||||
use crate::dependencies::libsurvive_deps::get_missing_libsurvive_deps;
|
use crate::dependencies::libsurvive_deps::get_missing_libsurvive_deps;
|
||||||
use crate::dependencies::monado_deps::get_missing_monado_deps;
|
use crate::dependencies::monado_deps::get_missing_monado_deps;
|
||||||
use crate::dependencies::wivrn_deps::get_missing_wivrn_deps;
|
use crate::dependencies::wivrn_deps::get_missing_wivrn_deps;
|
||||||
use crate::file_builders::active_runtime_json::{
|
|
||||||
set_current_active_runtime_to_profile, set_current_active_runtime_to_steam,
|
|
||||||
};
|
|
||||||
use crate::file_builders::openvrpaths_vrpath::{
|
|
||||||
set_current_openvrpaths_to_profile, set_current_openvrpaths_to_steam,
|
|
||||||
};
|
|
||||||
use crate::file_utils::setcap_cap_sys_nice_eip;
|
use crate::file_utils::setcap_cap_sys_nice_eip;
|
||||||
use crate::profile::{Profile, XRServiceType};
|
use crate::profile::{Profile, XRServiceType};
|
||||||
use crate::profiles::system_valve_index::system_valve_index_profile;
|
use crate::profiles::system_valve_index::system_valve_index_profile;
|
||||||
|
@ -79,7 +73,6 @@ pub enum Msg {
|
||||||
EnableDebugViewChanged(bool),
|
EnableDebugViewChanged(bool),
|
||||||
DoStartStopXRService,
|
DoStartStopXRService,
|
||||||
ProfileSelected(String),
|
ProfileSelected(String),
|
||||||
SetXRServiceRuntime(bool),
|
|
||||||
RunSetCap,
|
RunSetCap,
|
||||||
OpenLibsurviveSetup,
|
OpenLibsurviveSetup,
|
||||||
}
|
}
|
||||||
|
@ -334,16 +327,6 @@ impl SimpleComponent for App {
|
||||||
.sender()
|
.sender()
|
||||||
.emit(MainViewMsg::UpdateSelectedProfile(profile.clone()));
|
.emit(MainViewMsg::UpdateSelectedProfile(profile.clone()));
|
||||||
}
|
}
|
||||||
Msg::SetXRServiceRuntime(is_rex) => {
|
|
||||||
if is_rex {
|
|
||||||
let profile = self.get_selected_profile();
|
|
||||||
set_current_active_runtime_to_profile(profile.clone());
|
|
||||||
set_current_openvrpaths_to_profile(profile.clone());
|
|
||||||
} else {
|
|
||||||
set_current_active_runtime_to_steam();
|
|
||||||
set_current_openvrpaths_to_steam();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Msg::OpenLibsurviveSetup => {
|
Msg::OpenLibsurviveSetup => {
|
||||||
self.libsurvive_setup_window
|
self.libsurvive_setup_window
|
||||||
.sender()
|
.sender()
|
||||||
|
@ -408,7 +391,6 @@ impl SimpleComponent for App {
|
||||||
MainViewOutMsg::EnableDebugViewChanged(val) => Msg::EnableDebugViewChanged(val),
|
MainViewOutMsg::EnableDebugViewChanged(val) => Msg::EnableDebugViewChanged(val),
|
||||||
MainViewOutMsg::DoStartStopXRService => Msg::DoStartStopXRService,
|
MainViewOutMsg::DoStartStopXRService => Msg::DoStartStopXRService,
|
||||||
MainViewOutMsg::ProfileSelected(name) => Msg::ProfileSelected(name),
|
MainViewOutMsg::ProfileSelected(name) => Msg::ProfileSelected(name),
|
||||||
MainViewOutMsg::SetXRServiceRuntime(is_rex) => Msg::SetXRServiceRuntime(is_rex),
|
|
||||||
}),
|
}),
|
||||||
debug_view: DebugView::builder()
|
debug_view: DebugView::builder()
|
||||||
.launch(DebugViewInit {
|
.launch(DebugViewInit {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use super::install_wivrn_box::{InstallWivrnBox, InstallWivrnBoxInit, InstallWivrnBoxMsg};
|
use super::install_wivrn_box::{InstallWivrnBox, InstallWivrnBoxInit, InstallWivrnBoxMsg};
|
||||||
|
use super::runtime_switcher_box::{
|
||||||
|
RuntimeSwitcherBox, RuntimeSwitcherBoxInit, RuntimeSwitcherBoxMsg,
|
||||||
|
};
|
||||||
use super::steam_launch_options_box::{SteamLaunchOptionsBox, SteamLaunchOptionsBoxMsg};
|
use super::steam_launch_options_box::{SteamLaunchOptionsBox, SteamLaunchOptionsBoxMsg};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::constants::APP_NAME;
|
use crate::constants::APP_NAME;
|
||||||
use crate::file_builders::active_runtime_json::{self, get_current_active_runtime};
|
|
||||||
use crate::profile::{Profile, XRServiceType};
|
use crate::profile::{Profile, XRServiceType};
|
||||||
use crate::ui::app::{
|
use crate::ui::app::{
|
||||||
AboutAction, BuildProfileAction, DebugViewToggleAction, LibsurviveSetupAction,
|
AboutAction, BuildProfileAction, DebugViewToggleAction, LibsurviveSetupAction,
|
||||||
|
@ -24,6 +26,8 @@ pub struct MainView {
|
||||||
install_wivrn_box: Controller<InstallWivrnBox>,
|
install_wivrn_box: Controller<InstallWivrnBox>,
|
||||||
#[tracker::do_not_track]
|
#[tracker::do_not_track]
|
||||||
steam_launch_options_box: Controller<SteamLaunchOptionsBox>,
|
steam_launch_options_box: Controller<SteamLaunchOptionsBox>,
|
||||||
|
#[tracker::do_not_track]
|
||||||
|
runtime_switcher_box: Controller<RuntimeSwitcherBox>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -43,7 +47,6 @@ pub enum MainViewOutMsg {
|
||||||
EnableDebugViewChanged(bool),
|
EnableDebugViewChanged(bool),
|
||||||
DoStartStopXRService,
|
DoStartStopXRService,
|
||||||
ProfileSelected(String),
|
ProfileSelected(String),
|
||||||
SetXRServiceRuntime(bool),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MainViewInit {
|
pub struct MainViewInit {
|
||||||
|
@ -132,37 +135,7 @@ impl SimpleComponent for MainView {
|
||||||
sender.input(MainViewMsg::StartStopClicked)
|
sender.input(MainViewMsg::StartStopClicked)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
gtk::Separator {
|
model.runtime_switcher_box.widget(),
|
||||||
set_orientation: gtk::Orientation::Horizontal,
|
|
||||||
set_hexpand: true,
|
|
||||||
},
|
|
||||||
gtk::Label {
|
|
||||||
add_css_class: "heading",
|
|
||||||
set_hexpand: true,
|
|
||||||
set_xalign: 0.0,
|
|
||||||
set_margin_start: 12,
|
|
||||||
set_margin_end: 12,
|
|
||||||
set_label: "OpenXR/OpenVR Runtime",
|
|
||||||
set_wrap: true,
|
|
||||||
set_wrap_mode: gtk::pango::WrapMode::Word,
|
|
||||||
},
|
|
||||||
gtk::Box {
|
|
||||||
set_orientation: gtk::Orientation::Horizontal,
|
|
||||||
set_hexpand: true,
|
|
||||||
set_halign: gtk::Align::Start,
|
|
||||||
set_margin_start: 12,
|
|
||||||
set_margin_end: 12,
|
|
||||||
set_spacing: 12,
|
|
||||||
gtk::Label {
|
|
||||||
set_label: "Steam",
|
|
||||||
},
|
|
||||||
#[name(runtime_switch)]
|
|
||||||
gtk::Switch {
|
|
||||||
},
|
|
||||||
gtk::Label {
|
|
||||||
set_label: APP_NAME,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
model.steam_launch_options_box.widget(),
|
model.steam_launch_options_box.widget(),
|
||||||
model.install_wivrn_box.widget(),
|
model.install_wivrn_box.widget(),
|
||||||
}
|
}
|
||||||
|
@ -204,6 +177,9 @@ impl SimpleComponent for MainView {
|
||||||
self.install_wivrn_box
|
self.install_wivrn_box
|
||||||
.sender()
|
.sender()
|
||||||
.emit(InstallWivrnBoxMsg::UpdateSelectedProfile(prof.clone()));
|
.emit(InstallWivrnBoxMsg::UpdateSelectedProfile(prof.clone()));
|
||||||
|
self.runtime_switcher_box
|
||||||
|
.sender()
|
||||||
|
.emit(RuntimeSwitcherBoxMsg::UpdateSelectedProfile(prof.clone()));
|
||||||
}
|
}
|
||||||
Self::Input::UpdateProfileNames(names, config) => {
|
Self::Input::UpdateProfileNames(names, config) => {
|
||||||
self.set_profile_names(names);
|
self.set_profile_names(names);
|
||||||
|
@ -253,28 +229,18 @@ impl SimpleComponent for MainView {
|
||||||
steam_launch_options_box: SteamLaunchOptionsBox::builder().launch(()).detach(),
|
steam_launch_options_box: SteamLaunchOptionsBox::builder().launch(()).detach(),
|
||||||
install_wivrn_box: InstallWivrnBox::builder()
|
install_wivrn_box: InstallWivrnBox::builder()
|
||||||
.launch(InstallWivrnBoxInit {
|
.launch(InstallWivrnBoxInit {
|
||||||
selected_profile: init.selected_profile,
|
selected_profile: init.selected_profile.clone(),
|
||||||
|
})
|
||||||
|
.detach(),
|
||||||
|
runtime_switcher_box: RuntimeSwitcherBox::builder()
|
||||||
|
.launch(RuntimeSwitcherBoxInit {
|
||||||
|
selected_profile: init.selected_profile.clone(),
|
||||||
})
|
})
|
||||||
.detach(),
|
.detach(),
|
||||||
tracker: 0,
|
tracker: 0,
|
||||||
};
|
};
|
||||||
let widgets = view_output!();
|
let widgets = view_output!();
|
||||||
|
|
||||||
{
|
|
||||||
match get_current_active_runtime() {
|
|
||||||
None => {}
|
|
||||||
Some(runtime) => {
|
|
||||||
widgets
|
|
||||||
.runtime_switch
|
|
||||||
.set_active(!active_runtime_json::is_steam(runtime));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
widgets.runtime_switch.connect_state_set(move |_, state| {
|
|
||||||
sender.output(MainViewOutMsg::SetXRServiceRuntime(state));
|
|
||||||
gtk::Inhibit(false)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
model.profiles_dropdown = Some(widgets.profiles_dropdown.clone());
|
model.profiles_dropdown = Some(widgets.profiles_dropdown.clone());
|
||||||
|
|
||||||
ComponentParts { model, widgets }
|
ComponentParts { model, widgets }
|
||||||
|
|
|
@ -6,3 +6,4 @@ pub mod build_window;
|
||||||
pub mod libsurvive_setup_window;
|
pub mod libsurvive_setup_window;
|
||||||
pub mod install_wivrn_box;
|
pub mod install_wivrn_box;
|
||||||
pub mod steam_launch_options_box;
|
pub mod steam_launch_options_box;
|
||||||
|
pub mod runtime_switcher_box;
|
||||||
|
|
110
src/ui/runtime_switcher_box.rs
Normal file
110
src/ui/runtime_switcher_box.rs
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
use relm4::prelude::*;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use crate::{constants::APP_NAME, file_builders::{active_runtime_json::{get_current_active_runtime, self, set_current_active_runtime_to_profile, set_current_active_runtime_to_steam}, openvrpaths_vrpath::{set_current_openvrpaths_to_profile, set_current_openvrpaths_to_steam}}, profile::Profile};
|
||||||
|
|
||||||
|
pub struct RuntimeSwitcherBox {
|
||||||
|
selected_profile: Profile,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum RuntimeSwitcherBoxMsg {
|
||||||
|
UpdateSelectedProfile(Profile),
|
||||||
|
SetXRServiceRuntime(bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RuntimeSwitcherBoxInit {
|
||||||
|
pub selected_profile: Profile,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[relm4::component(pub)]
|
||||||
|
impl SimpleComponent for RuntimeSwitcherBox {
|
||||||
|
type Init = RuntimeSwitcherBoxInit;
|
||||||
|
type Input = RuntimeSwitcherBoxMsg;
|
||||||
|
type Output = ();
|
||||||
|
|
||||||
|
view! {
|
||||||
|
gtk::Box {
|
||||||
|
set_orientation: gtk::Orientation::Vertical,
|
||||||
|
set_hexpand: true,
|
||||||
|
set_spacing: 12,
|
||||||
|
gtk::Separator {
|
||||||
|
set_orientation: gtk::Orientation::Horizontal,
|
||||||
|
set_hexpand: true,
|
||||||
|
},
|
||||||
|
gtk::Label {
|
||||||
|
add_css_class: "heading",
|
||||||
|
set_hexpand: true,
|
||||||
|
set_xalign: 0.0,
|
||||||
|
set_margin_start: 12,
|
||||||
|
set_margin_end: 12,
|
||||||
|
set_label: "OpenXR/OpenVR Runtime",
|
||||||
|
set_wrap: true,
|
||||||
|
set_wrap_mode: gtk::pango::WrapMode::Word,
|
||||||
|
},
|
||||||
|
gtk::Box {
|
||||||
|
set_orientation: gtk::Orientation::Horizontal,
|
||||||
|
set_hexpand: true,
|
||||||
|
set_halign: gtk::Align::Start,
|
||||||
|
set_margin_start: 12,
|
||||||
|
set_margin_end: 12,
|
||||||
|
set_spacing: 12,
|
||||||
|
gtk::Label {
|
||||||
|
set_label: "Steam",
|
||||||
|
},
|
||||||
|
#[name(runtime_switch)]
|
||||||
|
gtk::Switch {
|
||||||
|
},
|
||||||
|
gtk::Label {
|
||||||
|
set_label: APP_NAME,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
|
||||||
|
match message {
|
||||||
|
Self::Input::UpdateSelectedProfile(prof) => {
|
||||||
|
self.selected_profile = prof;
|
||||||
|
}
|
||||||
|
Self::Input::SetXRServiceRuntime(is_rex) => {
|
||||||
|
if is_rex {
|
||||||
|
set_current_active_runtime_to_profile(self.selected_profile.clone());
|
||||||
|
set_current_openvrpaths_to_profile(self.selected_profile.clone());
|
||||||
|
} else {
|
||||||
|
set_current_active_runtime_to_steam();
|
||||||
|
set_current_openvrpaths_to_steam();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(
|
||||||
|
init: Self::Init,
|
||||||
|
root: &Self::Root,
|
||||||
|
sender: ComponentSender<Self>,
|
||||||
|
) -> ComponentParts<Self> {
|
||||||
|
let model = Self {
|
||||||
|
selected_profile: init.selected_profile,
|
||||||
|
};
|
||||||
|
|
||||||
|
let widgets = view_output!();
|
||||||
|
|
||||||
|
{
|
||||||
|
match get_current_active_runtime() {
|
||||||
|
None => {}
|
||||||
|
Some(runtime) => {
|
||||||
|
widgets
|
||||||
|
.runtime_switch
|
||||||
|
.set_active(!active_runtime_json::is_steam(runtime));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
widgets.runtime_switch.connect_state_set(move |_, state| {
|
||||||
|
sender.input(Self::Input::SetXRServiceRuntime(state));
|
||||||
|
gtk::Inhibit(false)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ComponentParts { model, widgets }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue