Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ fn monitor_info_fallback() -> (f64, f64, f64, f64) {
cg_displays::main_display()
}

/// Activates the app before showing the overlay panel so AppKit treats the
/// WebView as part of the key application, restoring hover and cursor updates.
#[cfg(target_os = "macos")]
pub(crate) fn activate_app() {
if let Some(mtm) = tauri_nspanel::objc2_foundation::MainThreadMarker::new() {
let app = tauri_nspanel::objc2_app_kit::NSApplication::sharedApplication(mtm);
#[allow(deprecated)]
app.activateIgnoringOtherApps(true);
}
}

/// Shows the overlay and requests the frontend to replay its entrance animation.
///
/// Uses `show_and_make_key()` to guarantee the NSPanel becomes the key window,
Expand Down Expand Up @@ -264,24 +275,36 @@ fn show_overlay(app_handle: &tauri::AppHandle, ctx: crate::context::ActivationCo
None => (None, None, None),
};

match app_handle.get_webview_panel("main") {
Ok(panel) => {
panel.show_and_make_key();
emit_overlay_visibility(
app_handle,
OVERLAY_VISIBILITY_SHOW,
selected_text,
window_x,
window_y,
screen_bottom_y,
);
let handle = app_handle.clone();
let _ = app_handle.run_on_main_thread(move || {
if let (Some(x), Some(y), Some(window)) =
(window_x, window_y, handle.get_webview_window("main"))
{
let _ =
window.set_position(tauri::Position::Logical(tauri::LogicalPosition::new(x, y)));
}
Err(e) => {
eprintln!("thuki: [show_overlay] get_webview_panel FAILED: {e:?}");
// Reset the flag so future activation attempts are not permanently blocked.
OVERLAY_INTENDED_VISIBLE.store(false, Ordering::SeqCst);

activate_app();

match handle.get_webview_panel("main") {
Ok(panel) => {
panel.show_and_make_key();
emit_overlay_visibility(
&handle,
OVERLAY_VISIBILITY_SHOW,
selected_text,
window_x,
window_y,
screen_bottom_y,
);
}
Err(e) => {
eprintln!("thuki: [show_overlay] get_webview_panel FAILED: {e:?}");
// Reset the flag so future activation attempts are not permanently blocked.
OVERLAY_INTENDED_VISIBLE.store(false, Ordering::SeqCst);
}
}
}
});
}

/// Requests an animated hide sequence from the frontend. The actual native
Expand Down Expand Up @@ -529,6 +552,7 @@ fn init_panel(app_handle: &tauri::AppHandle) {
fn show_onboarding_window(app_handle: &tauri::AppHandle, stage: onboarding::OnboardingStage) {
let handle = app_handle.clone();
let _ = app_handle.run_on_main_thread(move || {
activate_app();
if let Some(window) = handle.get_webview_window("main") {
let _ = window.set_size(tauri::Size::Logical(tauri::LogicalSize::new(
ONBOARDING_LOGICAL_WIDTH,
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub async fn capture_screenshot_command(
let show_handle = app_handle.clone();
let _ = app_handle.run_on_main_thread(move || {
use tauri_nspanel::ManagerExt;
crate::activate_app();
match show_handle.get_webview_panel("main") {
Ok(panel) => panel.show_and_make_key(),
Err(_) => {
Expand Down