mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-07 00:28:48 +00:00
feat: command line options support; option to start the xr service on startup
This commit is contained in:
parent
bf96a54675
commit
06fcb0077c
4 changed files with 52 additions and 4 deletions
19
src/main.rs
19
src/main.rs
|
@ -7,11 +7,13 @@ use file_builders::{
|
||||||
use gettextrs::LocaleCategory;
|
use gettextrs::LocaleCategory;
|
||||||
use relm4::{
|
use relm4::{
|
||||||
adw,
|
adw,
|
||||||
gtk::{self, gdk, gio, glib},
|
gtk::{self, gdk, gio, glib, prelude::*},
|
||||||
RelmApp,
|
MessageBroker, RelmApp,
|
||||||
};
|
};
|
||||||
use ui::app::{App, AppInit};
|
use ui::app::{App, AppInit};
|
||||||
|
|
||||||
|
use crate::ui::{app::Msg, cmdline_opts::CmdLineOpts};
|
||||||
|
|
||||||
pub mod adb;
|
pub mod adb;
|
||||||
pub mod build_tools;
|
pub mod build_tools;
|
||||||
pub mod builders;
|
pub mod builders;
|
||||||
|
@ -90,10 +92,19 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
let main_app = adw::Application::builder()
|
let main_app = adw::Application::builder()
|
||||||
.application_id(APP_ID)
|
.application_id(APP_ID)
|
||||||
.flags(gio::ApplicationFlags::FLAGS_NONE)
|
.flags(gio::ApplicationFlags::HANDLES_COMMAND_LINE)
|
||||||
.resource_base_path(format!("/{}", APP_ID.replace(".", "/")))
|
.resource_base_path(format!("/{}", APP_ID.replace(".", "/")))
|
||||||
.build();
|
.build();
|
||||||
let app = RelmApp::from_app(main_app.clone());
|
|
||||||
|
static BROKER: MessageBroker<Msg> = MessageBroker::new();
|
||||||
|
CmdLineOpts::init(&main_app);
|
||||||
|
let sender = BROKER.sender();
|
||||||
|
main_app.connect_command_line(move |this, cmdline| {
|
||||||
|
this.activate();
|
||||||
|
sender.emit(Msg::HandleCommandLine(CmdLineOpts::from_cmdline(cmdline)));
|
||||||
|
0
|
||||||
|
});
|
||||||
|
let app = RelmApp::from_app(main_app.clone()).with_broker(&BROKER);
|
||||||
app.run::<App>(AppInit {
|
app.run::<App>(AppInit {
|
||||||
application: main_app,
|
application: main_app,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use super::about_dialog::AboutDialog;
|
use super::about_dialog::AboutDialog;
|
||||||
use super::alert::{alert, alert_w_widget};
|
use super::alert::{alert, alert_w_widget};
|
||||||
use super::build_window::{BuildStatus, BuildWindow};
|
use super::build_window::{BuildStatus, BuildWindow};
|
||||||
|
use super::cmdline_opts::CmdLineOpts;
|
||||||
use super::debug_view::{DebugView, DebugViewMsg};
|
use super::debug_view::{DebugView, DebugViewMsg};
|
||||||
use super::fbt_config_editor::{FbtConfigEditor, FbtConfigEditorInit, FbtConfigEditorMsg};
|
use super::fbt_config_editor::{FbtConfigEditor, FbtConfigEditorInit, FbtConfigEditorMsg};
|
||||||
use super::job_worker::internal_worker::JobWorkerOut;
|
use super::job_worker::internal_worker::JobWorkerOut;
|
||||||
|
@ -136,6 +137,7 @@ pub enum Msg {
|
||||||
DebugOpenPrefix,
|
DebugOpenPrefix,
|
||||||
DebugOpenData,
|
DebugOpenData,
|
||||||
OpenWivrnConfig,
|
OpenWivrnConfig,
|
||||||
|
HandleCommandLine(CmdLineOpts),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
@ -736,6 +738,11 @@ impl SimpleComponent for App {
|
||||||
editor.emit(WivrnConfEditorMsg::Present);
|
editor.emit(WivrnConfEditorMsg::Present);
|
||||||
self.wivrn_conf_editor = Some(editor);
|
self.wivrn_conf_editor = Some(editor);
|
||||||
}
|
}
|
||||||
|
Msg::HandleCommandLine(opts) => {
|
||||||
|
if opts.start {
|
||||||
|
sender.input(Msg::DoStartStopXRService)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
src/ui/cmdline_opts.rs
Normal file
29
src/ui/cmdline_opts.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
use gtk4::{
|
||||||
|
gio::{prelude::ApplicationExt, Application, ApplicationCommandLine},
|
||||||
|
glib::{self, IsA},
|
||||||
|
};
|
||||||
|
use zoha_vte4::ApplicationCommandLineExt;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct CmdLineOpts {
|
||||||
|
pub start: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CmdLineOpts {
|
||||||
|
pub fn init(app: &impl IsA<Application>) {
|
||||||
|
app.add_main_option(
|
||||||
|
"start",
|
||||||
|
glib::Char::try_from('S').unwrap(),
|
||||||
|
glib::OptionFlags::IN_MAIN,
|
||||||
|
glib::OptionArg::None,
|
||||||
|
"Start the XR Service right away",
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_cmdline(cmdline: &ApplicationCommandLine) -> Self {
|
||||||
|
Self {
|
||||||
|
start: cmdline.options_dict().contains("start"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ mod about_dialog;
|
||||||
mod alert;
|
mod alert;
|
||||||
pub mod app;
|
pub mod app;
|
||||||
mod build_window;
|
mod build_window;
|
||||||
|
pub mod cmdline_opts;
|
||||||
mod debug_view;
|
mod debug_view;
|
||||||
mod devices_box;
|
mod devices_box;
|
||||||
mod factories;
|
mod factories;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue