Skip to content

Commit

Permalink
Add network settings and preferences, adjust UI elements, refactor co…
Browse files Browse the repository at this point in the history
…de for settings and dashboard actions
  • Loading branch information
nullchinchilla committed Apr 25, 2024
1 parent 73cbf9d commit a379fe5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 2 additions & 0 deletions binaries/geph5-client-gui/src/l10n.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ language,Language,语言,Язык,Zabān
loading,Loading,加载中,Загрузка,Dar hāl-e bārgozārī
loading_exit_list,Loading exit list...,正在加载出口列表...,Загрузка списка выходов...,Dar hāl-e bārgozārī-ye liste xuruji-hā
logs,Logs,日志,Журналы,Lāg-hā
network_settings,Network Settings,网络设置,Настройки сети,Tanzimāt-e šabake
password,Password,密码,Пароль,Ramz-e 'obur
preferences,Preferences,首选项,Настройки,Tanzimāt-e 'olaviyat
protocol,Protocol,协议,Протокол,Protokol
save,Save,保存,Сохранить,Zaxīre
selected_server,Selected Server,选定的服务器,Выбранный сервер,Sarvar-e entexābī
Expand Down
2 changes: 1 addition & 1 deletion binaries/geph5-client-gui/src/l10n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use once_cell::sync::Lazy;
use smol_str::SmolStr;

use crate::{prefs::pref_read, settings::LANG_CODE};
use crate::settings::LANG_CODE;

static L10N_TABLE: Lazy<BTreeMap<SmolStr, BTreeMap<SmolStr, SmolStr>>> = Lazy::new(|| {
let csv = include_bytes!("l10n.csv");
Expand Down
29 changes: 22 additions & 7 deletions binaries/geph5-client-gui/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use geph5_broker_protocol::Credential;
use geph5_client::Config;
use once_cell::sync::Lazy;
Expand All @@ -7,7 +6,7 @@ use smol_str::{SmolStr, ToSmolStr};
use crate::{l10n, store_cell::StoreCell};

pub fn get_config() -> anyhow::Result<Config> {
let yaml: serde_yaml::Value = serde_yaml::from_str(include_str!("settings_default.yaml"))?;
let yaml: serde_yaml::Value = serde_yaml::from_str(include_str!("settings_default.yaml"))?;
let json: serde_json::Value = serde_json::to_value(&yaml)?;
let mut cfg: Config = serde_json::from_value(json)?;
cfg.credentials = Credential::LegacyUsernamePassword {
Expand All @@ -34,6 +33,10 @@ pub static PROXY_AUTOCONF: Lazy<StoreCell<bool>> =

pub fn render_settings(ctx: &egui::Context, ui: &mut egui::Ui) -> anyhow::Result<()> {
ctx.set_zoom_factor(ZOOM_FACTOR.get());

// Account settings
ui.separator();
ui.heading(l10n("account_info"));
USERNAME.modify(|username| {
ui.horizontal(|ui| {
ui.label(l10n("username"));
Expand All @@ -46,12 +49,17 @@ pub fn render_settings(ctx: &egui::Context, ui: &mut egui::Ui) -> anyhow::Result
ui.add(egui::TextEdit::singleline(password).password(true));
})
});

// Preferences
ui.separator();
ui.heading(l10n("preferences"));
ZOOM_FACTOR.modify(|zoom_factor| {
ui.horizontal(|ui| {
ui.label(l10n("zoom_factor"));
ui.add(egui::Slider::new(zoom_factor, 1.0..=1.5));
ui.add(egui::Slider::new(zoom_factor, 0.5..=3.0)); // Adjusted range for better control
})
});

ui.horizontal(|ui| {
ui.label(l10n("language"));
LANG_CODE.modify(|lang_code| {
Expand All @@ -68,21 +76,28 @@ pub fn render_settings(ctx: &egui::Context, ui: &mut egui::Ui) -> anyhow::Result
ui.selectable_value(lang_code, "zh".into(), "中文");
ui.selectable_value(lang_code, "fa".into(), "Fārsī");
ui.selectable_value(lang_code, "ru".into(), "Русский");
})
});
});
});

// Network settings
ui.separator();
ui.heading(l10n("network_settings"));
PROXY_AUTOCONF.modify(|proxy_autoconf| {
ui.horizontal(|ui| {
ui.label(l10n("proxy_autoconf"));
ui.add(egui::Checkbox::new(proxy_autoconf, ""));
})
});

// Configuration file
ui.separator();
// ui.heading(l10n("Configuration File"));
let config = get_config()?;
let config_json = serde_json::to_value(config)?;
let config_yaml = serde_yaml::to_string(&config_json)?;

ui.centered_and_justified(|ui| {
egui::ScrollArea::vertical().show(ui, |ui| ui.code_editor(&mut config_yaml.as_str()))
});
egui::ScrollArea::vertical().show(ui, |ui| ui.code_editor(&mut config_yaml.as_str()));

Ok(())
}
10 changes: 7 additions & 3 deletions binaries/geph5-client-gui/src/tabs/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
daemon::DAEMON,
l10n::l10n,
pac::{set_http_proxy, unset_http_proxy},
settings::get_config,
settings::{get_config, PROXY_AUTOCONF},
};

pub struct Dashboard {}
Expand Down Expand Up @@ -39,12 +39,16 @@ impl Dashboard {
if daemon.is_none() {
if ui.button(l10n("connect")).clicked() {
tracing::warn!("connect clicked");
set_http_proxy("127.0.0.1:11111".parse()?)?;
if PROXY_AUTOCONF.get() {
set_http_proxy("127.0.0.1:11111".parse()?)?;
}
*daemon = Some(geph5_client::Client::start(get_config()?));
}
} else if ui.button(l10n("disconnect")).clicked() {
tracing::warn!("disconnect clicked");
unset_http_proxy()?;
if PROXY_AUTOCONF.get() {
unset_http_proxy()?;
}
*daemon = None;
}
anyhow::Ok(())
Expand Down

0 comments on commit a379fe5

Please sign in to comment.