Skip to content

Commit

Permalink
Merge pull request #125 from martinling/about-dialog
Browse files Browse the repository at this point in the history
Add `--version` option and About dialog
  • Loading branch information
martinling authored Jul 12, 2024
2 parents 7c0fe3f + 003308c commit 50d0f41
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
21 changes: 21 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 @@ -47,6 +47,7 @@ lrumap = "0.1.0"
memmap2 = "0.9.4"
page_size = "0.6.0"
anyhow = { version = "1.0.79", features = ["backtrace"] }
git-version = "0.3.9"

[dev-dependencies]
serde = { version = "1.0.196", features = ["derive"] }
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ fn have_argument(name: &str) -> bool {
}

fn main() {
if have_argument("--test-cynthion") {
if have_argument("--version") {
println!("Packetry version {}", git_version::git_version!())
} else if have_argument("--test-cynthion") {
let save_captures = have_argument("--save-captures");
test_cynthion::run_test(save_captures);
} else {
Expand Down
45 changes: 44 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ use std::sync::Mutex;

use anyhow::{Context as ErrorContext, Error, bail};

use gtk::gio::ListModel;
use gtk::gio::{ActionEntry, ListModel, Menu, MenuItem, SimpleActionGroup};
use gtk::glib::{Object, SignalHandlerId};
use gtk::{
prelude::*,
AboutDialog,
Align,
Application,
ApplicationWindow,
Button,
DropDown,
InfoBar,
Label,
License,
ListItem,
ColumnView,
ColumnViewColumn,
MenuButton,
MessageType,
ProgressBar,
ResponseType,
Expand Down Expand Up @@ -370,13 +373,27 @@ pub fn activate(application: &Application) -> Result<(), Error> {
let selector = DeviceSelector::new()?;
capture_button.set_sensitive(selector.device_available());

let menu = Menu::new();
let about_item = MenuItem::new(Some("About..."), Some("actions.about"));
menu.append_item(&about_item);
let menu_button = MenuButton::builder()
.menu_model(&menu)
.build();
let action_group = SimpleActionGroup::new();
let action_about = ActionEntry::builder("about")
.activate(|_, _, _| display_error(show_about()))
.build();
action_group.add_action_entries([action_about]);
window.insert_action_group("actions", Some(&action_group));

action_bar.pack_start(&open_button);
action_bar.pack_start(&save_button);
action_bar.pack_start(&gtk::Separator::new(Orientation::Vertical));
action_bar.pack_start(&scan_button);
action_bar.pack_start(&capture_button);
action_bar.pack_start(&stop_button);
action_bar.pack_start(&selector.container);
action_bar.pack_end(&menu_button);

let warning = DeviceWarning::new();
warning.update(selector.device_unusable());
Expand Down Expand Up @@ -977,6 +994,32 @@ pub fn stop_cynthion() -> Result<(), Error> {
})
}

fn show_about() -> Result<(), Error> {
const GIT_VERSION: &str = git_version::git_version!();
const LICENSE: &str = include_str!("../LICENSE");
let about = AboutDialog::builder()
.program_name("Packetry")
.version(format!("Version: {GIT_VERSION}"))
.comments("A fast, intuitive USB 2.0 protocol analysis application")
.copyright("© 2022-2024 Great Scott Gadgets. All rights reserved.")
.license_type(License::Bsd3)
.license(LICENSE)
.website("https://github.com/greatscottgadgets/packetry/")
.website_label("https://github.com/greatscottgadgets/packetry/")
.system_information(format!(
"OS: {}\n\
Architecture: {}\n\
GTK version: {}.{}.{}",
std::env::consts::OS,
std::env::consts::ARCH,
gtk::major_version(),
gtk::minor_version(),
gtk::micro_version()))
.build();
about.present();
Ok(())
}

pub fn display_error(result: Result<(), Error>) {
#[cfg(not(test))]
if let Err(e) = result {
Expand Down

0 comments on commit 50d0f41

Please sign in to comment.