improv(input-sources): gracefully exit if keyboard layouts data could not be obtained

This commit is contained in:
Michael Aaron Murphy 2024-05-06 15:19:40 +02:00 committed by Michael Murphy
parent 33cb23f04f
commit b9308af4b7
3 changed files with 18 additions and 5 deletions

View file

@ -9,6 +9,15 @@ mod localize;
mod window;
pub fn run() -> cosmic::iced::Result {
localize::localize();
let layouts = match xkb_data::keyboard_layouts() {
Ok(layouts) => layouts,
Err(why) => {
tracing::error!("could not get keyboard layouts data: {:?}", why);
return Ok(());
}
};
let (config_handler, config) = match cosmic_config::Config::new(window::ID, CONFIG_VERSION) {
Ok(config_handler) => {
let config = match Config::get_entry(&config_handler) {
@ -46,8 +55,9 @@ pub fn run() -> cosmic::iced::Result {
let flags = Flags {
comp_config,
comp_config_handler,
config_handler: config_handler,
config: config,
config_handler,
config,
layouts,
};
cosmic::applet::run::<Window>(true, flags)
}

View file

@ -1,3 +1,6 @@
fn main() -> cosmic::iced::Result {
tracing_subscriber::fmt::init();
let _ = tracing_log::LogTracer::init();
cosmic_applet_input_sources::run()
}

View file

@ -38,12 +38,13 @@ pub enum Message {
SetActiveLayout(ActiveLayout),
KeyboardSettings,
}
#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct Flags {
pub config_handler: Option<cosmic_config::Config>,
pub config: Config,
pub comp_config: CosmicCompConfig,
pub comp_config_handler: Option<cosmic_config::Config>,
pub layouts: KeyboardLayouts,
}
impl cosmic::Application for Window {
type Executor = cosmic::SingleThreadExecutor;
@ -64,10 +65,9 @@ impl cosmic::Application for Window {
core: Core,
flags: Self::Flags,
) -> (Self, Command<cosmic::app::Message<Self::Message>>) {
let layouts = xkb_data::keyboard_layouts().unwrap();
let window = Window {
comp_config_handler: flags.comp_config_handler,
layouts,
layouts: flags.layouts,
core,
config: flags.config,
config_handler: flags.config_handler,