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
use std::{
env,
path::PathBuf,
process::{exit, Command as StdCommand},
};
#[cfg(shell_execute)]
mod command;
#[cfg(shell_execute)]
pub use command::*;
pub fn current_binary() -> Option<PathBuf> {
let mut current_binary = None;
#[cfg(target_os = "linux")]
if let Some(app_image_path) = env::var_os("APPIMAGE") {
current_binary = Some(PathBuf::from(app_image_path));
}
if current_binary.is_none() {
if let Ok(current_process) = env::current_exe() {
current_binary = Some(current_process);
}
}
current_binary
}
pub fn restart() {
if let Some(path) = current_binary() {
StdCommand::new(path)
.spawn()
.expect("application failed to start");
}
exit(0);
}