Skip to content

Commit

Permalink
Merge pull request #8 from n3tw0rth/dev
Browse files Browse the repository at this point in the history
chore: some updates
  • Loading branch information
n3tw0rth authored Jan 15, 2025
2 parents 6866dd3 + 1fa4218 commit 31e44db
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Install directly from source
$ cd completion-notifier
$ ./install.sh

$ completion-notifier -v
$ completion-notifier -h
```

Expand All @@ -28,6 +27,18 @@ It is easy as passing the command directly, by default a notification will be se
```shell
$ completion-notifier ping google.com
```
### Profiles
Profiles can used to group notification clients by a specific name.

```toml
[profiles.default]
sendto = ["desktop","email.default"]

[profiles.work]
sendto = ["desktop","gchat.work","email.work"]

```

### Triggers
Triggers can be added to send custom notifications based on the requirement. for example,

Expand Down
1 change: 0 additions & 1 deletion src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, FromRepr};

#[derive(Default, Debug, Clone, Copy, Display, FromRepr, EnumIter)]
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use tokio::fs::File;
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
use tokio::io::{AsyncReadExt, AsyncWriteExt};

use super::Config;

Expand Down
43 changes: 21 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ use std::collections::HashMap;

use clap::Parser;
use serde::Deserialize;
use tokio::io::{self, AsyncBufReadExt, BufReader};
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::process::Command;

mod constants;
mod enums;
mod helpers;
mod notification;
mod send_emails;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None,arg_required_else_help = true,trailing_var_arg=true)]
Expand Down Expand Up @@ -62,8 +61,6 @@ struct EmailConfig {
async fn main() -> anyhow::Result<()> {
let mut args = Args::parse();

println!("{:?}", args.triggers);

let config = helpers::app_state().await?;

// helpers::handle_ctrlc().await;
Expand All @@ -88,24 +85,26 @@ async fn main() -> anyhow::Result<()> {
// following line will handle it
println!("{}", line);

// Check if the line contains a trigger string
let contains_a_trigger = args
.triggers
.as_ref()
.unwrap()
.split(",")
.collect::<Vec<_>>()
.iter()
.any(|t| line.contains(t));
if contains_a_trigger {
let _ = notification::Notification::new(
&config,
&args.profiles.as_ref().unwrap(),
"Trigger Detected".to_string(),
"".to_string(),
)
.send()
.await;
if args.triggers.is_some() {
// Check if the line contains a trigger string
let contains_a_trigger = args
.triggers
.as_ref()
.unwrap()
.split(",")
.collect::<Vec<_>>()
.iter()
.any(|t| line.contains(t));
if contains_a_trigger {
let _ = notification::Notification::new(
&config,
&args.profiles.as_ref().unwrap(),
"Trigger Detected".to_string(),
"".to_string(),
)
.send()
.await;
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/notification.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::enums::ConfigType;
use futures::stream::{self, StreamExt};
use lettre::transport::smtp::authentication::Credentials;
use lettre::{Message, SmtpTransport, Transport};
Expand All @@ -25,8 +24,6 @@ impl<'b> Notification<'b> {
}
}

pub async fn read_local_config() {}

pub async fn send_desktop(&self) -> anyhow::Result<()> {
let _ = notify_rust::Notification::new()
.summary(&self.title)
Expand All @@ -37,7 +34,7 @@ impl<'b> Notification<'b> {
}

pub async fn send_gchat(&self, gchat_config: &super::GChatConfig) -> anyhow::Result<()> {
let result = reqwest::Client::new()
let _ = reqwest::Client::new()
.post(gchat_config.webhook.to_string())
.header("Content-Type", "application/json; charset=UTF-8")
.json(&serde_json::json!({
Expand Down
1 change: 0 additions & 1 deletion src/send_emails.rs

This file was deleted.

0 comments on commit 31e44db

Please sign in to comment.