fix: make event loop in tray compatible with main window

This commit is contained in:
Kingtous 2023-05-02 12:52:27 +08:00
parent 4e7a8065b9
commit 7a82070420
8 changed files with 45 additions and 23 deletions

4
Cargo.lock generated
View File

@ -5876,7 +5876,7 @@ dependencies = [
[[package]]
name = "tao"
version = "0.18.1"
source = "git+https://github.com/tauri-apps/tao?branch=muda#0c1417884161d165b8852fbf11be5492edef9fe7"
source = "git+https://github.com/Kingtous/tao?branch=muda#dea701661a182cf2d944d5d05b5d299c78079871"
dependencies = [
"bitflags",
"cairo-rs",
@ -5921,7 +5921,7 @@ dependencies = [
[[package]]
name = "tao-macros"
version = "0.1.1"
source = "git+https://github.com/tauri-apps/tao?branch=muda#0c1417884161d165b8852fbf11be5492edef9fe7"
source = "git+https://github.com/Kingtous/tao?branch=muda#dea701661a182cf2d944d5d05b5d299c78079871"
dependencies = [
"proc-macro2 1.0.54",
"quote 1.0.26",

View File

@ -113,7 +113,7 @@ objc_id = "0.1"
[target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies]
tray-icon = "0.4"
tao = { git = "https://github.com/tauri-apps/tao", branch = "muda" }
tao = { git = "https://github.com/Kingtous/tao", branch = "muda" }
image = "0.24"
[target.'cfg(target_os = "linux")'.dependencies]

View File

@ -1581,7 +1581,13 @@ bool checkArguments() {
/// Returns true if we successfully handle the uri provided.
/// [Functions]
/// 1. New Connection: rustdesk://connection/new/your_peer_id
/// 2. Bring the main window to the top: empty uriPath
bool parseRustdeskUri(String uriPath) {
// If we invoke uri with blank path, we just bring the main window to tht top.
if (uriPath.isEmpty) {
window_on_top(null);
return true;
}
final uri = Uri.tryParse(uriPath);
if (uri == null) {
debugPrint("uri is not valid: $uriPath");

View File

@ -173,13 +173,10 @@ class PlatformFFI {
if (Platform.isLinux) {
// Start a dbus service, no need to await
_ffiBind.mainStartDbusServer();
_ffiBind.mainStartPa();
} else if (Platform.isMacOS && isMain) {
Future.wait([
// Start dbus service.
_ffiBind.mainStartDbusServer(),
// Start local audio pulseaudio server.
_ffiBind.mainStartPa()
]);
// Start ipc service for uri links.
_ffiBind.mainStartIpcUrlServer();
}
_startListenEvent(_ffiBind); // global event
try {

View File

@ -969,13 +969,20 @@ impl PeerConfig {
fn path(id: &str) -> PathBuf {
//If the id contains invalid chars, encode it
let forbidden_paths = Regex::new(r".*[<>:/\\|\?\*].*").unwrap();
let id_encoded = if forbidden_paths.is_match(id) {
"base64_".to_string() + base64::encode(id, base64::Variant::Original).as_str()
let forbidden_paths = Regex::new(r".*[<>:/\\|\?\*].*");
let path: PathBuf;
if let Ok(forbidden_paths) = forbidden_paths {
let id_encoded = if forbidden_paths.is_match(id) {
"base64_".to_string() + base64::encode(id, base64::Variant::Original).as_str()
} else {
id.to_string()
};
path = [PEERS, id_encoded.as_str()].iter().collect();
} else {
id.to_string()
};
let path: PathBuf = [PEERS, id_encoded.as_str()].iter().collect();
log::warn!("Regex create failed: {:?}", forbidden_paths.err());
// fallback for failing to create this regex.
path = [PEERS, id.replace(":", "_").as_str()].iter().collect();
}
Config::with_extension(Config::path(path))
}

View File

@ -6,7 +6,7 @@ use cocoa::{
base::{id, nil, YES},
foundation::{NSAutoreleasePool, NSString},
};
use objc::runtime::Class;
use objc::runtime::{Class, NO};
use objc::{
class,
declare::ClassDecl,
@ -107,7 +107,7 @@ pub unsafe fn set_delegate(handler: Option<Box<dyn AppHandler>>) {
);
decl.add_method(
sel!(handleEvent:withReplyEvent:),
handle_apple_event as extern "C" fn(&Object, Sel, u64, u64),
handle_apple_event as extern "C" fn(&Object, Sel, u64, u64) -> BOOL,
);
let decl = decl.register();
let delegate: id = msg_send![decl, alloc];
@ -183,11 +183,27 @@ extern "C" fn handle_menu_item(this: &mut Object, _: Sel, item: id) {
}
}
extern "C" fn handle_apple_event(_this: &Object, _cmd: Sel, event: u64, _reply: u64) {
#[no_mangle]
extern "C" fn handle_apple_event(_this: &Object, _cmd: Sel, event: u64, _reply: u64) -> BOOL {
let event = event as *mut Object;
let url = fruitbasket::parse_url_event(event);
log::debug!("an event was received: {}", url);
std::thread::spawn(move || crate::handle_url_scheme(url));
YES
}
// Customize the service opening logic.
#[no_mangle]
fn service_should_handle_reopen(
obj: &Object,
sel: Sel,
sender: id,
has_visible_windows: BOOL,
) -> BOOL {
log::debug!("Invoking the main rustdesk process");
std::thread::spawn(move || crate::handle_url_scheme("".to_string()));
// Prevent default logic.
NO
}
unsafe fn make_menu_item(title: &str, key: &str, tag: u32) -> *mut Object {

View File

@ -454,7 +454,7 @@ pub async fn start_ipc_url_server() {
let mut m = HashMap::new();
m.insert("name", "on_url_scheme_received");
m.insert("url", url.as_str());
let event = serde_json::to_string(&m).unwrap();
let event = serde_json::to_string(&m).unwrap_or("".to_owned());
match crate::flutter::push_global_event(crate::flutter::APP_TYPE_MAIN, event) {
None => log::warn!("No main window app found!"),
Some(..) => {}

View File

@ -131,10 +131,6 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
let event_loop = EventLoopBuilder::new().build();
unsafe {
crate::platform::delegate::set_delegate(None);
}
let tray_menu = Menu::new();
let quit_i = MenuItem::new(crate::client::translate("Exit".to_owned()), true, None);
tray_menu.append_items(&[&quit_i]);