mirror of
https://github.com/ByteAtATime/raycast-linux.git
synced 2025-09-12 00:46:22 +00:00
feat(snippets): initialize snippet db
This commit creates the initial backend infrastructure for the snippets feature. It sets up the core data model, a dedicated `SnippetManager` for database interactions using `rusqlite`, and integrates it into the Tauri application state.
This commit is contained in:
parent
21cd217a26
commit
1a2fa36a79
4 changed files with 60 additions and 4 deletions
|
@ -13,12 +13,13 @@ mod quicklinks;
|
|||
mod snippets;
|
||||
mod system;
|
||||
|
||||
use crate::{app::App, cache::AppCache, snippets::input_manager::EvdevInputManager};
|
||||
use crate::{app::App, cache::AppCache};
|
||||
use browser_extension::WsState;
|
||||
use frecency::FrecencyManager;
|
||||
use quicklinks::QuicklinkManager;
|
||||
use selection::get_text;
|
||||
use snippets::input_manager::InputManager;
|
||||
use snippets::input_manager::{InputManager, RdevInputManager};
|
||||
use snippets::manager::SnippetManager;
|
||||
use std::process::Command;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
@ -156,7 +157,7 @@ fn setup_global_shortcut(app: &mut tauri::App) -> Result<(), Box<dyn std::error:
|
|||
|
||||
fn setup_input_listener() {
|
||||
thread::spawn(move || {
|
||||
let manager = EvdevInputManager::new();
|
||||
let manager = RdevInputManager::new();
|
||||
let callback = |event| {
|
||||
println!("[InputManager] Received Key: {:?}", event);
|
||||
};
|
||||
|
@ -245,6 +246,10 @@ pub fn run() {
|
|||
let frecency_manager = FrecencyManager::new(app.handle().clone())?;
|
||||
app.manage(frecency_manager);
|
||||
|
||||
let snippet_manager = SnippetManager::new(app.handle().clone())?;
|
||||
snippet_manager.init_db()?;
|
||||
app.manage(snippet_manager);
|
||||
|
||||
setup_background_refresh();
|
||||
setup_global_shortcut(app)?;
|
||||
setup_input_listener();
|
||||
|
|
36
src-tauri/src/snippets/manager.rs
Normal file
36
src-tauri/src/snippets/manager.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use crate::error::AppError;
|
||||
use rusqlite::{Connection, Result as RusqliteResult};
|
||||
use std::sync::Mutex;
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
pub struct SnippetManager {
|
||||
db: Mutex<Connection>,
|
||||
}
|
||||
|
||||
impl SnippetManager {
|
||||
pub fn new(app_handle: AppHandle) -> Result<Self, AppError> {
|
||||
let data_dir = app_handle
|
||||
.path()
|
||||
.app_local_data_dir()
|
||||
.map_err(|_| AppError::DirectoryNotFound)?;
|
||||
let db_path = data_dir.join("snippets.sqlite");
|
||||
let db = Connection::open(db_path)?;
|
||||
Ok(Self { db: Mutex::new(db) })
|
||||
}
|
||||
|
||||
pub fn init_db(&self) -> RusqliteResult<()> {
|
||||
let db = self.db.lock().unwrap();
|
||||
db.execute(
|
||||
"CREATE TABLE IF NOT EXISTS snippets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
keyword TEXT NOT NULL UNIQUE,
|
||||
content TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
)",
|
||||
[],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1 +1,3 @@
|
|||
pub mod input_manager;
|
||||
pub mod manager;
|
||||
pub mod types;
|
13
src-tauri/src/snippets/types.rs
Normal file
13
src-tauri/src/snippets/types.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Snippet {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub keyword: String,
|
||||
pub content: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue