2024-04-07 21:31:08 +02:00
|
|
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
|
2024-04-18 10:16:06 +02:00
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
use home::home_dir;
|
2024-04-07 21:31:08 +02:00
|
|
|
use libsnotes::show_notes;
|
|
|
|
|
|
|
|
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
|
|
|
#[tauri::command]
|
|
|
|
fn greet(name: &str) -> String {
|
|
|
|
format!("Hello, {}! You've been greeted from Rust!", name)
|
|
|
|
}
|
|
|
|
|
2024-04-14 11:50:12 +02:00
|
|
|
/// get ALL notes in the Database. If you don't want this, set show_notes(false)
|
2024-04-07 21:31:08 +02:00
|
|
|
#[tauri::command]
|
|
|
|
fn get_notes_list() -> String {
|
2024-04-14 11:50:12 +02:00
|
|
|
let notes = show_notes(true, "").unwrap();
|
2024-04-13 20:51:49 +02:00
|
|
|
notes.to_string()
|
2024-04-07 21:31:08 +02:00
|
|
|
}
|
|
|
|
|
2024-04-15 14:22:46 +02:00
|
|
|
#[tauri::command]
|
|
|
|
fn get_latest_note() -> String {
|
|
|
|
let note = libsnotes::get_latest_note().unwrap();
|
|
|
|
note.to_string()
|
|
|
|
}
|
|
|
|
|
2024-04-17 13:11:54 +02:00
|
|
|
#[tauri::command]
|
|
|
|
fn get_note_by_id(id: u32) -> String {
|
|
|
|
let result = libsnotes::get_note_by_id(id).unwrap();
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2024-04-14 17:33:35 +02:00
|
|
|
#[tauri::command]
|
|
|
|
fn search_notes(query: &str) -> String {
|
|
|
|
let results = libsnotes::search_notes(query).unwrap();
|
|
|
|
results.to_string()
|
|
|
|
}
|
|
|
|
|
2024-04-09 19:54:49 +02:00
|
|
|
#[tauri::command]
|
|
|
|
fn create_note(content: &str, tag: &str) -> bool {
|
|
|
|
libsnotes::create_note(&content.to_string(), &tag.to_string()).unwrap();
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2024-04-13 20:51:49 +02:00
|
|
|
#[tauri::command]
|
|
|
|
fn delete_specific_note(id: u32) -> bool {
|
|
|
|
libsnotes::delete_specific_note(id.try_into().unwrap()).is_ok()
|
|
|
|
}
|
|
|
|
|
2024-04-14 11:50:12 +02:00
|
|
|
#[tauri::command]
|
|
|
|
fn update_specific_note(id: u32, content: &str, tag: &str) -> bool {
|
|
|
|
libsnotes::edit_specific_note(id.try_into().unwrap(), tag, content).is_ok()
|
|
|
|
}
|
|
|
|
|
2024-04-18 10:16:06 +02:00
|
|
|
#[tauri::command]
|
|
|
|
fn load_settings() -> String {
|
|
|
|
let settings_string = fs::read_to_string(
|
|
|
|
home_dir()
|
|
|
|
.unwrap()
|
|
|
|
.join(".snotes-data/snotes-settings.json"),
|
|
|
|
)
|
|
|
|
.unwrap_or(String::from(""))
|
|
|
|
.parse()
|
|
|
|
.unwrap_or(String::from(""));
|
|
|
|
dbg!(&settings_string);
|
|
|
|
settings_string
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
fn init_settings() {
|
|
|
|
let dir = home_dir().unwrap().join(".snotes-data");
|
|
|
|
dbg!(&dir);
|
|
|
|
if !dir.exists() {
|
|
|
|
fs::create_dir(dir).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
let settings = r#"
|
|
|
|
{
|
|
|
|
"fontSize": "16px"
|
|
|
|
}
|
|
|
|
"#;
|
|
|
|
|
|
|
|
fs::write(
|
|
|
|
home_dir()
|
|
|
|
.unwrap()
|
|
|
|
.join(".snotes-data/snotes-settings.json"),
|
|
|
|
settings,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
2024-04-07 21:31:08 +02:00
|
|
|
fn main() {
|
|
|
|
tauri::Builder::default()
|
2024-04-14 11:50:12 +02:00
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
greet,
|
|
|
|
get_notes_list,
|
2024-04-15 14:22:46 +02:00
|
|
|
get_latest_note,
|
2024-04-17 13:11:54 +02:00
|
|
|
get_note_by_id,
|
2024-04-14 17:33:35 +02:00
|
|
|
search_notes,
|
2024-04-14 11:50:12 +02:00
|
|
|
create_note,
|
|
|
|
delete_specific_note,
|
2024-04-18 10:16:06 +02:00
|
|
|
update_specific_note,
|
|
|
|
init_settings,
|
|
|
|
load_settings
|
2024-04-14 11:50:12 +02:00
|
|
|
])
|
2024-04-07 21:31:08 +02:00
|
|
|
.run(tauri::generate_context!())
|
|
|
|
.expect("error while running tauri application");
|
|
|
|
}
|