@@ -11,13 +11,12 @@ use std::os::unix::io::{FromRawFd, RawFd};
11
11
use tokio:: {
12
12
io:: { self , AsyncBufReadExt , BufReader } ,
13
13
net:: UnixStream ,
14
- sync:: oneshot,
15
14
} ;
16
15
use tracing:: { error, info, warn} ;
17
16
18
17
#[ derive( Debug ) ]
19
18
pub enum State {
20
- WaitingForPanel ,
19
+ Ready ,
21
20
WaitingForDaemon ( UnixStream ) ,
22
21
WaitingForNotificationEvent ( UnixStream ) ,
23
22
Finished ,
@@ -30,41 +29,16 @@ pub fn notifications() -> Subscription<AppletEvent> {
30
29
std:: any:: TypeId :: of :: < SomeWorker > ( ) ,
31
30
50 ,
32
31
|mut output| async move {
33
- let mut state = State :: WaitingForPanel ;
32
+ let mut state = State :: Ready ;
34
33
35
34
loop {
36
35
match & mut state {
37
- State :: WaitingForPanel => {
38
- info ! ( "Waiting for panel to send us a stream" ) ;
39
-
40
- let ( tx, rx) = oneshot:: channel ( ) ;
41
-
42
- std:: thread:: spawn ( move || -> anyhow:: Result < ( ) > {
43
- let mut msg = String :: new ( ) ;
44
-
45
- if let Err ( err) = std:: io:: stdin ( ) . read_line ( & mut msg) {
46
- error ! ( "Failed to read line from panel: {}" , err) ;
47
- anyhow:: bail!( "Failed to read line from panel" ) ;
48
- }
49
-
50
- info ! ( "Received fd from panel: {}" , msg) ;
51
- let Ok ( raw_fd) = msg. trim ( ) . parse :: < RawFd > ( ) else {
52
- error ! ( "Failed to parse fd from panel" ) ;
53
- anyhow:: bail!( "Failed to parse fd from panel" ) ;
54
- } ;
55
- if raw_fd == 0 {
56
- error ! ( "Invalid fd received from panel" ) ;
57
- anyhow:: bail!( "Invalid fd received from panel" ) ;
58
- }
59
- if let Err ( err) = tx. send ( raw_fd) {
60
- error ! ( "Failed to send fd to main thread: {}" , err) ;
61
- anyhow:: bail!( "Failed to send fd to main thread" ) ;
62
- }
63
- Ok ( ( ) )
64
- } ) ;
65
-
66
- let Ok ( raw_fd) = rx. await else {
67
- error ! ( "Failed to receive raw fd from panel" ) ;
36
+ State :: Ready => {
37
+ info ! ( "Reading COSMIC_NOTIFICATIONS env var" ) ;
38
+ let Ok ( Some ( raw_fd) ) = std:: env:: var ( "COSMIC_NOTIFICATIONS" )
39
+ . map ( |fd| fd. parse :: < RawFd > ( ) . ok ( ) ) else
40
+ {
41
+ error ! ( "Failed to parse COSMIC_NOTIFICATIONS env var" ) ;
68
42
state = State :: Finished ;
69
43
continue ;
70
44
} ;
@@ -76,6 +50,7 @@ pub fn notifications() -> Subscription<AppletEvent> {
76
50
continue ;
77
51
} ;
78
52
state = State :: WaitingForDaemon ( stream) ;
53
+
79
54
}
80
55
State :: WaitingForDaemon ( stream) => {
81
56
info ! ( "Waiting for panel to send us a stream" ) ;
0 commit comments