Skip to content

Commit

Permalink
Revert "feat(dock): try to setup macos dock handler"
Browse files Browse the repository at this point in the history
This reverts commit be4d562.
  • Loading branch information
greenhat616 committed Sep 3, 2024
1 parent e7cd92e commit 38b6c5e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 50 deletions.
51 changes: 3 additions & 48 deletions backend/tauri/src/utils/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@ pub mod macos {
extern crate cocoa;
extern crate objc;

use cocoa::{
appkit::{NSApp, NSApplication, NSApplicationActivationPolicy, NSWindow},
base::{id, nil, BOOL, NO, YES},
};
use objc::{
class,
declare::ClassDecl,
msg_send,
runtime::{Object, Sel},
sel, sel_impl,
};
use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicy};
use objc::runtime::YES;

pub unsafe fn show_dock_icon() {
let app = NSApp();
app.setActivationPolicy_(
Expand All @@ -28,41 +20,4 @@ pub mod macos {
NSApplicationActivationPolicy::NSApplicationActivationPolicyAccessory,
);
}

pub fn setup_dock_click_handler() {
unsafe {
let app = NSApp();
let superclass = class!(NSObject);
let mut decl = ClassDecl::new("AppDelegate", superclass).unwrap();
decl.add_method(
sel!(applicationShouldHandleReopen:hasVisibleWindows:),
reopen_handler as extern "C" fn(&mut Object, Sel, id, BOOL) -> BOOL,
);
decl.register();
let delegate: id = msg_send![class!(AppDelegate), new];
app.setDelegate_(delegate);
}
}

extern "C" fn reopen_handler(_: &mut Object, _: Sel, _: id, has_visible_windows: BOOL) -> BOOL {
unsafe {
let app = NSApp();
let current_policy: NSApplicationActivationPolicy = msg_send![app, activationPolicy];
if current_policy
== NSApplicationActivationPolicy::NSApplicationActivationPolicyAccessory
{
if has_visible_windows == NO {
// resolve crate window
let handle = crate::core::handle::Handle::global();
let app_handle = handle.app_handle.lock();
if let Some(app_handle) = app_handle.as_ref() {
crate::utils::resolve::create_window(app_handle);
}
}
NO
} else {
YES
}
}
}
}
2 changes: 0 additions & 2 deletions backend/tauri/src/utils/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ pub fn find_unused_port() -> Result<u16> {
pub fn resolve_setup(app: &mut App) {
#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Accessory);
#[cfg(target_os = "macos")]
crate::utils::dock::macos::setup_dock_click_handler();
app.listen_global("react_app_mounted", move |_| {
tracing::debug!("Frontend React App is mounted, reset open window counter");
reset_window_open_counter();
Expand Down

0 comments on commit 38b6c5e

Please sign in to comment.