Skip to content

Commit

Permalink
Merge pull request #70 from Eliasin/main
Browse files Browse the repository at this point in the history
Make welcome message configurable
  • Loading branch information
rharish101 committed Jun 5, 2024
2 parents 079f274 + 0655ad4 commit 1b3b532
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Currently, the following can be configured:
* Background image
* How the background image fits the screen (needs GTK 4.8+ support compiled)
* Environment variables for created sessions
* Greeting message
* GTK theme
* Dark mode
* Icon theme
Expand Down
4 changes: 4 additions & 0 deletions regreet.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ reboot = [ "systemctl", "reboot" ]

# The command used to shut down the system
poweroff = [ "systemctl", "poweroff" ]

[appearance]
# The message that initially displays on startup
greeting_msg = "Welcome back!"
26 changes: 25 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ use std::path::Path;

use serde::{Deserialize, Serialize};

use crate::constants::{POWEROFF_CMD, REBOOT_CMD};
use crate::constants::{GREETING_MSG, POWEROFF_CMD, REBOOT_CMD};
use crate::tomlutils::load_toml;

#[derive(Deserialize, Serialize)]
pub struct AppearanceSettings {
#[serde(default = "default_greeting_msg")]
pub greeting_msg: String,
}

impl Default for AppearanceSettings {
fn default() -> Self {
AppearanceSettings {
greeting_msg: default_greeting_msg(),
}
}
}

/// Struct holding all supported GTK settings
#[derive(Default, Deserialize, Serialize)]
pub struct GtkSettings {
Expand Down Expand Up @@ -72,9 +86,15 @@ fn default_poweroff_command() -> Vec<String> {
shlex::split(POWEROFF_CMD).expect("Unable to lex poweroff command")
}

fn default_greeting_msg() -> String {
GREETING_MSG.to_string()
}

/// The configuration struct
#[derive(Default, Deserialize, Serialize)]
pub struct Config {
#[serde(default)]
appearance: AppearanceSettings,
#[serde(default)]
env: HashMap<String, String>,
#[serde(default)]
Expand Down Expand Up @@ -110,4 +130,8 @@ impl Config {
pub fn get_sys_commands(&self) -> &SystemCommands {
&self.commands
}

pub fn get_default_message(&self) -> String {
self.appearance.greeting_msg.clone()
}
}
3 changes: 3 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub const REBOOT_CMD: &str = env_or!("REBOOT_CMD", "reboot");
/// Default command for shutting down
pub const POWEROFF_CMD: &str = env_or!("POWEROFF_CMD", "poweroff");

/// Default greeting message
pub const GREETING_MSG: &str = "Welcome back!";

/// Directories separated by `:`, containing desktop files for X11/Wayland sessions
pub const SESSION_DIRS: &str = env_or!(
"SESSION_DIRS",
Expand Down
11 changes: 6 additions & 5 deletions src/gui/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use crate::sysutil::SysUtil;

use super::messages::{CommandMsg, UserSessInfo};

pub(super) const DEFAULT_MSG: &str = "Welcome back!";
const ERROR_MSG_CLEAR_DELAY: u64 = 5;

#[derive(PartialEq)]
Expand Down Expand Up @@ -95,8 +94,10 @@ pub struct Greeter {

impl Greeter {
pub(super) async fn new(config_path: &Path) -> Self {
let config = Config::new(config_path);

let updates = Updates {
message: DEFAULT_MSG.to_string(),
message: config.get_default_message(),
error: None,
input: String::new(),
manual_user_mode: false,
Expand All @@ -117,8 +118,8 @@ impl Greeter {
greetd_client,
sys_util: SysUtil::new().expect("Couldn't read available users and sessions"),
cache: Cache::new(),
config: Config::new(config_path),
sess_info: None,
config,
updates,
}
}
Expand Down Expand Up @@ -210,7 +211,7 @@ impl Greeter {
};
self.updates.set_input(String::new());
self.updates.set_input_mode(InputMode::None);
self.updates.set_message(DEFAULT_MSG.to_string());
self.updates.set_message(self.config.get_default_message())
}

/// Create a greetd session, i.e. start a login attempt for the current user.
Expand Down Expand Up @@ -315,7 +316,7 @@ impl Greeter {
// Greetd has sent an error message that should be displayed and logged
self.updates.set_input_mode(InputMode::None);
// Reset outdated info message, if any
self.updates.set_message(DEFAULT_MSG.to_string());
self.updates.set_message(self.config.get_default_message());
self.display_error(
sender,
&capitalize(&auth_message),
Expand Down

0 comments on commit 1b3b532

Please sign in to comment.