Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Gabriel committed Apr 4, 2024
1 parent 205a7a0 commit aafe53d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ use relm4::gtk::gio::{prelude::ApplicationExt, Notification};

use relm4::gtk::{IconLookupFlags, IconTheme, TextDirection};

pub fn show_notification(msg: &str) {
pub fn log_result(msg: &str) {
println!("{}", msg);
show_notification(msg);
}

fn show_notification(msg: &str) {
// construct
let notification = Notification::new("Satty");
notification.set_body(Some(msg));
Expand Down
16 changes: 6 additions & 10 deletions src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use relm4::{gtk, Component, ComponentParts, ComponentSender};
use crate::configuration::APP_CONFIG;
use crate::femtovg_area::FemtoVGArea;
use crate::math::Vec2D;
use crate::notification::show_notification;
use crate::notification::log_result;
use crate::style::Style;
use crate::tools::{Tool, ToolEvent, ToolUpdateResult, ToolsManager};
use crate::ui::toolbars::ToolbarEvent;
Expand Down Expand Up @@ -186,9 +186,7 @@ impl SketchBoard {

// TODO: we could support more data types
if !output_filename.ends_with(".png") {
let msg = "The only supported format is png, but the filename does not end in png";
println!("{msg}");
show_notification(msg);
log_result("The only supported format is png, but the filename does not end in png");
return;
}

Expand All @@ -200,12 +198,10 @@ impl SketchBoard {
}
};

let msg = match fs::write(&output_filename, data) {
Err(e) => format!("Error while saving file: {e}"),
Ok(_) => format!("File saved to '{}'.", &output_filename),
match fs::write(&output_filename, data) {
Err(e) => log_result(&format!("Error while saving file: {e}")),
Ok(_) => log_result(&format!("File saved to '{}'.", &output_filename)),
};

show_notification(&msg);
}

fn save_to_clipboard(&self, texture: &impl IsA<Texture>) -> anyhow::Result<()> {
Expand Down Expand Up @@ -249,7 +245,7 @@ impl SketchBoard {
match result {
Err(e) => println!("Error saving {e}"),
Ok(()) => {
show_notification("Copied to clipboard.");
log_result("Copied to clipboard.");

// TODO: rethink order and messaging patterns
if APP_CONFIG.read().save_after_copy() {
Expand Down

0 comments on commit aafe53d

Please sign in to comment.