mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-05 07:39:00 +00:00
feat: separate steam launch options box into its own component
This commit is contained in:
parent
dcece17445
commit
32fc42865f
4 changed files with 166 additions and 99 deletions
|
@ -167,7 +167,7 @@ impl SimpleComponent for App {
|
|||
RunnerStatus::Stopped(_) => {
|
||||
self.main_view
|
||||
.sender()
|
||||
.emit(MainViewMsg::XRServiceActiveChanged(false));
|
||||
.emit(MainViewMsg::XRServiceActiveChanged(false, None));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -227,11 +227,9 @@ impl SimpleComponent for App {
|
|||
self.start_xrservice();
|
||||
self.main_view
|
||||
.sender()
|
||||
.emit(MainViewMsg::XRServiceActiveChanged(true));
|
||||
self.main_view
|
||||
.sender()
|
||||
.emit(MainViewMsg::SteamLaunchOptionsChanged(
|
||||
self.get_selected_profile().get_steam_launch_options(),
|
||||
.emit(MainViewMsg::XRServiceActiveChanged(
|
||||
true,
|
||||
Some(self.get_selected_profile()),
|
||||
));
|
||||
}
|
||||
Some(runner) => match runner.status() {
|
||||
|
@ -239,7 +237,7 @@ impl SimpleComponent for App {
|
|||
runner.terminate();
|
||||
self.main_view
|
||||
.sender()
|
||||
.emit(MainViewMsg::XRServiceActiveChanged(false));
|
||||
.emit(MainViewMsg::XRServiceActiveChanged(false, None));
|
||||
}
|
||||
RunnerStatus::Stopped(_) => {
|
||||
self.debug_view
|
||||
|
@ -248,7 +246,10 @@ impl SimpleComponent for App {
|
|||
self.start_xrservice();
|
||||
self.main_view
|
||||
.sender()
|
||||
.emit(MainViewMsg::XRServiceActiveChanged(true));
|
||||
.emit(MainViewMsg::XRServiceActiveChanged(
|
||||
true,
|
||||
Some(self.get_selected_profile()),
|
||||
));
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -332,9 +333,7 @@ impl SimpleComponent for App {
|
|||
let profile = self.get_selected_profile();
|
||||
self.main_view
|
||||
.sender()
|
||||
.emit(MainViewMsg::UpdateSelectedProfile(
|
||||
profile.clone()
|
||||
));
|
||||
.emit(MainViewMsg::UpdateSelectedProfile(profile.clone()));
|
||||
}
|
||||
Msg::SetXRServiceRuntime(is_rex) => {
|
||||
if is_rex {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use super::install_wivrn_box::{InstallWivrnBox, InstallWivrnBoxInit, InstallWivrnBoxMsg};
|
||||
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};
|
||||
|
@ -5,40 +7,34 @@ use crate::profile::{Profile, XRServiceType};
|
|||
use crate::ui::app::{
|
||||
AboutAction, BuildProfileAction, DebugViewToggleAction, LibsurviveSetupAction,
|
||||
};
|
||||
use expect_dialog::ExpectDialog;
|
||||
use gtk::prelude::*;
|
||||
use relm4::prelude::*;
|
||||
use relm4::{ComponentParts, ComponentSender, SimpleComponent};
|
||||
use relm4_icons::icon_name;
|
||||
|
||||
use super::install_wivrn_box::{
|
||||
InstallWivrnBox, InstallWivrnBoxInit, InstallWivrnBoxMsg
|
||||
};
|
||||
|
||||
#[tracker::track]
|
||||
pub struct MainView {
|
||||
xrservice_active: bool,
|
||||
xrservice_type: XRServiceType,
|
||||
enable_debug_view: bool,
|
||||
profile_names: Vec<String>,
|
||||
steam_launch_options: String,
|
||||
#[tracker::do_not_track]
|
||||
profiles_dropdown: Option<gtk::DropDown>,
|
||||
#[tracker::do_not_track]
|
||||
install_wivrn_box: Controller<InstallWivrnBox>,
|
||||
#[tracker::do_not_track]
|
||||
steam_launch_options_box: Controller<SteamLaunchOptionsBox>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MainViewMsg {
|
||||
ClockTicking,
|
||||
StartStopClicked,
|
||||
XRServiceActiveChanged(bool),
|
||||
XRServiceActiveChanged(bool, Option<Profile>),
|
||||
EnableDebugViewChanged(bool),
|
||||
UpdateProfileNames(Vec<String>, Config),
|
||||
SetSelectedProfile(u32),
|
||||
ProfileSelected(u32),
|
||||
SteamLaunchOptionsChanged(String),
|
||||
CopySteamLaunchOptions,
|
||||
UpdateSelectedProfile(Profile),
|
||||
}
|
||||
|
||||
|
@ -167,78 +163,7 @@ impl SimpleComponent for MainView {
|
|||
set_label: APP_NAME,
|
||||
},
|
||||
},
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_hexpand: true,
|
||||
set_vexpand: false,
|
||||
set_spacing: 12,
|
||||
set_margin_top: 12,
|
||||
set_margin_bottom: 12,
|
||||
#[track = "model.changed(Self::xrservice_active())"]
|
||||
set_visible: model.xrservice_active,
|
||||
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: "Steam Launch Options",
|
||||
set_wrap: true,
|
||||
set_wrap_mode: gtk::pango::WrapMode::Word,
|
||||
},
|
||||
gtk::Label {
|
||||
add_css_class: "dim-label",
|
||||
set_hexpand: true,
|
||||
set_xalign: 0.0,
|
||||
set_margin_start: 12,
|
||||
set_margin_end: 12,
|
||||
set_label: format!(
|
||||
"Set this string in the launch options of Steam games, so that they can pick up the {app} runtime correctly",
|
||||
app = APP_NAME)
|
||||
.as_str(),
|
||||
set_wrap: true,
|
||||
set_wrap_mode: gtk::pango::WrapMode::Word,
|
||||
},
|
||||
gtk::Box {
|
||||
set_margin_start: 12,
|
||||
set_margin_end: 12,
|
||||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_spacing: 6,
|
||||
gtk::TextView {
|
||||
add_css_class: "card",
|
||||
set_hexpand: true,
|
||||
set_vexpand: false,
|
||||
set_monospace: true,
|
||||
set_editable: false,
|
||||
set_wrap_mode: gtk::WrapMode::Word,
|
||||
set_left_margin: 6,
|
||||
set_right_margin: 6,
|
||||
set_top_margin: 6,
|
||||
set_bottom_margin: 6,
|
||||
set_size_request: (-1, 150),
|
||||
#[wrap(Some)]
|
||||
set_buffer: cmdbuf = >k::TextBuffer {
|
||||
#[track = "model.changed(Self::steam_launch_options())"]
|
||||
set_text: model.steam_launch_options.as_str(),
|
||||
}
|
||||
},
|
||||
gtk::Button {
|
||||
add_css_class: "flat",
|
||||
add_css_class: "circular",
|
||||
set_tooltip_text: Some("Copy"),
|
||||
set_icon_name: icon_name::COPY,
|
||||
set_vexpand: false,
|
||||
set_valign: gtk::Align::Center,
|
||||
connect_clicked[sender] => move |_| {
|
||||
sender.input(MainViewMsg::CopySteamLaunchOptions)
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
model.steam_launch_options_box.widget(),
|
||||
model.install_wivrn_box.widget(),
|
||||
}
|
||||
}
|
||||
|
@ -257,8 +182,19 @@ impl SimpleComponent for MainView {
|
|||
Self::Input::StartStopClicked => {
|
||||
sender.output(MainViewOutMsg::DoStartStopXRService);
|
||||
}
|
||||
Self::Input::XRServiceActiveChanged(active) => {
|
||||
Self::Input::XRServiceActiveChanged(active, profile) => {
|
||||
self.set_xrservice_active(active);
|
||||
self.steam_launch_options_box
|
||||
.sender()
|
||||
.emit(SteamLaunchOptionsBoxMsg::UpdateXRServiceActive(active));
|
||||
match profile {
|
||||
None => {}
|
||||
Some(prof) => {
|
||||
self.steam_launch_options_box
|
||||
.sender()
|
||||
.emit(SteamLaunchOptionsBoxMsg::UpdateLaunchOptions(prof));
|
||||
}
|
||||
}
|
||||
}
|
||||
Self::Input::EnableDebugViewChanged(val) => {
|
||||
self.set_enable_debug_view(val);
|
||||
|
@ -293,11 +229,6 @@ impl SimpleComponent for MainView {
|
|||
.clone()
|
||||
.set_selected(index);
|
||||
}
|
||||
Self::Input::SteamLaunchOptionsChanged(lo) => self.set_steam_launch_options(lo),
|
||||
Self::Input::CopySteamLaunchOptions => gtk::gdk::Display::default()
|
||||
.expect_dialog("Could not find default display")
|
||||
.clipboard()
|
||||
.set_text(self.steam_launch_options.as_str()),
|
||||
Self::Input::ProfileSelected(position) => {
|
||||
// self.install_wivrn_box.sender.emit(InstallWivrnBoxMsg::Upda);
|
||||
// TODO: send profile to install_wivrn_box
|
||||
|
@ -319,7 +250,7 @@ impl SimpleComponent for MainView {
|
|||
enable_debug_view: init.config.debug_view_enabled,
|
||||
profiles_dropdown: None,
|
||||
profile_names: vec![],
|
||||
steam_launch_options: "".into(),
|
||||
steam_launch_options_box: SteamLaunchOptionsBox::builder().launch(()).detach(),
|
||||
install_wivrn_box: InstallWivrnBox::builder()
|
||||
.launch(InstallWivrnBoxInit {
|
||||
selected_profile: init.selected_profile,
|
||||
|
|
|
@ -5,3 +5,4 @@ pub mod debug_view;
|
|||
pub mod build_window;
|
||||
pub mod libsurvive_setup_window;
|
||||
pub mod install_wivrn_box;
|
||||
pub mod steam_launch_options_box;
|
||||
|
|
136
src/ui/steam_launch_options_box.rs
Normal file
136
src/ui/steam_launch_options_box.rs
Normal file
|
@ -0,0 +1,136 @@
|
|||
use expect_dialog::ExpectDialog;
|
||||
use gtk::prelude::*;
|
||||
use relm4::prelude::*;
|
||||
use relm4_icons::icon_name;
|
||||
|
||||
use crate::{constants::APP_NAME, profile::Profile};
|
||||
|
||||
#[tracker::track]
|
||||
pub struct SteamLaunchOptionsBox {
|
||||
xrservice_active: bool,
|
||||
launch_options: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SteamLaunchOptionsBoxMsg {
|
||||
UpdateXRServiceActive(bool),
|
||||
UpdateLaunchOptions(Profile),
|
||||
CopyLaunchOptions,
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
impl SimpleComponent for SteamLaunchOptionsBox {
|
||||
type Init = ();
|
||||
type Input = SteamLaunchOptionsBoxMsg;
|
||||
type Output = ();
|
||||
|
||||
view! {
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_hexpand: true,
|
||||
set_vexpand: false,
|
||||
set_spacing: 12,
|
||||
set_margin_top: 12,
|
||||
set_margin_bottom: 12,
|
||||
#[track = "model.changed(Self::xrservice_active())"]
|
||||
set_visible: model.xrservice_active,
|
||||
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: "Steam Launch Options",
|
||||
set_wrap: true,
|
||||
set_wrap_mode: gtk::pango::WrapMode::Word,
|
||||
},
|
||||
gtk::Label {
|
||||
add_css_class: "dim-label",
|
||||
set_hexpand: true,
|
||||
set_xalign: 0.0,
|
||||
set_margin_start: 12,
|
||||
set_margin_end: 12,
|
||||
set_label: format!(
|
||||
"Set this string in the launch options of Steam games, so that they can pick up the {app} runtime correctly",
|
||||
app = APP_NAME)
|
||||
.as_str(),
|
||||
set_wrap: true,
|
||||
set_wrap_mode: gtk::pango::WrapMode::Word,
|
||||
},
|
||||
gtk::Box {
|
||||
set_margin_start: 12,
|
||||
set_margin_end: 12,
|
||||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_spacing: 6,
|
||||
gtk::TextView {
|
||||
add_css_class: "card",
|
||||
set_hexpand: true,
|
||||
set_vexpand: false,
|
||||
set_monospace: true,
|
||||
set_editable: false,
|
||||
set_wrap_mode: gtk::WrapMode::Word,
|
||||
set_left_margin: 6,
|
||||
set_right_margin: 6,
|
||||
set_top_margin: 6,
|
||||
set_bottom_margin: 6,
|
||||
set_size_request: (-1, 150),
|
||||
#[wrap(Some)]
|
||||
set_buffer: cmdbuf = >k::TextBuffer {
|
||||
#[track = "model.changed(Self::launch_options())"]
|
||||
set_text: model.launch_options.as_str(),
|
||||
}
|
||||
},
|
||||
gtk::Button {
|
||||
add_css_class: "flat",
|
||||
add_css_class: "circular",
|
||||
set_tooltip_text: Some("Copy"),
|
||||
set_icon_name: icon_name::COPY,
|
||||
set_vexpand: false,
|
||||
set_valign: gtk::Align::Center,
|
||||
connect_clicked[sender] => move |_| {
|
||||
sender.input(Self::Input::CopyLaunchOptions)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
|
||||
self.reset();
|
||||
|
||||
match message {
|
||||
Self::Input::UpdateXRServiceActive(val) => {
|
||||
self.set_xrservice_active(val);
|
||||
}
|
||||
Self::Input::UpdateLaunchOptions(prof) => {
|
||||
self.set_launch_options(prof.get_steam_launch_options());
|
||||
}
|
||||
Self::Input::CopyLaunchOptions => {
|
||||
gtk::gdk::Display::default()
|
||||
.expect_dialog("Could not find default display")
|
||||
.clipboard()
|
||||
.set_text(self.launch_options.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn init(
|
||||
init: Self::Init,
|
||||
root: &Self::Root,
|
||||
sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let model = Self {
|
||||
xrservice_active: false,
|
||||
launch_options: "".into(),
|
||||
tracker: 0,
|
||||
};
|
||||
|
||||
let widgets = view_output!();
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue