Add launch service

This commit is contained in:
chenbaiyu
2022-01-13 19:23:41 +08:00
parent f45a2c7a94
commit 9be6b17a8b
9 changed files with 204 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ use core_graphics::{
use hbb_common::{allow_err, bail, log};
use objc::{class, msg_send, sel, sel_impl};
use scrap::{libc::c_void, quartz::ffi::*};
use std::io::Read;
static mut LATEST_SEED: i32 = 0;
@@ -98,6 +99,57 @@ pub fn is_can_screen_recording(prompt: bool) -> bool {
can_record_screen
}
pub fn is_installed_daemon(prompt: bool) -> bool {
if !prompt {
let output = std::process::Command::new("launchctl")
.args(vec!["list", "|", "grep", "com.carriez.rustdesk.daemon"])
.stdout(std::process::Stdio::piped())
.output()
.unwrap();
if output.stdout.len() <= 0{
return false;
}
let output = std::process::Command::new("launchctl")
.args(vec!["list", "|", "grep", "com.carriez.rustdesk.agent.root"])
.stdout(std::process::Stdio::piped())
.output()
.unwrap();
if output.stdout.len() <= 0{
return false;
}
let output = std::process::Command::new("launchctl")
.args(vec!["list", "|", "grep", "com.carriez.rustdesk.agent.user"])
.stdout(std::process::Stdio::piped())
.output()
.unwrap();
if output.stdout.len() <= 0{
return false;
}
return true;
}
if !std::process::Command::new("osascript")
.arg("./privileges_scripts/install.scpt")
.status()
.unwrap()
.success() {
return false;
}
if !std::process::Command::new("osascript")
.arg("./privileges_scripts/launch_service.scpt")
.status()
.unwrap()
.success() {
return false;
}
return true;
}
pub fn get_cursor_pos() -> Option<(i32, i32)> {
unsafe {
let e = CGEventCreate(0 as _);
@@ -334,8 +386,8 @@ pub fn is_installed() -> bool {
true
}
pub fn start_daemon(){
log::info!("{}",crate::username());
pub fn start_daemon() {
log::info!("{}", crate::username());
if let Err(err) = crate::ipc::start("_daemon") {
log::error!("Failed to start ipc_daemon: {}", err);
std::process::exit(-1);

View File

@@ -363,6 +363,20 @@ impl UI {
options.insert(key, value);
}
ipc::set_options(options.clone()).ok();
#[cfg(macos)]
if key == "stop-service" {
let mut service_script = "./privileges_scripts/stop_service.scpt";
if value == "Y" {
command = "./privileges_scripts/launch_service.scpt";
}
std::process::Command::new("osascript")
.arg(service_script)
.status()
.unwrap()
.success();
}
}
fn install_path(&mut self) -> String {
@@ -525,6 +539,13 @@ impl UI {
return true;
}
fn is_installed_daemon(&mut self, _prompt: bool) -> bool {
#[cfg(target_os = "macos")]
return crate::platform::macos::is_installed_daemon(_prompt);
#[cfg(not(target_os = "macos"))]
return true;
}
fn get_error(&mut self) -> String {
#[cfg(target_os = "linux")]
{
@@ -668,6 +689,7 @@ impl sciter::EventHandler for UI {
fn goto_install();
fn is_process_trusted(bool);
fn is_can_screen_recording(bool);
fn is_installed_daemon(bool);
fn get_error();
fn is_login_wayland();
fn fix_login_wayland();

View File

@@ -307,6 +307,7 @@ class App: Reactor.Component
{handler.is_installed() && !software_update_url && handler.is_installed_lower_version() ? <UpgradeMe /> : ""}
{is_can_screen_recording ? "": <CanScreenRecording />}
{is_can_screen_recording && !handler.is_process_trusted(false) ? <TrustMe /> : ""}
{is_can_screen_recording && handler.is_process_trusted(false) && handler.is_installed_daemon(false) ? <InstallDaemon /> : ""}
{system_error ? <SystemError /> : ""}
{!system_error && handler.is_login_wayland() && !handler.current_is_wayland() ? <FixWayland /> : ""}
{!system_error && handler.current_is_wayland() ? <ModifyDefaultLogin /> : ""}
@@ -491,6 +492,21 @@ class CanScreenRecording: Reactor.Component {
}
}
class InstallDaemon: Reactor.Component {
function render() {
return <div .trust-me>
<div>{translate('Configuration Permissions')}</div>
<div>{translate('install_daemon')}</div>
<div #install-daemon .link>{translate('Configure')}</div>
</div>;
}
event click $(#install-daemon) {
handler.is_installed_daemon(true);
watch_trust();
}
}
class FixWayland: Reactor.Component {
function render() {
return <div .trust-me>