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

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disable<key>
<false />
<key>Label</key>
<string>com.carriez.rustdesk.agent.root</string>
<key>LimitLoadToSessionType</key>
<array>
<string>LoginWindow</string>
</array>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false />
<key>AfterInitialDemand</key>
<false />
</dict>
<key>RunAtLoad</key>
<true />
<key>ProgramArguments</key>
<array>
<string>/Applications/RustDesk.app/Contents/MacOS/rustdesk</string>
<string>--server</string>
</array>
<key>WorkingDirectory</key>
<string>/Applications/RustDesk.app/Contents/MacOS/</string>
</dict>
</plist>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disable<key>
<false />
<key>Label</key>
<string>com.carriez.rustdesk.agent.root</string>
<key>LimitLoadToSessionType</key>
<array>
<string>Aqua</string>
</array>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false />
<key>AfterInitialDemand</key>
<false />
</dict>
<key>RunAtLoad</key>
<true />
<key>ProgramArguments</key>
<array>
<string>/Applications/RustDesk.app/Contents/MacOS/rustdesk</string>
<string>--server</string>
</array>
<key>WorkingDirectory</key>
<string>/Applications/RustDesk.app/Contents/MacOS/</string>
</dict>
</plist>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.carriez.rustdesk.daemon</string>
<key>Disabled</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.youqu.todesk.service</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/RustDesk.app/Contents/MacOS/rustdesk</string>
<string>--daemon</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/Applications/RustDesk.app/Contents/MacOS/</string>
</dict>
</plist>

View File

@ -0,0 +1,9 @@
set current_dir to POSIX path of ((path to me as text) & "::")
set sh1 to "cp " & current_dir & "com.carriez.rustdesk.daemon.plist /Library/LaunchDaemons/com.carriez.rustdesk.daemon.plist && chown root:wheel /Library/LaunchDaemons/com.carriez.rustdesk.daemon.plist"
set sh2 to "cp " & current_dir & "com.carriez.rustdesk.agent.root.plist /Library/LaunchAgents/com.carriez.rustdesk.agent.root.plist && chown root:wheel /Library/LaunchAgents/com.carriez.rustdesk.agent.root.plist"
set sh3 to "cp " & current_dir & "com.carriez.rustdesk.agent.user.plist /Library/LaunchAgents/com.carriez.rustdesk.agent.user.plist && chown root:wheel /Library/LaunchAgents/com.carriez.rustdesk.agent.user.plist"
set sh to sh1 & ";" & sh2 & ";" & sh3
do shell script sh with prompt "RustDesk需要安装服务plist" with administrator privileges

View File

@ -0,0 +1,10 @@
set sh to "
launchctl enable system/com.carriez.rustdesk.daemon;
launchctl start system/com.carriez.rustdesk.daemon;
launchctl enable system/com.carriez.rustdesk.agent.root;
launchctl start system/com.carriez.rustdesk.agent.root;
launchctl enable system/com.carriez.rustdesk.agent.user
launchctl start system/com.carriez.rustdesk.agent.user
"
do shell script sh with prompt "RustDesk需要启动服务" with administrator privileges

View File

@ -0,0 +1,10 @@
set sh to "
launchctl disable system/com.carriez.rustdesk.daemon;
launchctl stop system/com.carriez.rustdesk.daemon;
launchctl disable system/com.carriez.rustdesk.agent.root;
launchctl stop system/com.carriez.rustdesk.agent.root;
launchctl disable system/com.carriez.rustdesk.agent.user
launchctl stop system/com.carriez.rustdesk.agent.user
"
do shell script sh with prompt "RustDesk需要停止服务" with administrator privileges

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>