aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-10-29 14:54:11 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-10-29 21:27:26 +0100
commitbddf2324b1fd1c440127432cbd93ac64afc7ca85 (patch)
tree8898c591b5a5bcc7ffede8fe985f3003592514f8 /mumd/src
parent8cd74edc6079d26746cd07838c99d3b60228b87f (diff)
downloadmum-bddf2324b1fd1c440127432cbd93ac64afc7ca85.tar.gz
refactor and dont panic without x-server
Diffstat (limited to 'mumd/src')
-rw-r--r--mumd/src/main.rs3
-rw-r--r--mumd/src/state.rs29
2 files changed, 10 insertions, 22 deletions
diff --git a/mumd/src/main.rs b/mumd/src/main.rs
index 79e44a2..37ff0dd 100644
--- a/mumd/src/main.rs
+++ b/mumd/src/main.rs
@@ -1,6 +1,7 @@
mod audio;
mod command;
mod network;
+mod notify;
mod state;
use crate::network::ConnectionInfo;
@@ -22,7 +23,7 @@ use tokio::task::spawn_blocking;
#[tokio::main]
async fn main() {
setup_logger(std::io::stderr(), true);
- libnotify::init("mumd").unwrap();
+ notify::init();
// Oneshot channel for setting UDP CryptState from control task
// For simplicity we don't deal with re-syncing, real applications would have to.
diff --git a/mumd/src/state.rs b/mumd/src/state.rs
index ea0213c..ea081fc 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -4,6 +4,7 @@ pub mod user;
use crate::audio::Audio;
use crate::network::ConnectionInfo;
+use crate::notify;
use crate::state::server::Server;
use log::*;
@@ -239,12 +240,7 @@ impl State {
0
};
if let Some(channel) = self.server().unwrap().channels().get(&channel_id) {
- libnotify::Notification::new("mumd",
- Some(format!("{} connected and joined {}",
- &msg.get_name(),
- channel.name()).as_str()),
- None)
- .show().unwrap();
+ notify::send(format!("{} connected and joined {}", &msg.get_name(), channel.name()));
}
}
}
@@ -273,12 +269,10 @@ impl State {
//TODO our channel only
if let Some(channel_id) = diff.channel_id {
if let Some(channel) = self.server().unwrap().channels().get(&channel_id) {
- libnotify::Notification::new("mumd",
- Some(format!("{} moved to channel {}",
- &user.name(),
- channel.name()).as_str()),
- None)
- .show().unwrap();
+ notify::send(format!(
+ "{} moved to channel {}",
+ &user.name(),
+ channel.name()));
} else {
warn!("{} moved to invalid channel {}", &user.name(), channel_id);
}
@@ -309,10 +303,7 @@ impl State {
None
};
if let Some(notif_desc) = notif_desc {
- libnotify::Notification::new("mumd",
- notif_desc.as_str(),
- None)
- .show().unwrap();
+ notify::send(notif_desc);
}
diff
@@ -324,11 +315,7 @@ impl State {
return;
}
if let Some(user) = self.server().unwrap().users().get(&msg.get_session()) {
- libnotify::Notification::new("mumd",
- Some(format!("{} disconnected",
- &user.name()).as_str()),
- None)
- .show().unwrap();
+ notify::send(format!("{} disconnected", &user.name()));
}
self.audio().remove_client(msg.get_session());