2026-02-20 22:55:49 +01:00
|
|
|
pub mod ai_chat;
|
2026-02-17 12:05:39 +01:00
|
|
|
pub mod frontmatter;
|
2026-02-15 12:54:11 +01:00
|
|
|
pub mod git;
|
2026-02-22 13:33:32 +01:00
|
|
|
pub mod settings;
|
2026-02-14 18:20:07 +01:00
|
|
|
pub mod vault;
|
|
|
|
|
|
2026-02-20 22:55:49 +01:00
|
|
|
use ai_chat::{AiChatRequest, AiChatResponse};
|
2026-02-15 12:54:11 +01:00
|
|
|
use git::{GitCommit, ModifiedFile};
|
2026-02-22 13:33:32 +01:00
|
|
|
use settings::Settings;
|
2026-02-21 19:13:03 +01:00
|
|
|
use vault::{VaultEntry, RenameResult};
|
2026-02-17 12:05:39 +01:00
|
|
|
use frontmatter::FrontmatterValue;
|
2026-02-14 18:20:07 +01:00
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn list_vault(path: String) -> Result<Vec<VaultEntry>, String> {
|
2026-02-17 17:06:26 +01:00
|
|
|
vault::scan_vault_cached(&path)
|
2026-02-14 18:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-15 12:54:11 +01:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn get_note_content(path: String) -> Result<String, String> {
|
|
|
|
|
vault::get_note_content(&path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn update_frontmatter(path: String, key: String, value: FrontmatterValue) -> Result<String, String> {
|
|
|
|
|
vault::update_frontmatter(&path, &key, value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn delete_frontmatter_property(path: String, key: String) -> Result<String, String> {
|
|
|
|
|
vault::delete_frontmatter_property(&path, &key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn get_file_history(vault_path: String, path: String) -> Result<Vec<GitCommit>, String> {
|
|
|
|
|
git::get_file_history(&vault_path, &path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn get_modified_files(vault_path: String) -> Result<Vec<ModifiedFile>, String> {
|
|
|
|
|
git::get_modified_files(&vault_path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn get_file_diff(vault_path: String, path: String) -> Result<String, String> {
|
|
|
|
|
git::get_file_diff(&vault_path, &path)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 22:27:18 +01:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn get_file_diff_at_commit(vault_path: String, path: String, commit_hash: String) -> Result<String, String> {
|
|
|
|
|
git::get_file_diff_at_commit(&vault_path, &path, &commit_hash)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-15 12:54:11 +01:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn git_commit(vault_path: String, message: String) -> Result<String, String> {
|
|
|
|
|
git::git_commit(&vault_path, &message)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn git_push(vault_path: String) -> Result<String, String> {
|
|
|
|
|
git::git_push(&vault_path)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 22:55:49 +01:00
|
|
|
#[tauri::command]
|
|
|
|
|
async fn ai_chat(request: AiChatRequest) -> Result<AiChatResponse, String> {
|
|
|
|
|
ai_chat::send_chat(request).await
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 10:07:02 +01:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn save_image(vault_path: String, filename: String, data: String) -> Result<String, String> {
|
|
|
|
|
vault::save_image(&vault_path, &filename, &data)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 19:13:03 +01:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn rename_note(vault_path: String, old_path: String, new_title: String) -> Result<RenameResult, String> {
|
|
|
|
|
vault::rename_note(&vault_path, &old_path, &new_title)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 17:14:02 +01:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn purge_trash(vault_path: String) -> Result<Vec<String>, String> {
|
|
|
|
|
vault::purge_trash(&vault_path)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 13:33:32 +01:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn get_settings() -> Result<Settings, String> {
|
|
|
|
|
settings::get_settings()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn save_settings(settings: Settings) -> Result<(), String> {
|
|
|
|
|
settings::save_settings(settings)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 18:20:07 +01:00
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
|
|
|
pub fn run() {
|
|
|
|
|
tauri::Builder::default()
|
|
|
|
|
.setup(|app| {
|
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
|
app.handle().plugin(
|
|
|
|
|
tauri_plugin_log::Builder::default()
|
|
|
|
|
.level(log::LevelFilter::Info)
|
|
|
|
|
.build(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
2026-02-21 17:14:02 +01:00
|
|
|
|
2026-02-22 12:10:24 +01:00
|
|
|
#[cfg(desktop)]
|
|
|
|
|
{
|
|
|
|
|
app.handle().plugin(tauri_plugin_updater::Builder::new().build())?;
|
|
|
|
|
app.handle().plugin(tauri_plugin_process::init())?;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 17:14:02 +01:00
|
|
|
// Purge trashed files older than 30 days on startup
|
|
|
|
|
let vault_path = dirs::home_dir()
|
|
|
|
|
.map(|h| h.join("Laputa"))
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
if vault_path.is_dir() {
|
|
|
|
|
match vault::purge_trash(vault_path.to_str().unwrap_or_default()) {
|
|
|
|
|
Ok(deleted) if !deleted.is_empty() => {
|
|
|
|
|
log::info!("Purged {} trashed files on startup", deleted.len());
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
log::warn!("Failed to purge trash on startup: {}", e);
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 18:20:07 +01:00
|
|
|
Ok(())
|
|
|
|
|
})
|
2026-02-15 12:54:11 +01:00
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
list_vault,
|
|
|
|
|
get_note_content,
|
|
|
|
|
update_frontmatter,
|
|
|
|
|
delete_frontmatter_property,
|
2026-02-21 19:13:03 +01:00
|
|
|
rename_note,
|
2026-02-15 12:54:11 +01:00
|
|
|
get_file_history,
|
|
|
|
|
get_modified_files,
|
|
|
|
|
get_file_diff,
|
2026-02-21 22:27:18 +01:00
|
|
|
get_file_diff_at_commit,
|
2026-02-15 12:54:11 +01:00
|
|
|
git_commit,
|
2026-02-20 22:55:49 +01:00
|
|
|
git_push,
|
2026-02-21 13:08:29 +01:00
|
|
|
ai_chat,
|
2026-02-21 17:14:02 +01:00
|
|
|
save_image,
|
2026-02-22 13:33:32 +01:00
|
|
|
purge_trash,
|
|
|
|
|
get_settings,
|
|
|
|
|
save_settings
|
2026-02-15 12:54:11 +01:00
|
|
|
])
|
2026-02-14 18:20:07 +01:00
|
|
|
.run(tauri::generate_context!())
|
|
|
|
|
.expect("error while running tauri application");
|
|
|
|
|
}
|