mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-22 05:34:04 +02:00
feat: add code detection support
This commit is contained in:
parent
149e72802c
commit
e674e0a0ec
2 changed files with 50 additions and 23 deletions
|
@ -22,7 +22,7 @@ tauri-plugin-updater = "2.3.0"
|
||||||
tauri-plugin-dialog = "2.2.0"
|
tauri-plugin-dialog = "2.2.0"
|
||||||
tauri-plugin-fs = "2.2.0"
|
tauri-plugin-fs = "2.2.0"
|
||||||
tauri-plugin-clipboard = "2.1.11"
|
tauri-plugin-clipboard = "2.1.11"
|
||||||
tauri-plugin-prevent-default = "1.0.0"
|
tauri-plugin-prevent-default = "1.0.1"
|
||||||
tauri-plugin-global-shortcut = "2.2.0"
|
tauri-plugin-global-shortcut = "2.2.0"
|
||||||
sqlx = { version = "0.8.2", features = ["runtime-tokio-native-tls", "sqlite", "chrono"] }
|
sqlx = { version = "0.8.2", features = ["runtime-tokio-native-tls", "sqlite", "chrono"] }
|
||||||
serde = { version = "1.0.216", features = ["derive"] }
|
serde = { version = "1.0.216", features = ["derive"] }
|
||||||
|
@ -43,6 +43,8 @@ chrono = { version = "0.4.39", features = ["serde"] }
|
||||||
uuid = "1.11.0"
|
uuid = "1.11.0"
|
||||||
active-win-pos-rs = "0.8.3"
|
active-win-pos-rs = "0.8.3"
|
||||||
include_dir = "0.7.4"
|
include_dir = "0.7.4"
|
||||||
|
hyperpolyglot = { git = "https://github.com/0pandadev/hyperpolyglot" }
|
||||||
|
applications = { git = "https://github.com/HuakunShen/applications-rs", branch = "dev" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
custom-protocol = ["tauri/custom-protocol"]
|
custom-protocol = ["tauri/custom-protocol"]
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
|
use base64::{engine::general_purpose::STANDARD, Engine};
|
||||||
|
use hyperpolyglot;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use rdev::{simulate, EventType, Key};
|
use rdev::{simulate, EventType, Key};
|
||||||
|
use regex::Regex;
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
use uuid::Uuid;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::{thread, time::Duration};
|
use std::{thread, time::Duration};
|
||||||
use tauri::{AppHandle, Emitter, Listener, Manager, Runtime};
|
use tauri::{AppHandle, Emitter, Listener, Manager, Runtime};
|
||||||
use tauri_plugin_clipboard::Clipboard;
|
use tauri_plugin_clipboard::Clipboard;
|
||||||
use tokio::runtime::Runtime as TokioRuntime;
|
use tokio::runtime::Runtime as TokioRuntime;
|
||||||
use regex::Regex;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use base64::{Engine, engine::general_purpose::STANDARD};
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::db;
|
||||||
use crate::utils::commands::get_app_info;
|
use crate::utils::commands::get_app_info;
|
||||||
use crate::utils::favicon::fetch_favicon_as_base64;
|
use crate::utils::favicon::fetch_favicon_as_base64;
|
||||||
use crate::db;
|
|
||||||
use crate::utils::types::{ContentType, HistoryItem};
|
use crate::utils::types::{ContentType, HistoryItem};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -111,18 +112,26 @@ pub fn setup<R: Runtime>(app: &AppHandle<R>) {
|
||||||
.unwrap_or_else(|e| e);
|
.unwrap_or_else(|e| e);
|
||||||
let _ = db::history::add_history_item(
|
let _ = db::history::add_history_item(
|
||||||
pool,
|
pool,
|
||||||
HistoryItem::new(app_name, ContentType::Image, file_path, None, app_icon),
|
HistoryItem::new(app_name, ContentType::Image, file_path, None, app_icon, None),
|
||||||
).await;
|
).await;
|
||||||
}
|
}
|
||||||
} else if available_types.files {
|
} else if available_types.files {
|
||||||
println!("Handling files change");
|
println!("Handling files change");
|
||||||
if let Ok(files) = clipboard.read_files() {
|
if let Ok(files) = clipboard.read_files() {
|
||||||
let files_str = files.join(", ");
|
for file in files {
|
||||||
let _ = db::history::add_history_item(
|
let _ = db::history::add_history_item(
|
||||||
pool,
|
pool.clone(),
|
||||||
HistoryItem::new(app_name, ContentType::File, files_str, None, app_icon),
|
HistoryItem::new(
|
||||||
|
app_name.clone(),
|
||||||
|
ContentType::File,
|
||||||
|
file,
|
||||||
|
None,
|
||||||
|
app_icon.clone(),
|
||||||
|
None
|
||||||
|
),
|
||||||
).await;
|
).await;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if available_types.text {
|
} else if available_types.text {
|
||||||
println!("Handling text change");
|
println!("Handling text change");
|
||||||
if let Ok(text) = clipboard.read_text() {
|
if let Ok(text) = clipboard.read_text() {
|
||||||
|
@ -137,17 +146,30 @@ pub fn setup<R: Runtime>(app: &AppHandle<R>) {
|
||||||
|
|
||||||
let _ = db::history::add_history_item(
|
let _ = db::history::add_history_item(
|
||||||
pool,
|
pool,
|
||||||
HistoryItem::new(app_name, ContentType::Link, text, favicon, app_icon)
|
HistoryItem::new(app_name, ContentType::Link, text, favicon, app_icon, None)
|
||||||
).await;
|
).await;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(detection) = hyperpolyglot::detect_from_text(&text) {
|
||||||
|
let language = match detection {
|
||||||
|
hyperpolyglot::Detection::Heuristics(lang) => lang.to_string(),
|
||||||
|
_ => detection.language().to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
let _ = db::history::add_history_item(
|
let _ = db::history::add_history_item(
|
||||||
pool,
|
pool,
|
||||||
HistoryItem::new(app_name, ContentType::Text, text, None, app_icon)
|
HistoryItem::new(app_name, ContentType::Code, text, None, app_icon, Some(language))
|
||||||
).await;
|
).await;
|
||||||
|
} else {
|
||||||
|
let _ = db::history::add_history_item(
|
||||||
|
pool,
|
||||||
|
HistoryItem::new(app_name, ContentType::Text, text, None, app_icon, None)
|
||||||
|
).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -183,7 +205,10 @@ pub fn start_monitor(app_handle: AppHandle) -> Result<(), String> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save_image_to_file<R: Runtime>(app_handle: &AppHandle<R>, base64_data: &str) -> Result<String, Box<dyn std::error::Error>> {
|
async fn save_image_to_file<R: Runtime>(
|
||||||
|
app_handle: &AppHandle<R>,
|
||||||
|
base64_data: &str,
|
||||||
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let app_data_dir = app_handle.path().app_data_dir().unwrap();
|
let app_data_dir = app_handle.path().app_data_dir().unwrap();
|
||||||
let images_dir = app_data_dir.join("images");
|
let images_dir = app_data_dir.join("images");
|
||||||
fs::create_dir_all(&images_dir)?;
|
fs::create_dir_all(&images_dir)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue