Pi66

pino-rs
Rust notification daemon.
git clone https://git.pi66.xyz/pino-rs

← back to log

Bug: Dont open when force killed

author: pixel
date: 2025-05-03 13:09
hash: 9ef024d83125d56b19676ea1104e51fd284e0e81

Diffstat:

M

Cargo.lock
2 ++-

M

Cargo.toml
2 ++-

M

src/main.rs
6 ++++++---

M

src/ui.rs
3 +---

A

src/utils.rs
20 ++++++++++++++++++++++++++++++
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
diff --git a/Cargo.lock b/Cargo.lock
index 89424ab..7490101 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -117,7 +117,7 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"

 [[package]]
 name = "pino"
-version = "1.1.1"
+version = "1.1.3"
 dependencies = [
  "argh",
  "fltk",
diff --git a/Cargo.toml b/Cargo.toml
index 9c9158e..dc0b9c4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pino"
-version = "1.1.2"
+version = "1.1.3"
 edition = "2024"

 [dependencies]
diff --git a/src/main.rs b/src/main.rs
index 2dc5782..0a3198f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,13 @@
 use argh::FromArgs;
 use serde::Deserialize;
 use std::{fs, io::Write, os::unix::net::UnixStream, path::Path};
+use utils::is_running;

 mod colors;
 mod config;
 mod screen;
 mod ui;
+mod utils;

 #[derive(FromArgs)]
 #[argh(
@@ -108,7 +110,7 @@ fn main() {
     let args: Arg = argh::from_env();

     if args.version {
-        println!("v1.1.2");
+        println!("v1.1.3");
         return;
     }

@@ -134,7 +136,7 @@ fn main() {
     let config_content = fs::read_to_string(config_file).expect("Faild ");
     let config: Config = toml::from_str(&config_content).expect("Faild");

-    if Path::new("/tmp/pino-check.sock").exists() {
+    if Path::new("/tmp/pino-check.sock").exists() && is_running() {
         let mut stream = UnixStream::connect("/tmp/pino-check.sock").unwrap();
         stream
             .write_all(
diff --git a/src/ui.rs b/src/ui.rs
index 025ab1d..dfc8167 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -96,8 +96,7 @@ pub fn ui(
     });

     let (tx, rx) = mpsc::channel::<(String, String, u64)>();
-    tx.send((data.0, data.1, data.2))
-        .unwrap();
+    tx.send((data.0, data.1, data.2)).unwrap();
     let socket_path = "/tmp/pino-check.sock";

     if Path::new(socket_path).exists() {
diff --git a/src/utils.rs b/src/utils.rs
new file mode 100644
index 0000000..698a237
--- /dev/null
+++ b/src/utils.rs
@@ -0,0 +1,20 @@
+use std::process::{Command, Stdio};
+
+pub fn is_running() -> bool {
+    let output = Command::new("pgrep")
+        .arg("-x")
+        .arg("pino")
+        .stdout(Stdio::piped())
+        .stderr(Stdio::null())
+        .output();
+
+    match output {
+        Ok(output) if output.status.success() => {
+            let pids = String::from_utf8_lossy(&output.stdout);
+
+            pids.lines().count() == 2
+        }
+
+        _ => false,
+    }
+}