Skip to content

Commit

Permalink
fix: Add panic result for has_screen_capture_access
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemcilroy committed Mar 18, 2024
1 parent 97716a8 commit 792d4c1
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions apps/desktop/src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,45 @@ use ffmpeg_sidecar::{
};
use capture::{Capturer, Display};
use std::time::{Duration, Instant};
use std::panic;

#[tauri::command]
pub fn has_screen_capture_access() -> bool {
let display = match Display::primary() {
Ok(display) => display,
Err(_) => return false,
};

let mut capturer = match Capturer::new(display) {
Ok(capturer) => capturer,
Err(_) => return false,
};

let start = Instant::now();
let result = panic::catch_unwind(|| {
let mut capturer = match Capturer::new(display) {
Ok(capturer) => capturer,
Err(_) => return false,
};

loop {
if start.elapsed() > Duration::from_secs(2) {
return false;
}
let start = Instant::now();

match capturer.frame() {
Ok(_frame) => {
return true;
},
Err(_) => {
continue;
loop {
if start.elapsed() > Duration::from_secs(2) {
return false;
}
};

match capturer.frame() {
Ok(_frame) => {
return true;
},
Err(_) => {
continue;
}
};
}
});

match result {
Ok(val) => val,
Err(_) => false,
}
}


pub fn run_command(command: &str, args: Vec<&str>) -> Result<(String, String), String> {
let output = Command::new(command)
.args(args)
Expand Down

1 comment on commit 792d4c1

@vercel
Copy link

@vercel vercel bot commented on 792d4c1 Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.