Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwi committed Dec 3, 2024
1 parent 5d028c7 commit b1df9c0
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 45 deletions.
2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ tauri-plugin-store = "2.1.0"
tauri-plugin-os = "2"

# others
log = "0.4.22"
env_logger = "0.11.5"
directories = "5.0.1"
crabgrab = { git = "https://github.com/qzd1989/CrabGrab.git", features = [
"bitmap",
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use opencv::prelude::*;
use pyo3::prelude::*;
use serde::{Deserialize, Serialize};
use std::collections::VecDeque;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::sync::Mutex;

lazy_static! {
pub static ref VERSION: String = String::from("1.0.0");
Expand All @@ -28,7 +27,8 @@ lazy_static! {
.unwrap()
.to_string()
};
pub static ref PROJECT_DIR: Arc<Mutex<Option<PathBuf>>> = Arc::new(Mutex::new(None));
pub static ref PROJECT_DIR: Mutex<Option<String>> = Mutex::new(None);
pub static ref HAHA: Mutex<Option<String>> = Mutex::new(None);
pub static ref PYTHON_EXEC_FILE: String = {
#[cfg(target_os = "macos")]
{
Expand Down
32 changes: 22 additions & 10 deletions src-tauri/src/frontend_commands/project.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use super::AppHandleExt as _;
use crate::{
capture::{listen_primary_display, CAPTURE_SWITCH},
common::{PROJECT_DIR, PYTHON_EXEC_FILE},
capture::{listen_primary_display, CAPTURE_SWITCH, FRAME},
common::{HAHA, PROJECT_DIR, PYTHON_EXEC_FILE},
};
use lazy_static::lazy_static;
use std::{
io::{BufRead, BufReader},
path::PathBuf,
process::{Command, Stdio},
sync::{Arc, Mutex},
};
Expand All @@ -18,7 +17,6 @@ use install::TESSERACT_DIR;
use std::os::windows::process::CommandExt;
#[cfg(target_os = "windows")]
use windows::Win32::System::Threading::CREATE_NO_WINDOW;
/// project about
#[tauri::command]
pub fn run(app: AppHandle, file: String) {
let app: Arc<Mutex<AppHandle>> = Arc::new(Mutex::new(app));
Expand All @@ -35,7 +33,22 @@ pub fn run(app: AppHandle, file: String) {
{
*CAPTURE_SWITCH.lock().unwrap() = true;
listen_primary_display();
//waiting until the frame is not empty
loop {
if FRAME.lock().unwrap().is_some() {
break;
}
}
}
println!("set haha");
*HAHA.lock().unwrap() = Some("huhu".to_string());
println!(
"haha: {:?}",
HAHA.lock()
.unwrap()
.clone()
.unwrap_or("none from run".to_string())
);
std::thread::spawn(move || {
let handle = Command::new(PYTHON_EXEC_FILE.to_string())
.arg(file)
Expand Down Expand Up @@ -140,16 +153,15 @@ pub fn stop(app: AppHandle) {

#[tauri::command]
pub fn set_project(path: String) {
let path_buff = PathBuf::from(path);
*PROJECT_DIR.lock().unwrap() = Some(path_buff);
*PROJECT_DIR.lock().unwrap() = Some(path);
}

#[tauri::command]
pub fn get_project_dir() -> Result<String, String> {
let project_path = PROJECT_DIR.lock().unwrap();
match project_path.as_ref() {
Some(path_buff) => Ok(path_buff.to_str().unwrap().to_string()),
None => Ok("".to_string()),
let project_path = PROJECT_DIR.lock().unwrap().clone();
match project_path {
Some(path) => Ok(path),
None => Err("project dir is not set".to_string()),
}
}

Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use pyo3::prelude::*;
//for frontend
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
env_logger::init();
let frontend = tauri::Builder::default()
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
Expand Down
Loading

0 comments on commit b1df9c0

Please sign in to comment.