Skip to content

Commit 06314c7

Browse files
committed
notifications
1 parent 66e644e commit 06314c7

File tree

9 files changed

+314
-8
lines changed

9 files changed

+314
-8
lines changed

Cargo.lock

+287-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ascella"
3-
version = "0.11.0"
3+
version = "0.12.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -51,6 +51,7 @@ hyper = { version = "0.14.26", features = ["http1", "server"] }
5151
oxipng = { version = "8.0.0", default-features = false, features = [
5252
"parallel"
5353
] }
54+
notify-rust = { version = "4.8.0", features = ["images"] }
5455

5556
[target.'cfg(not(linux))'.dependencies]
5657
clipboard2 = "0"

src/ascella_config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct AscellaConfig {
2222
pub optimize_png: bool,
2323
pub optimize_timeout: u64,
2424
pub console_logging: bool,
25+
pub notifications_enabled: bool,
2526
}
2627

2728
impl AscellaConfig {

src/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ pub enum Commands {
2020
/// Screenshot a screen
2121
Screen { delay: Option<u64> },
2222
/// Upload a file
23-
Upload { file: PathBuf }
23+
Upload { file: PathBuf },
2424
}

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ fn main() -> Result<()> {
126126
.set_default("optimize_png", false)?
127127
.set_default("optimize_timeout", 100)?
128128
.set_default("console_logging", false)?
129+
.set_default("notifications_enabled", true)?
129130
.set_default(
130131
"s_type",
131132
toml::from_str::<config::Value>(&toml::to_string(&ScreenshotType::Flameshot)?)?,

src/request_handler.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use reqwest::{
88
use tokio::{process::Command, sync::mpsc::UnboundedSender};
99
use tracing::info;
1010

11-
use crate::{ascella_config::AscellaConfig, clipboard::copy, Request, RequestResponse, UploadResponse};
11+
use crate::{
12+
ascella_config::AscellaConfig, clipboard::copy, utils::ascella_notif, Request, RequestResponse, UploadResponse,
13+
};
1214

1315
pub async fn handle_event(
1416
data: Request,
@@ -157,6 +159,15 @@ pub async fn upload_file(
157159
println!("Image uploaded {}", response.url);
158160
println!("Delete URL: {}", response.delete);
159161
}
162+
if config.notifications_enabled {
163+
let mut notif = &mut ascella_notif();
164+
notif = notif.body("Upload success, url copied to clipboard!");
165+
#[cfg(all(unix, not(target_os = "macos")))]
166+
{
167+
notif = notif.image_path(&path.to_string_lossy());
168+
};
169+
notif.show()?;
170+
}
160171
Ok(response)
161172
}
162173

src/screens/settings.rs

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub fn screen(app: &mut MyApp, ui: &mut Ui, _ctx: &egui::Context) -> Result<()>
8383
ui.text_edit_singleline(window).labelled_by(token_label.id);
8484
});
8585
}
86+
ui.horizontal(|ui| ui.checkbox(&mut app.config.notifications_enabled, "Notifications Enabled"));
8687

8788
egui::CollapsingHeader::new("Advanced").show(ui, |ui| {
8889
ui.horizontal(|ui| {
@@ -91,6 +92,7 @@ pub fn screen(app: &mut MyApp, ui: &mut Ui, _ctx: &egui::Context) -> Result<()>
9192
.labelled_by(url_label.id);
9293
});
9394

95+
9496
ui.horizontal(|ui| ui.checkbox(&mut app.config.debug, "Debug Mode"));
9597
ui.heading(RichText::new("Headers").size(15.0));
9698

src/utils.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{env, path::PathBuf};
22

33
use home::home_dir;
4+
use notify_rust::Notification;
45

56
use crate::theme::{themes, Theme};
67

@@ -42,3 +43,6 @@ pub fn theme_to_name(theme: u8) -> String {
4243
_ => panic!("Invalid theme"),
4344
}
4445
}
46+
pub fn ascella_notif() -> Notification {
47+
Notification::new().summary("Ascella").clone()
48+
}

src/webserver.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::{convert::Infallible, net::SocketAddr};
22

3-
use crate::RequestResponse;
3+
use crate::{utils::ascella_notif, RequestResponse};
44
use anyhow::Result;
55
use hyper::{
66
server::conn::AddrStream,
77
service::{make_service_fn, service_fn},
88
Body, Request, Response, Server,
99
};
10+
1011
use tokio::sync::mpsc::UnboundedSender;
1112

1213
fn create_res(body: Body) -> Response<Body> {
@@ -33,6 +34,7 @@ async fn handle_req(req: Request<Body>, sender: UnboundedSender<RequestResponse>
3334
sender
3435
.send(RequestResponse::UpdateConfigFromStringSxcu(body.to_vec()))
3536
.ok();
37+
ascella_notif().body("Config Imported successfully").show()?;
3638
return Ok(create_res(Body::empty()));
3739
}
3840

@@ -70,6 +72,6 @@ pub async fn start_server(sender: UnboundedSender<RequestResponse>) -> Result<()
7072
let server = Server::bind(&addr).serve(make_service);
7173

7274
// And run forever...
73-
server.await;
75+
let _ = server.await;
7476
Ok(())
7577
}

0 commit comments

Comments
 (0)