1
+ #![ feature( panic_info_message) ]
1
2
use glutin:: {
2
3
dpi:: PhysicalSize ,
3
4
event:: { Event , StartCause } ,
4
5
event_loop:: EventLoop ,
5
6
} ;
6
- use std:: thread;
7
- use std:: { fs, io:: Read , os:: unix:: net:: UnixListener , path:: Path , sync:: mpsc, time:: Instant } ;
7
+ use std:: {
8
+ fs, io:: Read , os:: unix:: net:: UnixListener , path:: Path , process, sync:: mpsc, time:: Instant ,
9
+ } ;
10
+ use std:: { os:: unix:: net:: UnixStream , thread} ;
8
11
9
12
mod app;
10
13
#[ path = "../common.rs" ]
11
14
mod common;
12
15
mod plugins;
13
16
14
17
fn main ( ) {
18
+ // Set less distracting panic message
19
+ std:: panic:: set_hook ( Box :: new ( |info| match info. message ( ) {
20
+ Some ( message) => println ! ( "Error: {}" , message) ,
21
+ None => println ! ( "{}" , info) ,
22
+ } ) ) ;
23
+
15
24
let ( tx, rx) = mpsc:: channel ( ) ;
16
25
let socket_thread = thread:: spawn ( move || {
17
26
start_socket ( & tx) ;
@@ -23,6 +32,11 @@ fn main() {
23
32
fn start_socket ( tx : & mpsc:: Sender < UserEvent > ) {
24
33
let socket = Path :: new ( common:: SOCKET_PATH ) ;
25
34
35
+ if UnixStream :: connect ( & socket) . is_ok ( ) {
36
+ tx. send ( UserEvent :: Quit ) . unwrap ( ) ;
37
+ panic ! ( "One daemon is already listening." )
38
+ }
39
+
26
40
// Delete old socket if necessary
27
41
if socket. exists ( ) {
28
42
fs:: remove_file ( & socket) . unwrap ( ) ;
@@ -123,6 +137,7 @@ fn start_gui(rx: mpsc::Receiver<UserEvent>) {
123
137
}
124
138
command => println ! ( "Got command: {:?}" , command) ,
125
139
} ,
140
+ Event :: UserEvent ( UserEvent :: Quit ) => process:: exit ( 0 ) ,
126
141
_ => { }
127
142
} ) ;
128
143
}
@@ -204,5 +219,6 @@ fn create_display(
204
219
205
220
#[ derive( Debug ) ]
206
221
enum UserEvent {
222
+ Quit ,
207
223
CliCommand ( String ) ,
208
224
}
0 commit comments