Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve screenshot speed #761

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
12 changes: 6 additions & 6 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions src-tauri/src/window.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::config::get;
use crate::config::set;
use crate::StringWrapper;
use crate::APP;
use crate::{
config::{get, set},
screenshot, StringWrapper, APP,
};
use log::{info, warn};
use tauri::Manager;
use tauri::Monitor;
use tauri::Window;
use tauri::WindowBuilder;
use mouse_position::mouse_position::{Mouse, Position};
use tauri::{Manager, Monitor, Window, WindowBuilder};
#[cfg(any(target_os = "macos", target_os = "windows"))]
use window_shadows::set_shadow;

Expand Down Expand Up @@ -56,8 +54,6 @@ fn get_current_monitor(x: i32, y: i32) -> Monitor {

// Creating a window on the mouse monitor
fn build_window(label: &str, title: &str) -> (Window, bool) {
use mouse_position::mouse_position::{Mouse, Position};

let mouse_position = match Mouse::get_mouse_position() {
Mouse::Position { x, y } => Position { x, y },
Mouse::Error => {
Expand Down Expand Up @@ -120,7 +116,6 @@ pub fn config_window() {
}

fn translate_window() -> Window {
use mouse_position::mouse_position::{Mouse, Position};
// Mouse physical position
let mut mouse_position = match Mouse::get_mouse_position() {
Mouse::Position { x, y } => Position { x, y },
Expand Down Expand Up @@ -337,6 +332,17 @@ pub fn ocr_recognize() {
});
}
pub fn ocr_translate() {
let mouse_position = match Mouse::get_mouse_position() {
Mouse::Position { x, y } => Position { x, y },
Mouse::Error => {
warn!("Mouse position not found, using (0, 0) as default");
Position { x: 0, y: 0 }
}
};
let current_monitor = get_current_monitor(mouse_position.x, mouse_position.y);
let position = current_monitor.position();
screenshot(position.x, position.y);

let window = screenshot_window();
let window_ = window.clone();
window.listen("success", move |event| {
Expand Down
11 changes: 3 additions & 8 deletions src/window/Screenshot/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ export default function Screenshot() {
const imgRef = useRef();

useEffect(() => {
currentMonitor().then((monitor) => {
const position = monitor.position;
invoke('screenshot', { x: position.x, y: position.y }).then(() => {
appCacheDir().then((appCacheDirPath) => {
join(appCacheDirPath, 'pot_screenshot.png').then((filePath) => {
setImgurl(convertFileSrc(filePath));
});
});
appCacheDir().then((appCacheDirPath) => {
join(appCacheDirPath, 'pot_screenshot.png').then((filePath) => {
setImgurl(convertFileSrc(filePath));
});
});
}, []);
Expand Down