inital
4
src-tauri/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
/gen/schemas
|
5595
src-tauri/Cargo.lock
generated
Normal file
33
src-tauri/Cargo.toml
Normal file
|
@ -0,0 +1,33 @@
|
|||
[package]
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
license = ""
|
||||
repository = ""
|
||||
edition = "2021"
|
||||
rust-version = "1.70"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
name = "app_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.0.0-beta.18", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2.0.0-beta.23", features = ["unstable"] }
|
||||
tauri-plugin-clipboard-manager = "2.1.0-beta.5"
|
||||
tauri-plugin-window-state = "2.0.0-beta.10"
|
||||
tauri-plugin-sql = {version = "2.0.0-beta.8", features = ["sqlite"] }
|
||||
tauri-plugin-global-shortcut = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
tauri-plugin-autostart = "2.0.0-beta.8"
|
||||
sqlx = { version = "0.7.4", features = ["runtime-tokio-native-tls", "sqlite"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
serde_json = "1.0"
|
||||
rdev = "0.5.3"
|
||||
rand = "0.8"
|
||||
tauri-plugin-os = "2.0.0-beta.7"
|
3
src-tauri/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
42
src-tauri/capabilities/default.json
Normal file
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "enables the default permissions",
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"path:default",
|
||||
"event:default",
|
||||
"window:default",
|
||||
"webview:default",
|
||||
"app:default",
|
||||
"resources:default",
|
||||
"image:default",
|
||||
"menu:default",
|
||||
"tray:default",
|
||||
"clipboard-manager:default",
|
||||
"clipboard-manager:allow-read-text",
|
||||
"clipboard-manager:allow-write-text",
|
||||
"clipboard-manager:allow-read-image",
|
||||
"clipboard-manager:allow-write-html",
|
||||
"clipboard-manager:allow-write-image",
|
||||
"sql:allow-load",
|
||||
"sql:allow-select",
|
||||
"sql:allow-execute",
|
||||
"global-shortcut:default",
|
||||
"global-shortcut:allow-is-registered",
|
||||
"global-shortcut:allow-register",
|
||||
"global-shortcut:allow-unregister",
|
||||
"global-shortcut:allow-unregister-all",
|
||||
"autostart:allow-enable",
|
||||
"autostart:allow-disable",
|
||||
"autostart:allow-is-enabled",
|
||||
"os:allow-os-type",
|
||||
"app:allow-app-hide",
|
||||
"app:allow-app-show",
|
||||
"window:allow-hide",
|
||||
"window:allow-show",
|
||||
"window:allow-set-focus"
|
||||
]
|
||||
}
|
BIN
src-tauri/icons/128x128.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
After Width: | Height: | Size: 9 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
After Width: | Height: | Size: 2 KiB |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
src-tauri/icons/icon.png
Normal file
After Width: | Height: | Size: 49 KiB |
133
src-tauri/src/lib.rs
Normal file
|
@ -0,0 +1,133 @@
|
|||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
use rdev::{listen, EventType, Key};
|
||||
use sqlx::{sqlite::SqlitePoolOptions, SqlitePool};
|
||||
use std::fs;
|
||||
use std::sync::mpsc;
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, Some(vec![])))
|
||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
.plugin(tauri_plugin_window_state::Builder::default().build())
|
||||
.plugin(tauri_plugin_sql::Builder::default().build())
|
||||
.setup(|app| {
|
||||
let app_handle = app.handle().clone();
|
||||
|
||||
let rt = Runtime::new().expect("Failed to create Tokio runtime");
|
||||
|
||||
let app_data_dir = app.path().app_data_dir().unwrap();
|
||||
fs::create_dir_all(&app_data_dir).expect("Failed to create app data directory");
|
||||
|
||||
let db_path = app_data_dir.join("data.db");
|
||||
let is_new_db = !db_path.exists();
|
||||
if is_new_db {
|
||||
fs::File::create(&db_path).expect("Failed to create database file");
|
||||
}
|
||||
|
||||
let db_url = format!("sqlite:{}", db_path.to_str().unwrap());
|
||||
let pool = rt.block_on(async {
|
||||
SqlitePoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&db_url)
|
||||
.await
|
||||
.expect("Failed to create pool")
|
||||
});
|
||||
|
||||
rt.block_on(async {
|
||||
sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS history (
|
||||
id TEXT PRIMARY KEY,
|
||||
content TEXT NOT NULL,
|
||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)"
|
||||
)
|
||||
.execute(&pool)
|
||||
.await
|
||||
.expect("Failed to create table");
|
||||
|
||||
if is_new_db {
|
||||
let id: String = thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(16)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
sqlx::query("INSERT INTO history (id, content) VALUES (?, ?)")
|
||||
.bind(id)
|
||||
.bind("Welcome to your clipboard history!")
|
||||
.execute(&pool)
|
||||
.await
|
||||
.expect("Failed to insert welcome message");
|
||||
}
|
||||
});
|
||||
|
||||
app.manage(pool);
|
||||
app.manage(rt);
|
||||
|
||||
if let Some(window) = app.get_window("main") {
|
||||
let _ = window.restore_state(StateFlags::POSITION);
|
||||
window.show().unwrap();
|
||||
}
|
||||
|
||||
std::thread::spawn(move || {
|
||||
listen(move |event| match event.event_type {
|
||||
EventType::KeyPress(Key::ControlLeft | Key::ControlRight) => {
|
||||
let _ = tx.send(true);
|
||||
}
|
||||
EventType::KeyRelease(Key::KeyC) => {
|
||||
if rx.try_recv().is_ok() {
|
||||
match app_handle.clipboard().read_text() {
|
||||
Ok(content) => {
|
||||
let pool = app_handle.state::<SqlitePool>();
|
||||
let rt = app_handle.state::<Runtime>();
|
||||
rt.block_on(async {
|
||||
let exists = sqlx::query_scalar::<_, bool>("SELECT EXISTS(SELECT 1 FROM history WHERE content = ?)")
|
||||
.bind(&content)
|
||||
.fetch_one(&*pool)
|
||||
.await
|
||||
.unwrap_or(false);
|
||||
|
||||
if !exists {
|
||||
let id: String = thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(16)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
let _ = sqlx::query("INSERT INTO history (id, content) VALUES (?, ?)")
|
||||
.bind(id)
|
||||
.bind(content)
|
||||
.execute(&*pool)
|
||||
.await;
|
||||
}
|
||||
});
|
||||
},
|
||||
Err(e) => eprintln!("Error reading clipboard: {:?}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.unwrap();
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|app, event| match event {
|
||||
tauri::WindowEvent::CloseRequested { .. }
|
||||
| tauri::WindowEvent::Destroyed
|
||||
| tauri::WindowEvent::Focused(false) => {
|
||||
let _ = AppHandleExt::save_window_state(app.app_handle(), StateFlags::POSITION);
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
6
src-tauri/src/main.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
app_lib::run();
|
||||
}
|
48
src-tauri/tauri.conf.json
Normal file
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"productName": "Clipboard Manager",
|
||||
"version": "0.1.0",
|
||||
"identifier": "net.pandadev.clipboard-manager",
|
||||
"build": {
|
||||
"frontendDist": "../dist",
|
||||
"devUrl": "http://localhost:3000",
|
||||
"beforeDevCommand": "pnpm nuxt dev",
|
||||
"beforeBuildCommand": "pnpm nuxt generate"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "Clipboard Manager",
|
||||
"titleBarStyle": "Overlay",
|
||||
"fullscreen": false,
|
||||
"resizable": false,
|
||||
"height": 474,
|
||||
"width": 750,
|
||||
"minHeight": 474,
|
||||
"maxHeight": 474,
|
||||
"minWidth": 750,
|
||||
"maxWidth": 750,
|
||||
"decorations": false,
|
||||
"center": true,
|
||||
"shadow": false,
|
||||
"transparent": true,
|
||||
"visible": false
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
},
|
||||
"withGlobalTauri": true
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
},
|
||||
"$schema": "../node_modules/@tauri-apps/cli/schema.json"
|
||||
}
|