still not robust
This commit is contained in:
parent
bbe902d92e
commit
8995011d45
@ -131,7 +131,7 @@ pub fn is_installed_daemon(prompt: bool) -> bool {
|
|||||||
.arg(daemon_plist_body)
|
.arg(daemon_plist_body)
|
||||||
.arg(agent_plist_body)
|
.arg(agent_plist_body)
|
||||||
.arg(&get_active_username())
|
.arg(&get_active_username())
|
||||||
.output()
|
.status()
|
||||||
{
|
{
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("run osascript failed: {}", e);
|
log::error!("run osascript failed: {}", e);
|
||||||
@ -148,9 +148,8 @@ pub fn is_installed_daemon(prompt: bool) -> bool {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.arg(&format!(
|
.arg(&format!(
|
||||||
"sleep 0.5; launchctl load -w {}; sleep 0.5; open /Applications/{}.app",
|
"sleep 0.5; launchctl load -w {};",
|
||||||
agent_plist_file,
|
agent_plist_file,
|
||||||
crate::get_app_name()
|
|
||||||
))
|
))
|
||||||
.spawn()
|
.spawn()
|
||||||
.ok();
|
.ok();
|
||||||
@ -177,7 +176,7 @@ pub fn uninstall() -> bool {
|
|||||||
.arg("-e")
|
.arg("-e")
|
||||||
.arg(script_body)
|
.arg(script_body)
|
||||||
.arg(&get_active_username())
|
.arg(&get_active_username())
|
||||||
.output()
|
.status()
|
||||||
{
|
{
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("run osascript failed: {}", e);
|
log::error!("run osascript failed: {}", e);
|
||||||
@ -401,21 +400,40 @@ pub fn lock_screen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_os_service() {
|
pub fn start_os_service() {
|
||||||
|
let exe = std::env::current_exe().unwrap_or_default();
|
||||||
|
let tm0 = hbb_common::get_modified_time(&exe);
|
||||||
log::info!("{}", crate::username());
|
log::info!("{}", crate::username());
|
||||||
|
|
||||||
std::thread::spawn(move || loop {
|
std::thread::spawn(move || loop {
|
||||||
let exe = std::env::current_exe().unwrap_or_default();
|
|
||||||
let tm0 = hbb_common::get_modified_time(&exe);
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_millis(300));
|
std::thread::sleep(std::time::Duration::from_millis(300));
|
||||||
if hbb_common::get_modified_time(&exe) != tm0 {
|
let now = hbb_common::get_modified_time(&exe);
|
||||||
log::info!("{:?} updated, will restart", exe);
|
if now != tm0 && now != std::time::UNIX_EPOCH {
|
||||||
|
// sleep a while to wait for resources file ready
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(300));
|
||||||
|
println!("{:?} updated, will restart", exe);
|
||||||
|
// this won't kill myself
|
||||||
std::process::Command::new("pkill")
|
std::process::Command::new("pkill")
|
||||||
.args(&["-f", exe.to_str().unwrap_or("")])
|
.args(&["-f", &crate::get_app_name()])
|
||||||
.output()
|
.status()
|
||||||
.ok();
|
.ok();
|
||||||
std::process::exit(0); // self not killed by above pkill
|
println!("The others killed");
|
||||||
|
// launchctl load/unload/start agent not work in daemon, show not priviledged.
|
||||||
|
// sudo launchctl asuser 501 open -n also not allowed.
|
||||||
|
std::process::Command::new("launchctl")
|
||||||
|
.args(&[
|
||||||
|
"asuser",
|
||||||
|
&get_active_userid(),
|
||||||
|
"open",
|
||||||
|
"-a",
|
||||||
|
&exe.to_str().unwrap_or(""),
|
||||||
|
"--args",
|
||||||
|
"--server",
|
||||||
|
])
|
||||||
|
.status()
|
||||||
|
.ok();
|
||||||
|
// if above spawn, we may need sleep for a while here.
|
||||||
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -493,10 +511,10 @@ pub fn block_input(_v: bool) -> bool {
|
|||||||
|
|
||||||
pub fn is_installed() -> bool {
|
pub fn is_installed() -> bool {
|
||||||
if let Ok(p) = std::env::current_exe() {
|
if let Ok(p) = std::env::current_exe() {
|
||||||
return p.to_str().unwrap_or_default().contains(&format!(
|
return p
|
||||||
"/Applications/{}.app",
|
.to_str()
|
||||||
crate::get_app_name(),
|
.unwrap_or_default()
|
||||||
));
|
.contains(&format!("/Applications/{}.app", crate::get_app_name()));
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,9 @@
|
|||||||
<true/>
|
<true/>
|
||||||
<key>WorkingDirectory</key>
|
<key>WorkingDirectory</key>
|
||||||
<string>/Applications/RustDesk.app/Contents/MacOS/</string>
|
<string>/Applications/RustDesk.app/Contents/MacOS/</string>
|
||||||
|
<key>StandardErrorPath</key>
|
||||||
|
<string>/tmp/rustdesk_service.err</string>
|
||||||
|
<key>StandardOutPath</key>
|
||||||
|
<string>/tmp/rustdesk_service.out</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -4,6 +4,3 @@ set sh3 to "/bin/rm /Library/LaunchAgents/com.carriez.RustDesk_server.plist;"
|
|||||||
|
|
||||||
set sh to sh1 & sh2 & sh3
|
set sh to sh1 & sh2 & sh3
|
||||||
do shell script sh with prompt "RustDesk want to unload daemon" with administrator privileges
|
do shell script sh with prompt "RustDesk want to unload daemon" with administrator privileges
|
||||||
|
|
||||||
set sh5 to "[ ! -f /Library/LaunchAgents/com.carriez.RustDesk_server.plist ] && launchctl remove com.carriez.RustDesk_server && sleep 1 && open /Applications/RustDesk.app"
|
|
||||||
do shell script sh5
|
|
||||||
|
@ -333,36 +333,41 @@ async fn sync_and_watch_config_dir() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 1..=6 {
|
let mut cfg0 = (Config::get(), Config2::get());
|
||||||
|
let mut synced = false;
|
||||||
|
for i in 1..=30 {
|
||||||
sleep(i as f32 * 0.3).await;
|
sleep(i as f32 * 0.3).await;
|
||||||
match crate::ipc::connect(1000, "_service").await {
|
match crate::ipc::connect(1000, "_service").await {
|
||||||
Ok(mut conn) => {
|
Ok(mut conn) => {
|
||||||
if conn.send(&Data::SyncConfig(None)).await.is_ok() {
|
if !synced {
|
||||||
if let Ok(Some(data)) = conn.next_timeout(1000).await {
|
if conn.send(&Data::SyncConfig(None)).await.is_ok() {
|
||||||
match data {
|
if let Ok(Some(data)) = conn.next_timeout(1000).await {
|
||||||
Data::SyncConfig(Some((config, config2))) => {
|
match data {
|
||||||
let _chk = crate::ipc::CheckIfRestart::new();
|
Data::SyncConfig(Some((config, config2))) => {
|
||||||
Config::set(config);
|
let _chk = crate::ipc::CheckIfRestart::new();
|
||||||
Config2::set(config2);
|
Config::set(config);
|
||||||
log::info!("sync config from root");
|
Config2::set(config2);
|
||||||
}
|
log::info!("sync config from root");
|
||||||
_ => {}
|
synced = true;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cfg0 = (Config::get(), Config2::get());
|
|
||||||
loop {
|
loop {
|
||||||
sleep(0.3).await;
|
sleep(0.3).await;
|
||||||
let cfg = (Config::get(), Config2::get());
|
let cfg = (Config::get(), Config2::get());
|
||||||
if cfg != cfg0 {
|
if cfg != cfg0 {
|
||||||
cfg0 = cfg;
|
|
||||||
log::info!("config updated, sync to root");
|
log::info!("config updated, sync to root");
|
||||||
match conn.send(&Data::SyncConfig(Some(cfg0.clone()))).await {
|
match conn.send(&Data::SyncConfig(Some(cfg0.clone()))).await {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("sync config to root failed: {}", e);
|
log::error!("sync config to root failed: {}", e);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
cfg0 = cfg;
|
||||||
conn.next_timeout(1000).await.ok();
|
conn.next_timeout(1000).await.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,8 +153,6 @@ pub fn start(args: &mut [String]) {
|
|||||||
page
|
page
|
||||||
));
|
));
|
||||||
if is_server {
|
if is_server {
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
macos::ignore_first_time_awake();
|
|
||||||
frame.collapse(true);
|
frame.collapse(true);
|
||||||
frame.run_loop();
|
frame.run_loop();
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,12 +42,8 @@ impl DelegateState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut IGNORE_FIRST_TIME: bool = false;
|
lazy_static::lazy_static! {
|
||||||
|
static ref START_TM: std::sync::Mutex<std::time::Instant> = std::sync::Mutex::new(std::time::Instant::now());
|
||||||
pub fn ignore_first_time_awake() {
|
|
||||||
unsafe {
|
|
||||||
IGNORE_FIRST_TIME = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppHandler for Rc<Host> {
|
impl AppHandler for Rc<Host> {
|
||||||
@ -59,11 +55,9 @@ impl AppHandler for Rc<Host> {
|
|||||||
let _ = self.call_function("awake", &make_args![]);
|
let _ = self.call_function("awake", &make_args![]);
|
||||||
let _ = self.call_function("showSettings", &make_args![]);
|
let _ = self.call_function("showSettings", &make_args![]);
|
||||||
} else if cmd == AWAKE {
|
} else if cmd == AWAKE {
|
||||||
unsafe {
|
if START_TM.lock().unwrap().elapsed().as_millis() < 1000 {
|
||||||
if IGNORE_FIRST_TIME {
|
hbb_common::log::debug!("First click on docker icon {:?}", START_TM.lock().unwrap().elapsed());
|
||||||
IGNORE_FIRST_TIME = false;
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let _ = self.call_function("awake", &make_args![]);
|
let _ = self.call_function("awake", &make_args![]);
|
||||||
}
|
}
|
||||||
@ -72,6 +66,7 @@ impl AppHandler for Rc<Host> {
|
|||||||
|
|
||||||
// https://github.com/xi-editor/druid/blob/master/druid-shell/src/platform/mac/application.rs
|
// https://github.com/xi-editor/druid/blob/master/druid-shell/src/platform/mac/application.rs
|
||||||
unsafe fn set_delegate(handler: Option<Box<dyn AppHandler>>) {
|
unsafe fn set_delegate(handler: Option<Box<dyn AppHandler>>) {
|
||||||
|
*START_TM.lock().unwrap() = std::time::Instant::now();
|
||||||
let mut decl =
|
let mut decl =
|
||||||
ClassDecl::new("AppDelegate", class!(NSObject)).expect("App Delegate definition failed");
|
ClassDecl::new("AppDelegate", class!(NSObject)).expect("App Delegate definition failed");
|
||||||
decl.add_ivar::<*mut c_void>(APP_HANDLER_IVAR);
|
decl.add_ivar::<*mut c_void>(APP_HANDLER_IVAR);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user