Skip to content

Commit 29a8685

Browse files
Improve events organization (#2801)
## Problem While moving some logic to separate packages, we found out some circular dependency problems with some types, especially with `http::Event` struct from *agama-lib* package. ## Solution * Extract to *agama-utils* the types used for the HTTP API . In the future, the CLI will use these types without the need to depend on types from all Agama packages. * The events of the new API are separated from the old events. * The events are shared to all the packages, making possilbe to use a single broadcast channel to emit events. * Remove the events listener which is not needed anymore. * The manager emits a `StatusChanged` event. * The progress adds information of the `ProgressChanged` event. * The progress emits a `ProgressFinished` event everytime a progress is finished.
2 parents 3313741 + 4152553 commit 29a8685

File tree

103 files changed

+1325
-1188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1325
-1188
lines changed

rust/Cargo.lock

Lines changed: 4 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/agama-l10n/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ edition.workspace = true
66

77
[dependencies]
88
anyhow = "1.0.99"
9-
merge-struct = "0.1.0"
10-
serde = { version = "1.0.219", features = ["derive"] }
119
thiserror = "2.0.16"
1210
agama-locale-data = { path = "../agama-locale-data" }
1311
agama-utils = { path = "../agama-utils" }
1412
regex = "1.11.2"
1513
tracing = "0.1.41"
16-
serde_with = "3.14.0"
17-
utoipa = "5.4.0"
1814
gettext-rs = { version = "0.7.2", features = ["gettext-system"] }
19-
serde_json = "1.0.143"
2015
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "sync"] }
2116
tokio-stream = "0.1.17"
2217
zbus = "5.11.0"

rust/agama-l10n/src/config.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) [2024] SUSE LLC
1+
// Copyright (c) [2025] SUSE LLC
22
//
33
// All Rights Reserved.
44
//
@@ -18,39 +18,42 @@
1818
// To contact SUSE LLC about this file by physical or electronic mail, you may
1919
// find current contact information at www.suse.com.
2020

21-
//! Representation of the localization settings
21+
use crate::service;
22+
use agama_locale_data::{KeymapId, LocaleId, TimezoneId};
23+
use agama_utils::api;
24+
use agama_utils::api::l10n::SystemInfo;
2225

23-
use crate::extended_config::ExtendedConfig;
24-
use serde::{Deserialize, Serialize};
25-
26-
/// User configuration for the localization of the target system.
27-
///
28-
/// This configuration is provided by the user, so all the values are optional.
29-
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, utoipa::ToSchema)]
30-
#[schema(as = l10n::UserConfig)]
31-
#[serde(rename_all = "camelCase")]
26+
#[derive(Clone, PartialEq)]
3227
pub struct Config {
33-
/// Locale (e.g., "en_US.UTF-8").
34-
#[serde(skip_serializing_if = "Option::is_none")]
35-
#[serde(alias = "language")]
36-
pub locale: Option<String>,
37-
/// Keymap (e.g., "us", "cz(qwerty)", etc.).
38-
#[serde(skip_serializing_if = "Option::is_none")]
39-
#[serde(alias = "keyboard")]
40-
pub keymap: Option<String>,
41-
/// Timezone (e.g., "Europe/Berlin").
42-
#[serde(skip_serializing_if = "Option::is_none")]
43-
pub timezone: Option<String>,
28+
pub locale: LocaleId,
29+
pub keymap: KeymapId,
30+
pub timezone: TimezoneId,
4431
}
4532

46-
/// Converts the localization configuration, which contains values for all the
47-
/// elements, into a user configuration.
48-
impl From<&ExtendedConfig> for Config {
49-
fn from(config: &ExtendedConfig) -> Self {
50-
Config {
51-
locale: Some(config.locale.to_string()),
52-
keymap: Some(config.keymap.to_string()),
53-
timezone: Some(config.timezone.to_string()),
33+
impl Config {
34+
pub fn new_from(system: &SystemInfo) -> Self {
35+
Self {
36+
locale: system.locale.clone(),
37+
keymap: system.keymap.clone(),
38+
timezone: system.timezone.clone(),
39+
}
40+
}
41+
42+
pub fn merge(&self, config: &api::l10n::Config) -> Result<Self, service::Error> {
43+
let mut merged = self.clone();
44+
45+
if let Some(language) = &config.locale {
46+
merged.locale = language.parse()?
5447
}
48+
49+
if let Some(keyboard) = &config.keymap {
50+
merged.keymap = keyboard.parse()?
51+
}
52+
53+
if let Some(timezone) = &config.timezone {
54+
merged.timezone = timezone.parse()?;
55+
}
56+
57+
Ok(merged)
5558
}
5659
}

rust/agama-l10n/src/extended_config.rs

Lines changed: 0 additions & 57 deletions
This file was deleted.

rust/agama-l10n/src/lib.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,8 @@ pub use service::Service;
4444
mod model;
4545
pub use model::{Model, ModelAdapter};
4646

47-
mod system_info;
48-
pub use system_info::SystemInfo;
49-
5047
mod config;
51-
pub use config::Config;
52-
53-
mod proposal;
54-
pub use proposal::Proposal;
55-
56-
pub mod event;
57-
pub use event::Event;
58-
48+
mod dbus;
5949
pub mod helpers;
6050
pub mod message;
61-
62-
mod dbus;
63-
mod extended_config;
6451
mod monitor;

rust/agama-l10n/src/message.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
// To contact SUSE LLC about this file by physical or electronic mail, you may
1919
// find current contact information at www.suse.com.
2020

21-
use crate::{config::Config, proposal::Proposal, system_info::SystemInfo};
2221
use agama_locale_data::{KeymapId, LocaleId};
2322
use agama_utils::actor::Message;
24-
use serde::Deserialize;
23+
use agama_utils::api;
24+
use agama_utils::api::l10n::{Proposal, SystemInfo};
2525

2626
#[derive(Clone)]
2727
pub struct GetSystem;
@@ -44,16 +44,10 @@ impl<T> SetSystem<T> {
4444
}
4545
}
4646

47-
#[derive(Clone, Debug, Deserialize, utoipa::ToSchema)]
48-
pub struct SystemConfig {
49-
pub locale: Option<String>,
50-
pub keymap: Option<String>,
51-
}
52-
5347
pub struct GetConfig;
5448

5549
impl Message for GetConfig {
56-
type Reply = Config;
50+
type Reply = api::l10n::Config;
5751
}
5852

5953
pub struct SetConfig<T> {

rust/agama-l10n/src/model.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,45 @@
1919
// find current contact information at www.suse.com.
2020

2121
mod keyboard;
22-
pub use keyboard::{Keymap, KeymapsDatabase};
22+
pub use keyboard::KeymapsDatabase;
2323

2424
mod locale;
25-
pub use locale::{LocaleEntry, LocalesDatabase};
25+
pub use locale::LocalesDatabase;
2626

2727
mod timezone;
28-
pub use timezone::{TimezoneEntry, TimezonesDatabase};
28+
pub use timezone::TimezonesDatabase;
2929

3030
use crate::{helpers, service};
3131
use agama_locale_data::{KeymapId, LocaleId, TimezoneId};
32+
use agama_utils::api::l10n::SystemInfo;
3233
use regex::Regex;
33-
use std::{env, fs::OpenOptions, io::Write, process::Command};
34+
use std::env;
35+
use std::fs::OpenOptions;
36+
use std::io::Write;
37+
use std::process::Command;
3438

3539
/// Abstract the localization-related configuration from the underlying system.
3640
///
3741
/// It offers an API to query and set different localization elements of a
3842
/// system. This trait can be implemented to replace the real system during
3943
/// tests.
4044
pub trait ModelAdapter: Send + 'static {
45+
/// Reads the system info.
46+
fn read_system_info(&self) -> SystemInfo {
47+
let locales = self.locales_db().entries().clone();
48+
let keymaps = self.keymaps_db().entries().clone();
49+
let timezones = self.timezones_db().entries().clone();
50+
51+
SystemInfo {
52+
locales,
53+
keymaps,
54+
timezones,
55+
locale: self.locale(),
56+
keymap: self.keymap().unwrap(),
57+
timezone: Default::default(),
58+
}
59+
}
60+
4161
/// Locales database.
4262
fn locales_db(&self) -> &LocalesDatabase;
4363

rust/agama-l10n/src/model/keyboard.rs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,12 @@
1818
// To contact SUSE LLC about this file by physical or electronic mail, you may
1919
// find current contact information at www.suse.com.
2020

21-
use agama_locale_data::{get_localectl_keymaps, keyboard::XkbConfigRegistry, KeymapId};
22-
use gettextrs::*;
23-
use serde::ser::{Serialize, SerializeStruct};
21+
use agama_locale_data::get_localectl_keymaps;
22+
use agama_locale_data::keyboard::XkbConfigRegistry;
23+
use agama_locale_data::KeymapId;
24+
use agama_utils::api::l10n::Keymap;
2425
use std::collections::HashMap;
2526

26-
// Minimal representation of a keymap
27-
#[derive(Clone, Debug, utoipa::ToSchema)]
28-
pub struct Keymap {
29-
/// Keymap identifier (e.g., "us")
30-
pub id: KeymapId,
31-
/// Keymap description
32-
description: String,
33-
}
34-
35-
impl Keymap {
36-
pub fn new(id: KeymapId, description: &str) -> Self {
37-
Self {
38-
id,
39-
description: description.to_string(),
40-
}
41-
}
42-
43-
pub fn localized_description(&self) -> String {
44-
gettext(&self.description)
45-
}
46-
}
47-
48-
impl Serialize for Keymap {
49-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
50-
where
51-
S: serde::Serializer,
52-
{
53-
let mut state = serializer.serialize_struct("Keymap", 2)?;
54-
state.serialize_field("id", &self.id.to_string())?;
55-
state.serialize_field("description", &self.localized_description())?;
56-
state.end()
57-
}
58-
}
59-
6027
/// Represents the keymaps database.
6128
///
6229
/// The list of supported keymaps is read from `systemd-localed` and the

rust/agama-l10n/src/model/locale.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,10 @@
2121
//! This module provides support for reading the locales database.
2222
2323
use agama_locale_data::LocaleId;
24+
use agama_utils::api::l10n::LocaleEntry;
2425
use anyhow::Context;
25-
use serde::Serialize;
26-
use serde_with::{serde_as, DisplayFromStr};
2726
use std::{fs, process::Command};
2827

29-
/// Represents a locale, including the localized language and territory.
30-
#[serde_as]
31-
#[derive(Debug, Serialize, Clone, utoipa::ToSchema)]
32-
pub struct LocaleEntry {
33-
/// The locale code (e.g., "es_ES.UTF-8").
34-
#[serde_as(as = "DisplayFromStr")]
35-
pub id: LocaleId,
36-
/// Localized language name (e.g., "Spanish", "Español", etc.)
37-
pub language: String,
38-
/// Localized territory name (e.g., "Spain", "España", etc.)
39-
pub territory: String,
40-
/// Console font
41-
pub consolefont: Option<String>,
42-
}
43-
4428
/// Represents the locales database.
4529
///
4630
/// The list of supported locales is read from `systemd-localed`. However, the

0 commit comments

Comments
 (0)