Skip to content

Commit

Permalink
fix(macos): consistent injection
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Sep 9, 2023
1 parent 95bce54 commit 17747bc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src-tauri/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ use std::time::Duration;
static mut IS_READY: bool = false;

pub fn inject_routine(win: tauri::Window) {
win.listen("initial_inject", move |_| unsafe {
let win_cln = win.clone();

win.once("initial_inject", move |_| unsafe {
IS_READY = true;
println!("JS context ready!");
injection_runner::do_injection(win_cln);
});

std::thread::spawn(move || {
loop {
let win_cln = win.clone();

// Check if ready, if so, run injection
unsafe {
if IS_READY {
println!("JS context ready!");
injection_runner::do_injection(win_cln);
break;
}
}
Expand All @@ -27,12 +26,12 @@ pub fn inject_routine(win: tauri::Window) {
// Send javascript that sends the "initial_inject" event
//
// If it succeeds, that means the web context is ready
win_cln
win
.eval("window.__TAURI__.event.emit('initial_inject')")
.unwrap();

#[cfg(target_os = "macos")]
std::thread::sleep(Duration::from_millis(100));
std::thread::sleep(Duration::from_millis(10));

#[cfg(not(target_os = "macos"))]
std::thread::sleep(Duration::from_millis(100));
Expand Down

0 comments on commit 17747bc

Please sign in to comment.