https://github.com/rustdesk/rustdesk/issues/77 mac tray, still no find good way to open rustdesk from finder after tray

shown
This commit is contained in:
rustdesk
2022-04-28 21:32:44 +08:00
parent de44e45ed6
commit c1f5c20e94
13 changed files with 631 additions and 125 deletions

View File

@@ -265,5 +265,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("android_version_audio_tip", "当前安卓版本不支持音频录制请升级至安卓10或更高。"),
("android_start_service_tip", "点击 [启动服务] 或打开 [屏幕录制] 权限开启手机屏幕共享服务。"),
("Account", "账号"),
("Quit", "退出"),
].iter().cloned().collect();
}

View File

@@ -265,5 +265,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("android_version_audio_tip", "Die aktuelle Android-Version unterstützt keine Audioaufnahme, bitte aktualisieren Sie auf Android 10 oder höher."),
("android_start_service_tip", "Tippen Sie auf [Dienst starten] oder ÖFFNEN Sie die Berechtigung [Bildschirmaufnahme], um den Bildschirmfreigabedienst zu starten."),
("Account", "Konto"),
("Quit", "Ausgang"),
].iter().cloned().collect();
}

View File

@@ -265,5 +265,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("android_version_audio_tip", "La version actuelle d'Android ne prend pas en charge la capture audio, veuillez passer à Android 10 ou supérieur."),
("android_start_service_tip", "Appuyez sur [Démarrer le service] ou sur l'autorisation OUVRIR [Capture d'écran] pour démarrer le service de partage d'écran."),
("Account", "Compte"),
("Quit", "Quitter"),
].iter().cloned().collect();
}

View File

@@ -265,5 +265,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("android_version_audio_tip", "L'attuale versione di Android non supporta l'acquisizione audio, esegui l'upgrade ad Android 10 o versioni successive."),
("android_start_service_tip", "Toccare [Avvia servizio] o APRI l'autorizzazione [Cattura schermo] per avviare il servizio di condivisione dello schermo."),
("Account", "Account"),
("Quit", "Esci"),
].iter().cloned().collect();
}

View File

@@ -265,5 +265,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("android_version_audio_tip", "A versão atual do Android não suporta captura de áudio, por favor atualize para o Android 10 ou maior."),
("android_start_service_tip", "Toque [Iniciar Serviço] ou ABRA a permissão [Captura de Tela] para iniciar o serviço de compartilhamento de tela."),
("Account", "Conta"),
("Quit", "Saída"),
].iter().cloned().collect();
}

View File

@@ -265,5 +265,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("android_version_audio_tip", "Текущая версия Android не поддерживает захват звука, обновите ее до Android 10 или выше."),
("android_start_service_tip", "Коснитесь [Запуск промежуточного сервера] или ОТКРЫТЬ разрешение [Скриншот], чтобы запустить службу демонстрации экрана."),
("Account", "Аккаунт"),
("Quit", "Выйти"),
].iter().cloned().collect();
}

View File

@@ -265,5 +265,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("android_version_audio_tip", "當前安卓版本不支持音頻錄製請升級至安卓10或更高。"),
("android_start_service_tip", "點擊 [啟動服務] 或打開 [屏幕錄製] 權限開啟手機屏幕共享服務。"),
("Account", "帳戶"),
("Quit", "退出"),
].iter().cloned().collect();
}

View File

@@ -39,6 +39,10 @@ struct UIHostHandler;
pub fn start(args: &mut [String]) {
let is_server = args.len() == 1 && args[0] == "--server";
if is_server && LocalConfig::get_option("service-as-tray") == "Y" {
macos::make_tray();
return;
}
let is_index = args.is_empty() || is_server;
if is_server {
// wait a moment for server's ipc check to avoid sciter crash
@@ -451,7 +455,7 @@ impl UI {
}
}
fn save_size(&mut self, x: i32, y: i32, w: i32, h: i32) {
fn closing(&mut self, x: i32, y: i32, w: i32, h: i32) {
crate::server::input_service::fix_key_down_timeout_at_exit();
LocalConfig::set_size(x, y, w, h);
}
@@ -695,7 +699,7 @@ impl sciter::EventHandler for UI {
fn update_password(String);
fn get_remote_id();
fn set_remote_id(String);
fn save_size(i32, i32, i32, i32);
fn closing(i32, i32, i32, i32);
fn get_size();
fn new_remote(String, bool);
fn remove_peer(String);

View File

@@ -744,11 +744,12 @@ $(body).content(<App />);
function self.closing() {
// return false; // can prevent window close
var (x, y, w, h) = view.box(#rectw, #border, #screen);
handler.save_size(x, y, w, h);
if (is_osx) {
handler.closing(x, y, w, h);
if (is_osx && handler.get_local_option("service-as-tray") != "Y") {
view.windowState = View.WINDOW_HIDDEN;
return false;
}
return true;
}
function self.ready() {

View File

@@ -1,6 +1,6 @@
#[cfg(target_os = "macos")]
use cocoa::{
appkit::{NSApp, NSApplication, NSMenu, NSMenuItem},
appkit::{NSApp, NSApplication, NSApplicationActivationPolicy::*, NSMenu, NSMenuItem},
base::{id, nil, YES},
foundation::{NSAutoreleasePool, NSString},
};
@@ -56,7 +56,10 @@ impl AppHandler for Rc<Host> {
let _ = self.call_function("showSettings", &make_args![]);
} else if cmd == AWAKE {
if START_TM.lock().unwrap().elapsed().as_millis() < 1000 {
hbb_common::log::debug!("First click on docker icon {:?}", START_TM.lock().unwrap().elapsed());
hbb_common::log::debug!(
"First click on docker icon {:?}",
START_TM.lock().unwrap().elapsed()
);
return;
}
let _ = self.call_function("awake", &make_args![]);
@@ -81,6 +84,26 @@ unsafe fn set_delegate(handler: Option<Box<dyn AppHandler>>) {
application_should_handle_open_untitled_file as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);
decl.add_method(
sel!(applicationDidBecomeActive:),
application_did_become_active as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);
decl.add_method(
sel!(applicationDidUnhide:),
application_did_become_unhide as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);
decl.add_method(
sel!(applicationShouldHandleReopen:),
application_should_handle_reopen as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);
decl.add_method(
sel!(applicationWillTerminate:),
application_will_terminate as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);
decl.add_method(
sel!(handleMenuItem:),
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
@@ -113,6 +136,40 @@ extern "C" fn application_should_handle_open_untitled_file(
YES
}
extern "C" fn application_should_handle_reopen(
_this: &mut Object,
_: Sel,
_sender: id,
) -> BOOL {
hbb_common::log::debug!("reopen");
YES
}
extern "C" fn application_did_become_active (
_this: &mut Object,
_: Sel,
_sender: id,
) -> BOOL {
hbb_common::log::debug!("active");
YES
}
extern "C" fn application_did_become_unhide (
_this: &mut Object,
_: Sel,
_sender: id,
) -> BOOL {
hbb_common::log::debug!("unhide");
YES
}
extern "C" fn application_will_terminate(_this: &mut Object, _: Sel, _sender: id) -> BOOL {
if std::env::args().len() == 1 || std::env::args().nth(1) == Some("--server".to_owned()) {
hide_dock();
}
YES
}
/// This handles menu items in the case that all windows are closed.
extern "C" fn handle_menu_item(this: &mut Object, _: Sel, item: id) {
unsafe {
@@ -182,3 +239,30 @@ pub fn make_menubar(host: Rc<Host>, is_index: bool) {
NSApp().setMainMenu_(menubar);
}
}
pub fn hide_dock() {
unsafe {
NSApp().setActivationPolicy_(NSApplicationActivationPolicyAccessory);
}
}
pub fn make_tray() {
hide_dock();
use tray_item::TrayItem;
if let Ok(mut tray) = TrayItem::new(&crate::get_app_name(), "mac-tray.png") {
tray.add_label(&format!(
"{} {}",
crate::get_app_name(),
crate::lang::translate("Service is running".to_owned())
))
.ok();
let inner = tray.inner_mut();
inner.add_quit_item(&crate::lang::translate("Quit".to_owned()));
inner.display();
} else {
loop {
std::thread::sleep(std::time::Duration::from_secs(3));
}
}
}