feat: command line options support; option to start the xr service on startup

This commit is contained in:
Gabriele Musco 2024-02-05 13:37:11 +01:00
commit 06fcb0077c
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
4 changed files with 52 additions and 4 deletions

View file

@ -7,11 +7,13 @@ use file_builders::{
use gettextrs::LocaleCategory;
use relm4::{
adw,
gtk::{self, gdk, gio, glib},
RelmApp,
gtk::{self, gdk, gio, glib, prelude::*},
MessageBroker, RelmApp,
};
use ui::app::{App, AppInit};
use crate::ui::{app::Msg, cmdline_opts::CmdLineOpts};
pub mod adb;
pub mod build_tools;
pub mod builders;
@ -90,10 +92,19 @@ fn main() -> Result<()> {
let main_app = adw::Application::builder()
.application_id(APP_ID)
.flags(gio::ApplicationFlags::FLAGS_NONE)
.flags(gio::ApplicationFlags::HANDLES_COMMAND_LINE)
.resource_base_path(format!("/{}", APP_ID.replace(".", "/")))
.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 {
application: main_app,
});

View file

@ -1,6 +1,7 @@
use super::about_dialog::AboutDialog;
use super::alert::{alert, alert_w_widget};
use super::build_window::{BuildStatus, BuildWindow};
use super::cmdline_opts::CmdLineOpts;
use super::debug_view::{DebugView, DebugViewMsg};
use super::fbt_config_editor::{FbtConfigEditor, FbtConfigEditorInit, FbtConfigEditorMsg};
use super::job_worker::internal_worker::JobWorkerOut;
@ -136,6 +137,7 @@ pub enum Msg {
DebugOpenPrefix,
DebugOpenData,
OpenWivrnConfig,
HandleCommandLine(CmdLineOpts),
}
impl App {
@ -736,6 +738,11 @@ impl SimpleComponent for App {
editor.emit(WivrnConfEditorMsg::Present);
self.wivrn_conf_editor = Some(editor);
}
Msg::HandleCommandLine(opts) => {
if opts.start {
sender.input(Msg::DoStartStopXRService)
}
}
}
}

29
src/ui/cmdline_opts.rs Normal file
View 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"),
}
}
}

View file

@ -2,6 +2,7 @@ mod about_dialog;
mod alert;
pub mod app;
mod build_window;
pub mod cmdline_opts;
mod debug_view;
mod devices_box;
mod factories;