mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-06-24 19:02:58 +03:00
add gui settings
This commit is contained in:
parent
97948aa420
commit
efc202153f
@ -10,6 +10,7 @@ fn default_true() -> bool { true }
|
|||||||
pub fn default_max_messages() -> usize { 200 }
|
pub fn default_max_messages() -> usize { 200 }
|
||||||
pub fn default_update_time() -> usize { 100 }
|
pub fn default_update_time() -> usize { 100 }
|
||||||
pub fn default_oof_update_time() -> usize { 10000 }
|
pub fn default_oof_update_time() -> usize { 10000 }
|
||||||
|
pub fn default_konata_size() -> usize { 100 }
|
||||||
pub fn default_host() -> String { "meex.lol:11234".to_string() }
|
pub fn default_host() -> String { "meex.lol:11234".to_string() }
|
||||||
pub fn default_message_format() -> String { MESSAGE_FORMAT.to_string() }
|
pub fn default_message_format() -> String { MESSAGE_FORMAT.to_string() }
|
||||||
|
|
||||||
@ -21,6 +22,8 @@ pub struct Config {
|
|||||||
#[serde(default = "default_update_time")] pub update_time: usize,
|
#[serde(default = "default_update_time")] pub update_time: usize,
|
||||||
#[serde(default = "default_oof_update_time")] pub oof_update_time: usize,
|
#[serde(default = "default_oof_update_time")] pub oof_update_time: usize,
|
||||||
#[serde(default = "default_max_messages")] pub max_messages: usize,
|
#[serde(default = "default_max_messages")] pub max_messages: usize,
|
||||||
|
#[serde(default = "default_konata_size")] pub konata_size: usize,
|
||||||
|
#[serde(default)] pub remove_gui_shit: bool,
|
||||||
#[serde(default = "default_true")] pub hide_my_ip: bool,
|
#[serde(default = "default_true")] pub hide_my_ip: bool,
|
||||||
#[serde(default)] pub show_other_ip: bool,
|
#[serde(default)] pub show_other_ip: bool,
|
||||||
#[serde(default)] pub auth_enabled: bool,
|
#[serde(default)] pub auth_enabled: bool,
|
||||||
@ -114,10 +117,12 @@ pub struct Args {
|
|||||||
#[arg(long)] pub update_time: Option<usize>,
|
#[arg(long)] pub update_time: Option<usize>,
|
||||||
#[arg(long)] pub oof_update_time: Option<usize>,
|
#[arg(long)] pub oof_update_time: Option<usize>,
|
||||||
#[arg(long)] pub max_messages: Option<usize>,
|
#[arg(long)] pub max_messages: Option<usize>,
|
||||||
|
#[arg(long)] pub konata_size: Option<usize>,
|
||||||
#[arg(long)] pub hide_my_ip: Option<bool>,
|
#[arg(long)] pub hide_my_ip: Option<bool>,
|
||||||
#[arg(long)] pub show_other_ip: Option<bool>,
|
#[arg(long)] pub show_other_ip: Option<bool>,
|
||||||
#[arg(long)] pub auth_enabled:Option <bool>,
|
#[arg(long)] pub auth_enabled:Option <bool>,
|
||||||
#[arg(long)] pub ssl_enabled: Option<bool>,
|
#[arg(long)] pub ssl_enabled: Option<bool>,
|
||||||
|
#[arg(long)] pub remove_gui_shit: Option<bool>,
|
||||||
#[arg(long)] pub chunked_enabled: Option<bool>,
|
#[arg(long)] pub chunked_enabled: Option<bool>,
|
||||||
#[arg(long)] pub formatting_enabled: Option<bool>,
|
#[arg(long)] pub formatting_enabled: Option<bool>,
|
||||||
#[arg(long)] pub commands_enabled: Option<bool>,
|
#[arg(long)] pub commands_enabled: Option<bool>,
|
||||||
@ -136,8 +141,10 @@ impl Args {
|
|||||||
if let Some(v) = self.update_time { config.update_time = v }
|
if let Some(v) = self.update_time { config.update_time = v }
|
||||||
if let Some(v) = self.oof_update_time { config.oof_update_time = v }
|
if let Some(v) = self.oof_update_time { config.oof_update_time = v }
|
||||||
if let Some(v) = self.max_messages { config.max_messages = v }
|
if let Some(v) = self.max_messages { config.max_messages = v }
|
||||||
|
if let Some(v) = self.konata_size { config.konata_size = v }
|
||||||
if let Some(v) = self.hide_my_ip { config.hide_my_ip = v }
|
if let Some(v) = self.hide_my_ip { config.hide_my_ip = v }
|
||||||
if let Some(v) = self.show_other_ip { config.show_other_ip = v }
|
if let Some(v) = self.show_other_ip { config.show_other_ip = v }
|
||||||
|
if let Some(v) = self.remove_gui_shit { config.remove_gui_shit = v }
|
||||||
if let Some(v) = self.auth_enabled { config.auth_enabled = v }
|
if let Some(v) = self.auth_enabled { config.auth_enabled = v }
|
||||||
if let Some(v) = self.ssl_enabled { config.ssl_enabled = v }
|
if let Some(v) = self.ssl_enabled { config.ssl_enabled = v }
|
||||||
if let Some(v) = self.chunked_enabled { config.chunked_enabled = v }
|
if let Some(v) = self.chunked_enabled { config.chunked_enabled = v }
|
||||||
|
@ -27,7 +27,7 @@ use gtk::{
|
|||||||
Justification, Label, ListBox, Orientation, Overlay, Picture, ScrolledWindow, Settings, Window
|
Justification, Label, ListBox, Orientation, Overlay, Picture, ScrolledWindow, Settings, Window
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{chat::config::default_oof_update_time, proto::parse_rac_url};
|
use crate::{chat::config::{default_konata_size, default_oof_update_time}, proto::parse_rac_url};
|
||||||
|
|
||||||
use super::{config::{default_max_messages, default_update_time, get_config_path, save_config, Config},
|
use super::{config::{default_max_messages, default_update_time, get_config_path, save_config, Config},
|
||||||
ctx::Context, on_send_message, parse_message, print_message, recv_tick, sanitize_message, SERVER_LIST};
|
ctx::Context, on_send_message, parse_message, print_message, recv_tick, sanitize_message, SERVER_LIST};
|
||||||
@ -176,6 +176,8 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
let commands_enabled_entry = gui_checkbox_setting!("Commands Enabled", commands_enabled, ctx, vbox);
|
let commands_enabled_entry = gui_checkbox_setting!("Commands Enabled", commands_enabled, ctx, vbox);
|
||||||
let notifications_enabled_entry = gui_checkbox_setting!("Notifications Enabled", notifications_enabled, ctx, vbox);
|
let notifications_enabled_entry = gui_checkbox_setting!("Notifications Enabled", notifications_enabled, ctx, vbox);
|
||||||
let debug_logs_entry = gui_checkbox_setting!("Debug Logs", debug_logs, ctx, vbox);
|
let debug_logs_entry = gui_checkbox_setting!("Debug Logs", debug_logs, ctx, vbox);
|
||||||
|
let konata_size_entry = gui_usize_entry_setting!("Konata Size", konata_size, ctx, vbox);
|
||||||
|
let remove_gui_shit_entry = gui_checkbox_setting!("Remove Gui Shit", remove_gui_shit, ctx, vbox);
|
||||||
|
|
||||||
let save_button = Button::builder()
|
let save_button = Button::builder()
|
||||||
.label("Save")
|
.label("Save")
|
||||||
@ -202,6 +204,8 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
#[weak] proxy_entry,
|
#[weak] proxy_entry,
|
||||||
#[weak] debug_logs_entry,
|
#[weak] debug_logs_entry,
|
||||||
#[weak] oof_update_time_entry,
|
#[weak] oof_update_time_entry,
|
||||||
|
#[weak] konata_size_entry,
|
||||||
|
#[weak] remove_gui_shit_entry,
|
||||||
move |_| {
|
move |_| {
|
||||||
let config = Config {
|
let config = Config {
|
||||||
host: host_entry.text().to_string(),
|
host: host_entry.text().to_string(),
|
||||||
@ -237,6 +241,17 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
oof_update_time
|
oof_update_time
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
konata_size: {
|
||||||
|
let konata_size = konata_size_entry.text();
|
||||||
|
|
||||||
|
if let Ok(konata_size) = konata_size.parse::<usize>() {
|
||||||
|
konata_size.max(0).min(200)
|
||||||
|
} else {
|
||||||
|
let konata_size = default_konata_size();
|
||||||
|
konata_size_entry.set_text(&konata_size.to_string());
|
||||||
|
konata_size
|
||||||
|
}
|
||||||
|
},
|
||||||
max_messages: {
|
max_messages: {
|
||||||
let max_messages = max_messages_entry.text();
|
let max_messages = max_messages_entry.text();
|
||||||
|
|
||||||
@ -249,6 +264,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
hide_my_ip: hide_my_ip_entry.is_active(),
|
hide_my_ip: hide_my_ip_entry.is_active(),
|
||||||
|
remove_gui_shit: remove_gui_shit_entry.is_active(),
|
||||||
show_other_ip: show_other_ip_entry.is_active(),
|
show_other_ip: show_other_ip_entry.is_active(),
|
||||||
auth_enabled: auth_enabled_entry.is_active(),
|
auth_enabled: auth_enabled_entry.is_active(),
|
||||||
ssl_enabled: ssl_enabled_entry.is_active(),
|
ssl_enabled: ssl_enabled_entry.is_active(),
|
||||||
@ -426,11 +442,15 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
|||||||
|
|
||||||
widget_box.set_css_classes(&["widget_box"]);
|
widget_box.set_css_classes(&["widget_box"]);
|
||||||
|
|
||||||
|
let remove_gui_shit = ctx.config(|c| c.remove_gui_shit);
|
||||||
|
|
||||||
|
if !remove_gui_shit {
|
||||||
widget_box.append(&Calendar::builder()
|
widget_box.append(&Calendar::builder()
|
||||||
.css_classes(["calendar"])
|
.css_classes(["calendar"])
|
||||||
.show_heading(false)
|
.show_heading(false)
|
||||||
.can_target(false)
|
.can_target(false)
|
||||||
.build());
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
let server_list_vbox = GtkBox::new(Orientation::Vertical, 5);
|
let server_list_vbox = GtkBox::new(Orientation::Vertical, 5);
|
||||||
|
|
||||||
@ -471,18 +491,21 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
|||||||
|
|
||||||
widget_box.append(&server_list_vbox);
|
widget_box.append(&server_list_vbox);
|
||||||
|
|
||||||
|
if !remove_gui_shit {
|
||||||
let fixed = Fixed::new();
|
let fixed = Fixed::new();
|
||||||
fixed.set_can_target(false);
|
fixed.set_can_target(false);
|
||||||
|
|
||||||
let konata = Picture::for_pixbuf(&load_pixbuf(include_bytes!("images/konata.png")).unwrap());
|
let konata_size = ctx.config(|c| c.konata_size) as i32;
|
||||||
konata.set_size_request(174, 127);
|
|
||||||
|
|
||||||
fixed.put(&konata, 325.0, 4.0);
|
let konata = Picture::for_pixbuf(&load_pixbuf(include_bytes!("images/konata.png")).unwrap());
|
||||||
|
konata.set_size_request(174 * konata_size / 100, 127 * konata_size / 100);
|
||||||
|
|
||||||
|
fixed.put(&konata, (499 - 174 * konata_size / 100) as f64, (131 - 127 * konata_size / 100) as f64);
|
||||||
|
|
||||||
let logo_gif = include_bytes!("images/logo.gif");
|
let logo_gif = include_bytes!("images/logo.gif");
|
||||||
|
|
||||||
let logo = Picture::for_pixbuf(&load_pixbuf(logo_gif).unwrap());
|
let logo = Picture::for_pixbuf(&load_pixbuf(logo_gif).unwrap());
|
||||||
logo.set_size_request(152, 64);
|
logo.set_size_request(152 * konata_size / 100, 64 * konata_size / 100);
|
||||||
|
|
||||||
let logo_anim = PixbufAnimation::from_stream(
|
let logo_anim = PixbufAnimation::from_stream(
|
||||||
&MemoryInputStream::from_bytes(
|
&MemoryInputStream::from_bytes(
|
||||||
@ -505,7 +528,8 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fixed.put(&logo, 262.0, 4.0);
|
// 262, 4
|
||||||
|
fixed.put(&logo, (436 - 174 * konata_size / 100) as f64, (131 - 127 * konata_size / 100) as f64);
|
||||||
|
|
||||||
let time = Label::builder()
|
let time = Label::builder()
|
||||||
.label(&Local::now().format("%H:%M").to_string())
|
.label(&Local::now().format("%H:%M").to_string())
|
||||||
@ -528,6 +552,8 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
|||||||
|
|
||||||
widget_box_overlay.add_overlay(&fixed);
|
widget_box_overlay.add_overlay(&fixed);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
widget_box_overlay.set_child(Some(&widget_box));
|
widget_box_overlay.set_child(Some(&widget_box));
|
||||||
|
|
||||||
main_box.append(&widget_box_overlay);
|
main_box.append(&widget_box_overlay);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
error::Error, sync::Arc, thread, time::{Duration, SystemTime, UNIX_EPOCH}
|
error::Error, sync::Arc, time::{SystemTime, UNIX_EPOCH}
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::connect_rac;
|
use crate::connect_rac;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user