This commit is contained in:
PandaDEV 2025-04-15 22:39:51 +02:00 committed by GitHub
commit 2016e614ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 1748 additions and 273 deletions

View file

@ -230,7 +230,6 @@ pub fn setup(app: &AppHandle) {
}
}
let _ = app_handle.emit("clipboard-content-updated", ());
let _ = app_handle.track_event(
"clipboard_copied",
Some(

View file

@ -5,6 +5,7 @@ use rand::distr::Alphanumeric;
use sqlx::{ Row, SqlitePool };
use std::fs;
use tauri_plugin_aptabase::EventTracker;
use tauri::Emitter;
pub async fn initialize_history(pool: &SqlitePool) -> Result<(), Box<dyn std::error::Error>> {
let id: String = rng()
@ -71,8 +72,12 @@ pub async fn add_history_item(
Some(_) => {
sqlx
::query(
"UPDATE history SET timestamp = strftime('%Y-%m-%dT%H:%M:%f+00:00', 'now') WHERE content = ? AND content_type = ?"
"UPDATE history SET source = ?, source_icon = ?, timestamp = strftime('%Y-%m-%dT%H:%M:%f+00:00', 'now'), favicon = ?, language = ? WHERE content = ? AND content_type = ?"
)
.bind(&source)
.bind(&source_icon)
.bind(&favicon)
.bind(&language)
.bind(&content)
.bind(&content_type)
.execute(&*pool).await
@ -102,6 +107,8 @@ pub async fn add_history_item(
"content_type": item.content_type.to_string()
}))
);
let _ = app_handle.emit("clipboard-content-updated", ());
Ok(())
}
@ -191,6 +198,7 @@ pub async fn delete_history_item(
.map_err(|e| e.to_string())?;
let _ = app_handle.track_event("history_item_deleted", None);
let _ = app_handle.emit("clipboard-content-updated", ());
Ok(())
}
@ -206,6 +214,7 @@ pub async fn clear_history(
.map_err(|e| e.to_string())?;
let _ = app_handle.track_event("history_cleared", None);
let _ = app_handle.emit("clipboard-content-updated", ());
Ok(())
}

View file

@ -127,7 +127,8 @@ fn main() {
db::history::read_image,
db::settings::get_setting,
db::settings::save_setting,
utils::commands::fetch_page_meta
utils::commands::fetch_page_meta,
utils::commands::get_app_info
]
)
.run(tauri::generate_context!())

View file

@ -36,31 +36,49 @@ pub fn center_window_on_current_monitor(window: &tauri::WebviewWindow) {
}
}
#[tauri::command]
pub fn get_app_info() -> (String, Option<String>) {
println!("Getting app info");
let mut ctx = AppInfoContext::new(vec![]);
println!("Created AppInfoContext");
ctx.refresh_apps().unwrap();
if let Err(e) = ctx.refresh_apps() {
println!("Failed to refresh apps: {:?}", e);
return ("System".to_string(), None);
}
println!("Refreshed apps");
match ctx.get_frontmost_application() {
Ok(window) => {
println!("Found frontmost application: {}", window.name);
let name = window.name.clone();
let icon = window
.load_icon()
.ok()
.map(|i| {
println!("Loading icon for {}", name);
let png = i.to_png().unwrap();
let encoded = STANDARD.encode(png.get_bytes());
println!("Icon encoded successfully");
encoded
});
println!("Returning app info: {} with icon: {}", name, icon.is_some());
(name, icon)
let result = std::panic::catch_unwind(|| {
match ctx.get_frontmost_application() {
Ok(window) => {
println!("Found frontmost application: {}", window.name);
let name = window.name.clone();
let icon = window
.load_icon()
.ok()
.and_then(|i| {
println!("Loading icon for {}", name);
i.to_png().ok().map(|png| {
let encoded = STANDARD.encode(png.get_bytes());
println!("Icon encoded successfully");
encoded
})
});
println!("Returning app info: {} with icon: {}", name, icon.is_some());
(name, icon)
}
Err(e) => {
println!("Failed to get frontmost application: {:?}", e);
("System".to_string(), None)
}
}
Err(e) => {
println!("Failed to get frontmost application: {:?}", e);
});
match result {
Ok(info) => info,
Err(_) => {
println!("Panic occurred while getting app info");
("System".to_string(), None)
}
}