Skip to content

Commit c0da74f

Browse files
committed
update coderabbit
1 parent d407513 commit c0da74f

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

Cargo.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/src/routes/app.control.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ function Component() {
4545
const isDraggingRef = useRef(false);
4646
const dragOffsetRef = useRef({ x: 0, y: 0 });
4747

48+
// Interaction tracking (lifted to component scope)
49+
const lastInteractionRef = React.useRef(Date.now());
50+
const trackInteraction = React.useCallback(() => {
51+
lastInteractionRef.current = Date.now();
52+
}, []);
53+
4854
// Update refs whenever state changes
4955
useEffect(() => {
5056
isDraggingRef.current = isDragging;
@@ -262,15 +268,9 @@ function Component() {
262268
updateOverlayBounds();
263269
};
264270

265-
// Lightweight recovery: only trigger on actual user interaction
266-
let lastInteractionTime = Date.now();
267-
const trackInteraction = () => {
268-
lastInteractionTime = Date.now();
269-
};
270-
271271
// Only do aggressive reset if it's been a while since last interaction
272272
const smartRecovery = () => {
273-
const timeSinceInteraction = Date.now() - lastInteractionTime;
273+
const timeSinceInteraction = Date.now() - lastInteractionRef.current;
274274
if (timeSinceInteraction > 10000) { // 10 seconds of no interaction
275275
windowsCommands.removeFakeWindow("control").then(() => {
276276
setTimeout(updateOverlayBounds, 100);

plugins/windows/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ tauri-plugin-auth = { workspace = true }
3333
thiserror = { workspace = true }
3434
tokio = { workspace = true, features = ["time"] }
3535
tracing = { workspace = true }
36+
once_cell = { workspace = true }

plugins/windows/src/ext.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ impl HyprWindow {
225225
fn close(&self, app: &AppHandle<tauri::Wry>) -> Result<(), crate::Error> {
226226
match self {
227227
HyprWindow::Control => {
228+
crate::abort_overlay_join_handle();
229+
228230
#[cfg(target_os = "macos")]
229231
{
230232
use tauri_nspanel::ManagerExt;
@@ -437,12 +439,12 @@ impl HyprWindow {
437439
}
438440

439441
let join_handle = crate::spawn_overlay_listener(app.clone(), window.clone());
442+
crate::set_overlay_join_handle(join_handle);
440443

441444
// Cancel the overlay listener when the window is closed
442-
let window_clone = window.clone();
443445
window.on_window_event(move |event| {
444446
if let tauri::WindowEvent::CloseRequested { .. } = event {
445-
join_handle.abort();
447+
crate::abort_overlay_join_handle();
446448
}
447449
});
448450

plugins/windows/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,30 @@ pub use overlay::{FakeWindowBounds, OverlayBound};
1313
const PLUGIN_NAME: &str = "windows";
1414

1515
use tauri::Manager;
16+
use std::sync::Mutex;
17+
use once_cell::sync::Lazy;
1618

1719
pub type ManagedState = std::sync::Mutex<State>;
1820

21+
static OVERLAY_JOIN_HANDLE: Lazy<Mutex<Option<tokio::task::JoinHandle<()>>>> = Lazy::new(|| Mutex::new(None));
22+
23+
pub fn set_overlay_join_handle(handle: tokio::task::JoinHandle<()>) {
24+
if let Ok(mut guard) = OVERLAY_JOIN_HANDLE.lock() {
25+
if let Some(old_handle) = guard.take() {
26+
old_handle.abort();
27+
}
28+
*guard = Some(handle);
29+
}
30+
}
31+
32+
pub fn abort_overlay_join_handle() {
33+
if let Ok(mut guard) = OVERLAY_JOIN_HANDLE.lock() {
34+
if let Some(handle) = guard.take() {
35+
handle.abort();
36+
}
37+
}
38+
}
39+
1940
#[derive(Default)]
2041
pub struct WindowState {
2142
floating: bool,

plugins/windows/src/overlay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn spawn_overlay_listener(app: AppHandle, window: WebviewWindow) -> tokio::t
6969

7070
let mut ignore = true;
7171

72-
for (name, bounds) in windows.iter() {
72+
for (_name, bounds) in windows.iter() {
7373
let x_min = (window_position.x as f64) + bounds.x * scale_factor;
7474
let x_max = (window_position.x as f64) + (bounds.x + bounds.width) * scale_factor;
7575
let y_min = (window_position.y as f64) + bounds.y * scale_factor;

0 commit comments

Comments
 (0)