Skip to content

Commit d81a383

Browse files
committed
Update project configuration and enhance database initialization logic
- Updated Rust edition in Cargo.toml from 2021 to 2024 for improved language features. - Bumped application version in tauri.conf.json from 0.1.0 to 1.0.0 to reflect significant updates. - Enhanced database initialization in lib.rs to create an empty database file if it doesn't exist, ensuring proper directory structure for packaged apps. - Improved logging for backend executable resolution, providing better visibility into the paths being checked during application startup.
1 parent c4ea4c2 commit d81a383

File tree

3 files changed

+105
-6
lines changed

3 files changed

+105
-6
lines changed

frontend/src-tauri/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ description = "Budget Planer - A budget planning application"
55
authors = ["Budget Planer Team"]
66
license = ""
77
repository = ""
8-
edition = "2021"
9-
rust-version = "1.77.2"
8+
edition = "2024"
109

1110
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1211

frontend/src-tauri/src/lib.rs

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,23 @@ fn initialize_database(app: &tauri::AppHandle) -> Result<(), Box<dyn std::error:
273273
} else {
274274
warn!("Backend directory not found in any of these locations: {:?}", possible_backend_paths);
275275
warn!("Database will be created on first use when backend is available.");
276+
277+
// For packaged apps, create an empty database file so the directory structure is correct
278+
// The backend executable will handle migrations when it starts
279+
if let Some(parent) = db_path.parent() {
280+
if let Err(e) = std::fs::create_dir_all(parent) {
281+
warn!("Failed to create database directory: {}", e);
282+
} else {
283+
// Create an empty database file - SQLite will initialize it properly when first accessed
284+
if !db_path.exists() {
285+
if let Err(e) = std::fs::File::create(&db_path) {
286+
warn!("Failed to create database file: {}", e);
287+
} else {
288+
info!("Created empty database file at: {:?}", db_path);
289+
}
290+
}
291+
}
292+
}
276293
}
277294

278295
Ok(())
@@ -825,26 +842,109 @@ pub fn run() {
825842
let exe_path = std::env::current_exe().unwrap_or_default();
826843
let exe_dir = exe_path.parent().unwrap_or(std::path::Path::new("."));
827844

845+
info!("Looking for bundled backend executable...");
846+
info!("Executable path: {:?}", exe_path);
847+
info!("Executable directory: {:?}", exe_dir);
848+
828849
let mut possible_exe_paths: Vec<PathBuf> = vec![];
829850

830851
// Try Tauri resource resolution (for bundled resources)
831-
if let Ok(resource_dir) = app_handle.path().resource_dir() {
832-
possible_exe_paths.push(resource_dir.join("backend-server.exe"));
833-
possible_exe_paths.push(resource_dir.join("backend-server"));
852+
match app_handle.path().resource_dir() {
853+
Ok(resource_dir) => {
854+
info!("Resource directory resolved: {:?}", resource_dir);
855+
// Check if resource directory exists
856+
if resource_dir.exists() {
857+
info!("Resource directory exists, listing contents:");
858+
if let Ok(entries) = std::fs::read_dir(&resource_dir) {
859+
for entry in entries.flatten() {
860+
info!(" - {:?}", entry.path());
861+
}
862+
}
863+
} else {
864+
warn!("Resource directory does not exist: {:?}", resource_dir);
865+
}
866+
possible_exe_paths.push(resource_dir.join("backend-server.exe"));
867+
possible_exe_paths.push(resource_dir.join("backend-server"));
868+
}
869+
Err(e) => {
870+
warn!("Could not resolve resource directory: {}", e);
871+
}
872+
}
873+
874+
// Also try resolving the resource directly using Tauri's resolve method
875+
// This might work better in some bundle configurations
876+
// Note: In Tauri v2, resolve might work differently, so we try both approaches
877+
if let Ok(resource_path) = app_handle.path().resolve("backend-server", tauri::path::BaseDirectory::Resource) {
878+
info!("Resolved resource path (backend-server): {:?}", resource_path);
879+
possible_exe_paths.push(resource_path);
880+
}
881+
if let Ok(resource_path) = app_handle.path().resolve("backend-server.exe", tauri::path::BaseDirectory::Resource) {
882+
info!("Resolved resource path (backend-server.exe): {:?}", resource_path);
883+
possible_exe_paths.push(resource_path);
884+
}
885+
886+
// For Linux AppImages, resources might be in a different location
887+
// AppImages extract to a temporary directory, and resources are in usr/lib or usr/share
888+
#[cfg(target_os = "linux")]
889+
{
890+
// Check AppImage extraction directory structure
891+
if let Ok(appimage_path) = std::env::var("APPIMAGE") {
892+
info!("Running as AppImage: {}", appimage_path);
893+
if let Ok(appdir) = std::env::var("APPDIR") {
894+
info!("AppImage APPDIR: {}", appdir);
895+
let appdir_path = PathBuf::from(&appdir);
896+
possible_exe_paths.push(appdir_path.join("usr").join("lib").join("backend-server"));
897+
possible_exe_paths.push(appdir_path.join("usr").join("share").join("backend-server"));
898+
possible_exe_paths.push(appdir_path.join("resources").join("backend-server"));
899+
}
900+
}
901+
902+
// For DEB packages, resources are typically in /usr/lib or /usr/share
903+
// Check if we're in a system installation
904+
if exe_dir.starts_with("/usr") {
905+
possible_exe_paths.push(PathBuf::from("/usr/lib/budget-planer/backend-server"));
906+
possible_exe_paths.push(PathBuf::from("/usr/share/budget-planer/backend-server"));
907+
possible_exe_paths.push(PathBuf::from("/usr/lib/com.budgetplaner/backend-server"));
908+
possible_exe_paths.push(PathBuf::from("/usr/share/com.budgetplaner/backend-server"));
909+
}
834910
}
835911

836912
// Add paths relative to executable (fallback)
913+
// For standalone binaries, resources might be next to the executable
837914
possible_exe_paths.push(exe_dir.join("backend-server.exe"));
838915
possible_exe_paths.push(exe_dir.join("backend-server"));
839916
possible_exe_paths.push(exe_dir.join("resources").join("backend-server.exe"));
840917
possible_exe_paths.push(exe_dir.join("resources").join("backend-server"));
841918

919+
// For Linux, also check lib and share directories relative to executable
920+
// This is common for Linux applications and standalone binaries
921+
#[cfg(target_os = "linux")]
922+
{
923+
possible_exe_paths.push(exe_dir.join("lib").join("backend-server"));
924+
possible_exe_paths.push(exe_dir.join("share").join("backend-server"));
925+
possible_exe_paths.push(exe_dir.join("usr").join("lib").join("backend-server"));
926+
possible_exe_paths.push(exe_dir.join("usr").join("share").join("backend-server"));
927+
}
928+
842929
// Also check parent directories (for nested bundle structures)
843930
if let Some(parent) = exe_dir.parent() {
844931
possible_exe_paths.push(parent.join("backend-server.exe"));
845932
possible_exe_paths.push(parent.join("backend-server"));
846933
possible_exe_paths.push(parent.join("resources").join("backend-server.exe"));
847934
possible_exe_paths.push(parent.join("resources").join("backend-server"));
935+
936+
#[cfg(target_os = "linux")]
937+
{
938+
possible_exe_paths.push(parent.join("lib").join("backend-server"));
939+
possible_exe_paths.push(parent.join("share").join("backend-server"));
940+
}
941+
}
942+
943+
// Log all paths being checked
944+
info!("Checking the following paths for backend executable:");
945+
for path in &possible_exe_paths {
946+
let exists = path.exists();
947+
info!(" {:?} - {}", path, if exists { "EXISTS" } else { "not found" });
848948
}
849949

850950
let bundled_exe = possible_exe_paths.iter().find(|p| p.exists()).cloned();

frontend/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
33
"productName": "Budget Planer",
4-
"version": "0.1.0",
4+
"version": "1.0.0",
55
"identifier": "com.budgetplaner",
66
"build": {
77
"frontendDist": "../dist",

0 commit comments

Comments
 (0)