feat: move runtime switcher box (steam vs rex) to its own component

This commit is contained in:
Gabriele Musco 2023-06-21 07:47:15 +02:00
commit acafbac9d9
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
4 changed files with 126 additions and 67 deletions

View file

@ -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::monado_deps::get_missing_monado_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::profile::{Profile, XRServiceType};
use crate::profiles::system_valve_index::system_valve_index_profile;
@ -79,7 +73,6 @@ pub enum Msg {
EnableDebugViewChanged(bool),
DoStartStopXRService,
ProfileSelected(String),
SetXRServiceRuntime(bool),
RunSetCap,
OpenLibsurviveSetup,
}
@ -334,16 +327,6 @@ impl SimpleComponent for App {
.sender()
.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 => {
self.libsurvive_setup_window
.sender()
@ -408,7 +391,6 @@ impl SimpleComponent for App {
MainViewOutMsg::EnableDebugViewChanged(val) => Msg::EnableDebugViewChanged(val),
MainViewOutMsg::DoStartStopXRService => Msg::DoStartStopXRService,
MainViewOutMsg::ProfileSelected(name) => Msg::ProfileSelected(name),
MainViewOutMsg::SetXRServiceRuntime(is_rex) => Msg::SetXRServiceRuntime(is_rex),
}),
debug_view: DebugView::builder()
.launch(DebugViewInit {

View file

@ -1,8 +1,10 @@
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 crate::config::Config;
use crate::constants::APP_NAME;
use crate::file_builders::active_runtime_json::{self, get_current_active_runtime};
use crate::profile::{Profile, XRServiceType};
use crate::ui::app::{
AboutAction, BuildProfileAction, DebugViewToggleAction, LibsurviveSetupAction,
@ -24,6 +26,8 @@ pub struct MainView {
install_wivrn_box: Controller<InstallWivrnBox>,
#[tracker::do_not_track]
steam_launch_options_box: Controller<SteamLaunchOptionsBox>,
#[tracker::do_not_track]
runtime_switcher_box: Controller<RuntimeSwitcherBox>,
}
#[derive(Debug)]
@ -43,7 +47,6 @@ pub enum MainViewOutMsg {
EnableDebugViewChanged(bool),
DoStartStopXRService,
ProfileSelected(String),
SetXRServiceRuntime(bool),
}
pub struct MainViewInit {
@ -132,37 +135,7 @@ impl SimpleComponent for MainView {
sender.input(MainViewMsg::StartStopClicked)
},
},
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,
},
},
model.runtime_switcher_box.widget(),
model.steam_launch_options_box.widget(),
model.install_wivrn_box.widget(),
}
@ -204,6 +177,9 @@ impl SimpleComponent for MainView {
self.install_wivrn_box
.sender()
.emit(InstallWivrnBoxMsg::UpdateSelectedProfile(prof.clone()));
self.runtime_switcher_box
.sender()
.emit(RuntimeSwitcherBoxMsg::UpdateSelectedProfile(prof.clone()));
}
Self::Input::UpdateProfileNames(names, config) => {
self.set_profile_names(names);
@ -253,28 +229,18 @@ impl SimpleComponent for MainView {
steam_launch_options_box: SteamLaunchOptionsBox::builder().launch(()).detach(),
install_wivrn_box: InstallWivrnBox::builder()
.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(),
tracker: 0,
};
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());
ComponentParts { model, widgets }

View file

@ -6,3 +6,4 @@ pub mod build_window;
pub mod libsurvive_setup_window;
pub mod install_wivrn_box;
pub mod steam_launch_options_box;
pub mod runtime_switcher_box;

View 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 }
}
}