Skip to content

Commit

Permalink
Add http dependency, update l10n and zoom factor management, implemen…
Browse files Browse the repository at this point in the history
…t HTTPS proxy support
  • Loading branch information
nullchinchilla committed Apr 26, 2024
1 parent 7982706 commit 11ea270
Show file tree
Hide file tree
Showing 18 changed files with 789 additions and 60 deletions.
8 changes: 8 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 binaries/geph5-client-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tracing-subscriber = "0.3.18"
serde_json = "1.0.115"
oneshot = "0.1.6"
chrono = "0.4.38"
http = "1.1.0"

[target.'cfg(windows)'.dependencies]
winreg = "0.52.0"
Expand Down
2 changes: 1 addition & 1 deletion binaries/geph5-client-gui/src/l10n.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ connect,Connect,连接,Подключить,Etesāl
connected,Connected,已连接,Подключено,Mottasel
connection_time,Connection time,连接时间,Время соединения,Zamān-e etesāl
dashboard,Dashboard,仪表盘,Приборная панель,Dāšbord
data_used,Data used,已用流量,Использованные данные,Dādehā-ye maṣraf-šode
data_used,Data used,已用流量,Использ. данные,Dādehā-ye maṣraf-šode
disconnect,Disconnect,断开连接,Отключить,Qat'-e etesāl
disconnected,Disconnected,已断开连接,Отключено,Qat' šode ast
download_speed,Download speed,下载速度,Скорость загрузки,Sor'at-e dānlod
Expand Down
10 changes: 6 additions & 4 deletions binaries/geph5-client-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use l10n::l10n;
use logs::LogLayer;
use native_dialog::MessageType;
use prefs::{pref_read, pref_write};
use settings::render_settings;
use settings::{render_settings, ZOOM_FACTOR};
use tabs::{dashboard::Dashboard, logs::Logs};
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt, EnvFilter};

Expand Down Expand Up @@ -46,9 +46,10 @@ fn main() {

let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([350.0, 350.0])
.with_min_inner_size([350.0, 350.0])
.with_max_inner_size([350.0, 350.0]),
.with_inner_size([320.0, 320.0])
.with_min_inner_size([320.0, 320.0])
// .with_max_inner_size([320.0, 320.0])
,
// shader_version: Some(ShaderVersion::Es100),
..Default::default()
};
Expand Down Expand Up @@ -116,6 +117,7 @@ impl App {

impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
ctx.set_zoom_factor(ZOOM_FACTOR.get());
ctx.request_repaint_after(Duration::from_millis(300));
// ctx.request_repaint();

Expand Down
22 changes: 22 additions & 0 deletions binaries/geph5-client-gui/src/pac/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ pub fn set_http_proxy(proxy: SocketAddr) -> anyhow::Result<()> {
])
.output()
.context("Failed to set HTTP proxy port")?;
Command::new("gsettings")
.args(["set", "org.gnome.system.proxy.https", "enabled", "true"])
.output()
.context("Failed to enable HTTPS proxy setting")?;
Command::new("gsettings")
.args([
"set",
"org.gnome.system.proxy.https",
"host",
proxy.ip().to_string().as_str(),
])
.output()
.context("Failed to set HTTPS proxy host")?;
Command::new("gsettings")
.args([
"set",
"org.gnome.system.proxy.https",
"port",
&proxy.port().to_string(),
])
.output()
.context("Failed to set HTTPS proxy port")?;
Command::new("gsettings")
.args(["set", "org.gnome.system.proxy", "mode", "manual"])
.output()
Expand Down
28 changes: 17 additions & 11 deletions binaries/geph5-client-gui/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static USERNAME: Lazy<StoreCell<String>> =
static PASSWORD: Lazy<StoreCell<String>> =
Lazy::new(|| StoreCell::new_persistent("password", || "".to_string()));

static ZOOM_FACTOR: Lazy<StoreCell<f32>> =
pub static ZOOM_FACTOR: Lazy<StoreCell<f32>> =
Lazy::new(|| StoreCell::new_persistent("zoom_factor", || 1.0));

pub static LANG_CODE: Lazy<StoreCell<SmolStr>> =
Expand All @@ -32,8 +32,6 @@ pub static PROXY_AUTOCONF: Lazy<StoreCell<bool>> =
Lazy::new(|| StoreCell::new_persistent("proxy_autoconf", || false));

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

// Account settings
// ui.heading(l10n("account_info"));
USERNAME.modify(|username| {
Expand All @@ -55,7 +53,15 @@ pub fn render_settings(ctx: &egui::Context, ui: &mut egui::Ui) -> anyhow::Result
ZOOM_FACTOR.modify(|zoom_factor| {
ui.horizontal(|ui| {
ui.label(l10n("zoom_factor"));
ui.add(egui::Slider::new(zoom_factor, 0.5..=3.0)); // Adjusted range for better control
egui::ComboBox::from_id_source("zoom_factor_cmbx")
.selected_text(format!("{:.2}", zoom_factor))
.show_ui(ui, |ui| {
ui.selectable_value(zoom_factor, 1.0, "1.0");
ui.selectable_value(zoom_factor, 1.25, "1.25");
ui.selectable_value(zoom_factor, 1.5, "1.5");
ui.selectable_value(zoom_factor, 1.75, "1.75");
ui.selectable_value(zoom_factor, 2.0, "2.0");
});
})
});

Expand Down Expand Up @@ -89,14 +95,14 @@ pub fn render_settings(ctx: &egui::Context, ui: &mut egui::Ui) -> anyhow::Result
})
});

// 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)?;
// // 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)?;

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(())
}
1 change: 1 addition & 0 deletions binaries/geph5-client-gui/src/settings_default.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
socks5_listen: 127.0.0.1:9999
http_proxy_listen: 127.0.0.1:19999
exit_constraint: auto

broker:
Expand Down
2 changes: 1 addition & 1 deletion binaries/geph5-client-gui/src/tabs/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Dashboard {
if ui.button(l10n("connect")).clicked() {
tracing::warn!("connect clicked");
if PROXY_AUTOCONF.get() {
set_http_proxy("127.0.0.1:11111".parse()?)?;
set_http_proxy(get_config()?.http_proxy_listen)?;
}
*daemon = Some(geph5_client::Client::start(get_config()?));
}
Expand Down
6 changes: 6 additions & 0 deletions binaries/geph5-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ tap = "1.0.1"
dirs = "5.0.1"
moka = {version="0.12.5", features=["future"]}
isahc = {version="1.7.2", features=["static-ssl"]}
hyper = { version = "0.14.27", features = ["http1", "client", "server", "tcp", "stream"] }
http = "0.2.9"
tokio = { version = "1.33.0", features = ["rt", "net", "io-util"] }
bytes = "1.6.0"
pin-project = "1.1.5"
async-compat = "0.2.3"
7 changes: 6 additions & 1 deletion binaries/geph5-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
broker::{broker_client, BrokerSource},
client_inner::client_once,
database::db_read_or_wait,
http_proxy::run_http_proxy,
route::ExitConstraint,
socks5::socks5_loop,
stats::STAT_TOTAL_BYTES,
Expand All @@ -27,6 +28,7 @@ use crate::{
#[derive(Serialize, Deserialize, Clone)]
pub struct Config {
pub socks5_listen: SocketAddr,
pub http_proxy_listen: SocketAddr,
pub exit_constraint: ExitConstraint,
pub cache: Option<PathBuf>,
pub broker: Option<BrokerSource>,
Expand Down Expand Up @@ -120,6 +122,9 @@ async fn client_main(ctx: AnyCtx<Config>) -> anyhow::Result<()> {
|e| tracing::warn!("client died and restarted: {:?}", e)
)),
);
socks5_loop(&ctx).race(auth_loop(&ctx)).await
socks5_loop(&ctx)
.race(run_http_proxy(&ctx))
.race(auth_loop(&ctx))
.await
}
}
17 changes: 15 additions & 2 deletions binaries/geph5-client/src/client_inner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyctx::AnyCtx;
use anyhow::Context;
use clone_macro::clone;
use ed25519_dalek::VerifyingKey;
use futures_util::{future::try_join_all, AsyncReadExt as _};
use geph5_misc_rpc::{
Expand All @@ -21,15 +22,27 @@ use std::{

use stdcode::StdcodeSerializeExt;

use crate::{auth::get_connect_token, client::CtxField, route::get_dialer};
use crate::{
auth::get_connect_token, client::CtxField, route::get_dialer, stats::STAT_TOTAL_BYTES,
};

use super::Config;

pub async fn open_conn(ctx: &AnyCtx<Config>, dest_addr: &str) -> anyhow::Result<picomux::Stream> {
let (send, recv) = oneshot::channel();
let elem = (dest_addr.to_string(), send);
let _ = ctx.get(CONN_REQ_CHAN).0.send(elem).await;
Ok(recv.await?)
let mut conn = recv.await?;
let ctx = ctx.clone();
conn.set_on_read(clone!([ctx], move |n| {
ctx.get(STAT_TOTAL_BYTES)
.fetch_add(n as _, Ordering::Relaxed);
}));
conn.set_on_write(clone!([ctx], move |n| {
ctx.get(STAT_TOTAL_BYTES)
.fetch_sub(n as _, Ordering::Relaxed);
}));
Ok(conn)
}

type ChanElem = (String, oneshot::Sender<picomux::Stream>);
Expand Down
Loading

0 comments on commit 11ea270

Please sign in to comment.