Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async-global-executor = "3.0.0"
futures-util = "0.3.30"
log = "0.4.22"
lazy_static = "^1.4"
gettext-rs = "0.7"

[dependencies.glib]
version = "0.18"
Expand Down
2 changes: 1 addition & 1 deletion resources/lockscreen-user-session.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<interface domain="phrog">
<requires lib="gtk+" version="3.20"/>
<template class="PhrogUserSessionPage" parent="GtkBox">
<property name="visible">True</property>
Expand Down
36 changes: 36 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,45 @@ mod user_session_page;

use anyhow::{anyhow, Context};
use gtk::{gdk, gio};
use std::path::Path;
use wayland_client::protocol::wl_registry;

pub const APP_ID: &str = "mobi.phosh.phrog";
pub const TEXT_DOMAIN: &str = "phrog";
pub const LOCALEDIR: &str = "/usr/share/locale";

pub fn i18n_setup(
locale_dir: &Path,
locale: Option<&str>,
language: Option<&str>,
) -> anyhow::Result<()> {
if let Some(locale) = locale {
std::env::set_var("LC_ALL", locale);
std::env::set_var("LANG", locale);
}

if let Some(language) = language {
std::env::set_var("LANGUAGE", language);
}

gettextrs::setlocale(gettextrs::LocaleCategory::LcAll, "").with_context(|| {
if let Some(locale) = locale {
format!("failed to set process locale from environment (requested {locale})")
} else {
"failed to set process locale from environment".to_string()
}
})?;
gettextrs::textdomain("phosh").context("failed to set gettext domain")?;
gettextrs::bind_textdomain_codeset("phosh", "UTF-8")
.context("failed to set phosh gettext domain codeset")?;
gettextrs::bindtextdomain("phosh", locale_dir)
.context("failed to bind phosh gettext domain")?;
gettextrs::bind_textdomain_codeset(TEXT_DOMAIN, "UTF-8")
.context("failed to set phrog gettext domain codeset")?;
gettextrs::bindtextdomain(TEXT_DOMAIN, locale_dir)
.context("failed to bind phrog gettext domain")?;
Ok(())
}

struct DetectPhoc(bool);

Expand Down
16 changes: 11 additions & 5 deletions src/lockscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use greetd_ipc::ErrorType::AuthError;
use greetd_ipc::{Request, Response};
use gtk::glib;

use crate::TEXT_DOMAIN;

static G_LOG_DOMAIN: &str = "phrog-lockscreen";

glib::wrapper! {
Expand All @@ -24,7 +26,7 @@ impl Default for Lockscreen {
}

mod imp {
use super::G_LOG_DOMAIN;
use super::{tr, G_LOG_DOMAIN};
use crate::lockscreen::fake_greetd_interaction;
use crate::shell::Shell;
use crate::user_session_page::UserSessionPage;
Expand Down Expand Up @@ -248,7 +250,7 @@ mod imp {

if let Err(err) = resp {
error!("failed to send greetd request: {:?}", err);
self.obj().set_unlock_status("Error, please try again");
self.obj().set_unlock_status(&tr("Error, please try again"));
self.obj().set_sensitive(true);
return None;
}
Expand Down Expand Up @@ -301,7 +303,7 @@ mod imp {
} => {
warn!("auth error: '{}'", description);
self.obj()
.set_unlock_status("Login failed, please try again");
.set_unlock_status(&tr("Login failed, please try again"));
self.obj().shake_pin_entry();
// Greetd IPC dox seem to suggest that this isn't necessary, but then agreety
// does this, and if we don't we get a "session is already being configured"
Expand Down Expand Up @@ -344,17 +346,21 @@ mod imp {
}
}

fn tr(msgid: &str) -> String {
gettextrs::dgettext(TEXT_DOMAIN, msgid)
}

fn fake_greetd_interaction(req: Request) -> anyhow::Result<Response> {
match req {
Request::CreateSession { .. } => anyhow::Ok(Response::AuthMessage {
auth_message_type: Secret,
auth_message: "Password:".into(),
auth_message: tr("Password:"),
}),
Request::PostAuthMessageResponse { response } => {
if response.is_none() || response.unwrap() != "0" {
anyhow::Ok(Response::Error {
error_type: AuthError,
description: String::from("Incorrect password (hint: it's '0')"),
description: tr("Incorrect password (hint: it's '0')"),
})
} else {
anyhow::Ok(Response::Success)
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use libphosh::prelude::*;
use libphosh::WallClock;
use nix::libc::SIGTERM;
use phrog::shell::Shell;
use phrog::LOCALEDIR;

static G_LOG_DOMAIN: &str = "phrog";

Expand Down Expand Up @@ -40,6 +41,7 @@ fn main() -> anyhow::Result<()> {

let shell: Shell = Object::builder()
.property("fake-greetd", args.fake)
.property("locale-dir", LOCALEDIR)
.property("overview-visible", false)
.build();
shell.set_default();
Expand Down
28 changes: 27 additions & 1 deletion src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ glib::wrapper! {
impl Shell {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Object::builder().build()
Object::builder()
.property("locale-dir", crate::LOCALEDIR)
.build()
}
}

Expand Down Expand Up @@ -50,6 +52,15 @@ mod imp {
#[property(get, set)]
pub sessions: RefCell<Option<ListStore>>,

#[property(get, set, construct_only)]
locale_dir: RefCell<String>,

#[property(get, set, construct_only)]
locale: RefCell<Option<String>>,

#[property(get, set, construct_only)]
language: RefCell<Option<String>>,

provider: Cell<CssProvider>,
pub dbus_connection: OnceCell<zbus::Connection>,
}
Expand All @@ -64,6 +75,21 @@ mod imp {
#[glib::derived_properties]
impl ObjectImpl for Shell {
fn constructed(&self) {
let locale_dir = {
let locale_dir = self.locale_dir.borrow();
if locale_dir.is_empty() {
std::path::PathBuf::from(crate::LOCALEDIR)
} else {
std::path::PathBuf::from(locale_dir.as_str())
}
};
let locale = self.locale.borrow().clone();
let language = self.language.borrow().clone();
if let Err(err) = crate::i18n_setup(&locale_dir, locale.as_deref(), language.as_deref())
{
warn!("failed to initialize i18n: {err:#}");
}

let system_dbus = async_global_executor::block_on(zbus::Connection::system()).unwrap();
self.dbus_connection.set(system_dbus).unwrap();

Expand Down
4 changes: 4 additions & 0 deletions src/user_session_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mod imp {
use crate::shell::Shell;
use crate::user::User;
use crate::APP_ID;
use crate::TEXT_DOMAIN;
use futures_util::select;
use futures_util::StreamExt;
use glib::subclass::InitializingObject;
Expand Down Expand Up @@ -106,6 +107,9 @@ mod imp {
let shell = Shell::default();
let conn = shell.imp().dbus_connection.clone().into_inner().unwrap();

let session_title = gettextrs::dgettext(TEXT_DOMAIN, "Session");
self.row_sessions.set_title(Some(session_title.as_str()));

self.box_users
.connect_row_activated(clone!(@weak self as this => move |_, _| {
this.obj().emit_by_name::<()>("login", &[]);
Expand Down
Loading
Loading