From 463fb4d85e45a5f9e4bd915d1290b1a8e8d885e2 Mon Sep 17 00:00:00 2001 From: kiwi <1145567334@qq.com> Date: Sun, 1 Dec 2024 22:48:43 +0800 Subject: [PATCH] 1 --- src-tauri/src/frontend_commands/fs.rs | 18 ++++++- src-tauri/src/lib.rs | 2 + src-tauri/src/python_commands/input.rs | 7 +-- src/components/NewProject.vue | 5 ++ src/components/monitor/FindImage.vue | 71 +++++++++++++++++++++++--- src/stores/app.js | 6 +++ 6 files changed, 97 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/frontend_commands/fs.rs b/src-tauri/src/frontend_commands/fs.rs index e6c8662..e769c73 100644 --- a/src-tauri/src/frontend_commands/fs.rs +++ b/src-tauri/src/frontend_commands/fs.rs @@ -1,6 +1,10 @@ -use crate::utils; +use crate::{ + common::{Base64Png, Base64PngExt}, + utils, +}; use serde::Serialize; use std::fs; +use std::path::Path; #[tauri::command] pub fn create_dir(path: String) -> Result { @@ -81,6 +85,18 @@ pub fn read_dir(path: String) -> Result, String> { Ok(files) } +#[tauri::command] +pub fn save_base64_image(path: String, data: Base64Png) -> Result { + let buffer = data.to_buffer().unwrap(); + let path = Path::new(path.as_str()); + let parent_path = path.parent().unwrap(); + let _ = utils::fs::create_dir(parent_path.to_str().unwrap().to_string()); + if let Err(error) = buffer.save(path) { + return Err(error.to_string()); + } + Ok(true) +} + #[derive(Debug, Serialize, Clone)] pub struct Entry { name: String, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a9a82d8..3c8909a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -32,6 +32,7 @@ pub fn run() { frontend_commands::fs::exists, frontend_commands::fs::write_file, frontend_commands::fs::read_file, + frontend_commands::fs::save_base64_image, frontend_commands::capture::snapshot, frontend_commands::capture::display_size, frontend_commands::find::find_peak, @@ -69,6 +70,7 @@ pub fn run() { frontend_commands::fs::exists, frontend_commands::fs::write_file, frontend_commands::fs::read_file, + frontend_commands::fs::save_base64_image, frontend_commands::capture::snapshot, frontend_commands::capture::display_size, frontend_commands::find::find_image, diff --git a/src-tauri/src/python_commands/input.rs b/src-tauri/src/python_commands/input.rs index e22d041..95f4ee0 100644 --- a/src-tauri/src/python_commands/input.rs +++ b/src-tauri/src/python_commands/input.rs @@ -1,4 +1,4 @@ -use crate::{common::Point, input}; +use crate::input; use pyo3::prelude::*; #[pyfunction] @@ -50,8 +50,9 @@ pub fn move_rel(x: i32, y: i32) -> PyResult<()> { } #[pyfunction] -pub fn location() -> PyResult { - Ok(input::location()) +pub fn location() -> PyResult<(f64, f64)> { + let point = input::location(); + Ok((point.x, point.y)) } #[pyfunction] diff --git a/src/components/NewProject.vue b/src/components/NewProject.vue index d9b29a7..f50272e 100644 --- a/src/components/NewProject.vue +++ b/src/components/NewProject.vue @@ -6,6 +6,7 @@ import { resourceDir, scriptDir, defaultScriptFile, + moduleDir, } from "./../stores/app"; import { sep } from "@tauri-apps/api/path"; import { createDir, createFile, exists } from "./../utils/fs"; @@ -29,9 +30,13 @@ async function save() { msgError(`project already exists`); return; } + const module = await moduleDir(form.name); const resouce = await resourceDir(form.name); const script = await scriptDir(form.name); const defaultFile = await defaultScriptFile(form.name); + await createDir(module); + //copy default moudles into module folder + //todo await createDir(project); await createDir(resouce); await createDir(script); diff --git a/src/components/monitor/FindImage.vue b/src/components/monitor/FindImage.vue index 65a2d41..a07570a 100644 --- a/src/components/monitor/FindImage.vue +++ b/src/components/monitor/FindImage.vue @@ -1,12 +1,15 @@ diff --git a/src/stores/app.js b/src/stores/app.js index 5ac0103..17be54b 100644 --- a/src/stores/app.js +++ b/src/stores/app.js @@ -4,8 +4,14 @@ import { sep } from "@tauri-apps/api/path"; export const projectsDir = await invoke("projects_dir"); export const scriptDirName = "scripts"; export const resourceDirName = "resources"; +export const moduleDirName = "modules"; export const defaultScriptName = "main.py"; +export const moduleDir = async (projectName) => { + return ( + projectsDir + (await sep()) + projectName + (await sep()) + moduleDirName + ); +}; export const resourceDir = async (projectName) => { return ( projectsDir + (await sep()) + projectName + (await sep()) + resourceDirName