propagated use of config home path to other systems. file loading now works using rust instead of js

This commit is contained in:
Iaphetes 2025-03-09 09:03:40 +01:00
parent 62918416ee
commit 11bd003298
11 changed files with 1007 additions and 1000 deletions

View file

@ -6,13 +6,17 @@ use std::{
use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool};
use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url};
use crate::get_basepath;
async fn populate_file_db(db: &SqlitePool) {}
#[tauri::command]
pub async fn initialize_database(
app_handle: tauri::AppHandle,
basepath: String,
pathtemplate: String,
) {
if let Some(basepath) = get_basepath(app_handle.clone()) {
let db_path = Path::new("Documents")
.join(Path::new("Knowledgebase"))
.join("db.sqlite");
@ -61,7 +65,10 @@ pub async fn initialize_database(
.execute(&db)
.await
.unwrap();
}
}
#[tauri::command]
async fn store_diff(diff: String) {}
async fn store_diff(diff: String) {
}

View file

@ -0,0 +1,19 @@
use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url};
use std::fs::{read_to_string};
use std::path::Path;
use crate::get_basepath;
#[tauri::command]
pub async fn save(
app_handle: tauri::AppHandle,
path: String, content: String) {}
#[tauri::command]
pub async fn load(
path: String) -> Result<String, String> {
println!("loading file");
read_to_string(path).map_err(|e| e.to_string())
}

View file

@ -1,3 +1,4 @@
use crate::get_basepath;
use html_tag::HtmlTag;
use shellexpand;
use std::{
@ -5,11 +6,11 @@ use std::{
path::Path,
};
#[tauri::command]
pub fn dir_tree_html(basepath: &str, filter: Vec<String>) -> String {
match shellexpand::full(basepath) {
Ok(path) => add_dir_tree_node(&Path::new(&path.into_owned()), &filter).to_html(),
Err(_) => String::new(),
pub fn dir_tree_html(app_handle: tauri::AppHandle, filter: Vec<String>) -> String {
if let Some(basepath) = get_basepath(app_handle) {
add_dir_tree_node(&Path::new(&basepath), &filter).to_html()
} else {
String::new()
}
}
fn add_dir_tree_node(path: &Path, filter: &Vec<String>) -> HtmlTag {

View file

@ -1,6 +1,7 @@
mod config;
mod database;
mod file_access;
mod file_handler;
mod file_tree;
mod markdown_parser;
mod search;
@ -14,7 +15,7 @@ use std::env;
use std::sync::Mutex;
use tauri::Manager;
use tauri_plugin_fs::FsExt;
use file_handler::load;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
@ -40,6 +41,7 @@ pub fn run() {
search_files,
get_basepath,
set_basepath,
load
])
.run(tauri::generate_context!())
.expect("error while running tauri application");

View file

@ -1,2 +0,0 @@
#[tauri::command]
pub async fn save(path: String, content: String) {}