This commit is contained in:
aprilthepink 2025-02-19 00:08:36 +01:00
parent 601a18f165
commit aba99a8e6c
15 changed files with 5432 additions and 614 deletions

39
src/bininfo.rs Normal file
View file

@ -0,0 +1,39 @@
use crate::build;
pub fn print_info() {
bunt::println!("Printing {$yellow}infos about this binary compilation{/$}! Relevant for like, {$blue+italic}security audits{/$}.");
let v = [
("branch", shadow_rs::branch()),
("is debug", shadow_rs::is_debug().to_string()),
("tag", shadow_rs::tag()),
("git_clean", shadow_rs::git_clean().to_string()),
("git_status_file", shadow_rs::git_status_file()),
("is debug", build::VERSION.to_string()),
("tag", build::CLAP_LONG_VERSION.to_string()),
("git_clean", build::BRANCH.to_string()),
("git_status_file", build::SHORT_COMMIT.to_string()),
("is debug", build::COMMIT_HASH.to_string()),
("tag", build::COMMIT_DATE.to_string()),
("git_clean", build::COMMIT_AUTHOR.to_string()),
("git_status_file", build::COMMIT_EMAIL.to_string()),
("is debug", build::BUILD_OS.to_string()),
("tag", build::RUST_VERSION.to_string()),
("git_clean", build::RUST_CHANNEL.to_string()),
("git_status_file", build::CARGO_VERSION.to_string()),
("is debug", build::PKG_VERSION.to_string()),
("tag", build::CARGO_TREE.to_string()),
("git_clean", build::CARGO_MANIFEST_DIR.to_string()),
("git_clean", build::PROJECT_NAME.to_string()),
("git_status_file", build::BUILD_TIME.to_string()),
("is debug", build::BUILD_RUST_CHANNEL.to_string()),
("tag", build::GIT_CLEAN.to_string()),
("git_clean", build::GIT_STATUS_FILE.to_string()),
];
for entry in v {
bunt::println!("|> {[green]:?} ::: {[cyan]:?}", entry.0, entry.1);
}
}

65
src/gui.rs Normal file
View file

@ -0,0 +1,65 @@
/*
* SPDX-FileCopyrightText: 2025 April Faye John <april.john@denic.de> & Contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
use egui::{TextureOptions, Vec2};
pub fn gui_main() -> eframe::Result {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 540.0]),
..Default::default()
};
eframe::run_native(
"Hai VPN",
options,
Box::new(|cc| {
// This gives us image support:
egui_extras::install_image_loaders(&cc.egui_ctx);
Ok(Box::<MyApp>::default())
}),
)
}
struct MyApp {
name: String,
age: u32,
}
impl Default for MyApp {
fn default() -> Self {
Self {
name: "Arthur".to_owned(),
age: 42,
}
}
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Hai VPN Test");
ui.horizontal(|ui| {
let name_label = ui.label("Your name: ");
ui.text_edit_singleline(&mut self.name)
.labelled_by(name_label.id);
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Increment").clicked() {
self.age += 1;
}
ui.label(format!("Hello '{}', age {}", self.name, self.age));
ui.add(
egui::Image::new(egui::include_image!("../rosenpass-darkogo.svg"))
.max_size(Vec2::new(1000., 1000.))
.maintain_aspect_ratio(true)
.texture_options(TextureOptions::NEAREST)
.corner_radius(4.0)
.fit_to_fraction(Vec2::new(0.5, 0.5)),
);
});
}
}

View file

@ -1,109 +1,68 @@
/*
The MIT License (MIT)
/*
* SPDX-FileCopyrightText: 2025 April Faye John <april.john@denic.de> & Contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
Copyright (c) 2013-2015, The Gtk-rs Project Developers.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
mod gui;
mod bininfo;
extern crate gio;
extern crate glib;
extern crate gtk;
use clap::{Subcommand, Parser};
use shadow_rs::shadow;
use gio::prelude::*;
use glib::clone;
use gtk::prelude::*;
use gtk::{IconSize, Orientation, ReliefStyle, Widget};
shadow!(build);
use std::env::args;
/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Name of the person to greet
//#[arg(short, long)]
//name: String,
struct Notebook {
notebook: gtk::Notebook,
tabs: Vec<gtk::Box>,
/// Number of times to greet
//#[arg(short, long, default_value_t = 1)]
//count: u8,
#[command(subcommand)]
command: Commands,
}
impl Notebook {
fn new() -> Notebook {
Notebook {
notebook: gtk::Notebook::new(),
tabs: Vec::new(),
}
}
fn create_tab(&mut self, title: &str, widget: Widget) -> u32 {
let close_image = gtk::Image::from_icon_name(Some("window-close"), IconSize::Button);
let button = gtk::Button::new();
let label = gtk::Label::new(Some(title));
let tab = gtk::Box::new(Orientation::Horizontal, 0);
button.set_relief(ReliefStyle::None);
button.set_focus_on_click(false);
button.add(&close_image);
tab.pack_start(&label, false, false, 0);
tab.pack_start(&button, false, false, 0);
tab.show_all();
let index = self.notebook.append_page(&widget, Some(&tab));
button.connect_clicked(clone!(@weak self.notebook as notebook => move |_| {
let index = notebook
.page_num(&widget)
.expect("Couldn't get page_num from notebook");
notebook.remove_page(Some(index));
}));
self.tabs.push(tab);
index
}
#[derive(Debug, Subcommand)]
enum Commands {
#[command(arg_required_else_help = true, about = "todo replace this cmd")]
Clone {
/// The remote to clone
remote: String,
},
#[command(about = "List compile time backed info to audit binary")]
Shadow {
outfile: Option<String>,
},
}
fn build_ui(application: &gtk::Application) {
let window = gtk::ApplicationWindow::new(application);
window.set_title("Notebook");
window.set_position(gtk::WindowPosition::Center);
window.set_default_size(640, 480);
let mut notebook = Notebook::new();
for i in 1..4 {
let title = format!("sheet {}", i);
let label = gtk::Label::new(Some(&*title));
notebook.create_tab(&title, label.upcast());
}
window.add(&notebook.notebook);
window.show_all();
}
fn main() {
let application = gtk::Application::new(
Some("com.github.gtk-rs.examples.notebook"),
Default::default(),
)
.expect("Initialization failed...");
let args = Args::parse();
application.connect_activate(|app| {
build_ui(app);
});
match args.command {
application.run(&args().collect::<Vec<_>>());
Commands::Clone { remote } => {
}
Commands::Shadow { outfile } => {
bininfo::print_info();
return;
}
};
let res = gui::gui_main();
if let Err(e) = res {
println!("{}", e);
}
}