diff --git a/.env b/.env index 3cc194b..359b8f0 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ -DATABASE_FILENAME=shortcut.db +BASE_STORE_PATH= +DATABASE_FILENAME=${BASE_STORE_PATH}shortcut.db DATABASE_URL=sqlite://${DATABASE_FILENAME}?mode=rwc PORT=8035 UI_URL=http://localhost:${PORT} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 111abe9..c4d6b65 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,5 @@ SQLite-trunk* *.db-shm *.db-wal ui/assets/main.css -build/*_installer.iss \ No newline at end of file +build/windows/*_installer.iss +logs/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 4b867ef..c7ce9c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,11 @@ serde = { version = "1.0.219", features = ["derive"] } sqlx = { version= "0.8.5", features=["sqlite", "runtime-tokio-native-tls", "macros"] } state = "0.6.0" tera = { version = "1.20", default-features = false} -tera-hot-reload = "0.2.4" +tera-hot-reload = "0.2.5" tokio = { version = "1.45.0", features = ["full"] } tower-http = { version = "0.6.4", features = ["full"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } +tracing-appender = "0.2" tracing = "0.1.40" thiserror = "2.0.12" url = "2.5.4" @@ -26,7 +27,7 @@ mockall = "0.13.1" auto-launch = "0.5.0" [build-dependencies] -cc = "1.0" +cc = "1.2.27" [features] default = [] diff --git a/Makefile b/Makefile index 663072a..72e5f07 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ tailwind-watch: npx @tailwindcss/cli -i ./ui/styles/tailwind.css -o ./ui/assets/main.css --watch server-watch: - RUST_LOG=info cargo watch -x run + RUST_LOG=info cargo watch -x run --ignore logs/ --ignore build/ --ignore docs/ build-windows: echo "🦀 Building Rust project..." @@ -22,13 +22,13 @@ build-windows: # Linux commands (without inno): VERSION=$(grep '^version' Cargo.toml | head -n1 | cut -d '"' -f2) - sed "s/{#AppVersion}/$VERSION/" build/windows_template.iss > build/windows_installer.iss + sed "s/{#AppVersion}/${VERSION}/" build/windows/windows_template.iss > build/windows/windows_installer.iss # Window commands: - # $versionLine = Get-Content Cargo.toml | Where-Object { $_ -match '^version\s*=' } | Select-Object -First 1 - # $version = $versionLine -replace '^version\s*=\s*"(.*)"', '$1' - # (Get-Content build\windows_template.iss) -replace '\{#AppVersion\}', $version | Set-Content build\windows_installer.iss - # & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" ".\build\windows_installer.iss" + $versionLine = Get-Content Cargo.toml | Where-Object { $_ -match '^version\s*=' } | Select-Object -First 1 + $version = $versionLine -replace '^version\s*=\s*"(.*)"', '$1' + (Get-Content build\windows\windows_template.iss) -replace '\{#AppVersion\}', $version | Set-Content build\windows\windows_installer.iss + & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" ".\build\windows\windows_installer.iss" echo "✅ Done!" diff --git a/build/ShortcutInstaller.exe b/build/ShortcutInstaller.exe deleted file mode 100644 index 8d98742..0000000 Binary files a/build/ShortcutInstaller.exe and /dev/null differ diff --git a/build/windows/.env b/build/windows/.env new file mode 100644 index 0000000..7dee5ec --- /dev/null +++ b/build/windows/.env @@ -0,0 +1,5 @@ +BASE_STORE_PATH=${homepath}/AppData/Roaming/Shortcut +DATABASE_FILENAME=${BASE_STORE_PATH}shortcut.db +DATABASE_URL=sqlite://${DATABASE_FILENAME}?mode=rwc +PORT=8035 +UI_URL=http://localhost:${PORT} \ No newline at end of file diff --git a/build/windows/ShortcutInstaller.exe b/build/windows/ShortcutInstaller.exe new file mode 100644 index 0000000..a37b334 Binary files /dev/null and b/build/windows/ShortcutInstaller.exe differ diff --git a/build/windows_template.iss b/build/windows/windows_template.iss similarity index 79% rename from build/windows_template.iss rename to build/windows/windows_template.iss index 565dd3f..d1a3ca9 100644 --- a/build/windows_template.iss +++ b/build/windows/windows_template.iss @@ -6,12 +6,12 @@ OutputDir=. OutputBaseFilename=ShortcutInstaller Compression=lzma SolidCompression=yes -SetupIconFile=docs\icon.ico +SetupIconFile=docs\images\icon.ico [Files] Source: "target/x86_64-pc-windows-gnu/release/shortcut.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "../target/x86_64-pc-windows-gnu/release/ui/*"; DestDir: "{app}/ui/"; Flags: ignoreversion recursesubdirs -Source: "../.env"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs +Source: "build/windows.env"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs [Icons] Name: "{group}\Shortcut"; Filename: "{app}\shortcut.exe" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2c9a350..bc727e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,13 +16,14 @@ use repository::shortcut::{ShortcutRepository, ShortcutRepositoryTrait}; use routes::create_api_routes; use sqlx::{Pool, Sqlite}; use templates::create_ui_routes; -use std::{sync::{LazyLock, RwLock}, time::Duration}; +use std::{env, io, sync::{LazyLock, RwLock}, time::Duration}; use tera::Tera; use tera_hot_reload::{watch, LiveReloadLayer}; use tokio::net::TcpListener; use tower_http::{compression::CompressionLayer, cors::{Any, CorsLayer}, services::ServeDir, trace::TraceLayer}; use tracing::info; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; +use tracing_appender::rolling; +use tracing_subscriber::{filter, fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer}; use schema::connect_db; use service::shortcut::ShortcutService; use state::AppState; @@ -49,7 +50,7 @@ pub async fn app() -> Result { .allow_methods([Method::GET, Method::POST, Method::DELETE, Method::PUT]) .allow_origin(Any) .allow_headers([CONTENT_TYPE]); - + let app: Router = Router::new() .merge(create_ui_routes()) .nest_service("/assets", ServeDir::new("ui/assets")) @@ -76,16 +77,37 @@ pub async fn app() -> Result { pub async fn run() { dotenv().ok(); + let base_store_path = std::env::var("BASE_STORE_PATH").unwrap_or(String::from("")); + eprintln!("{}", base_store_path); + let file_appender = rolling::never(base_store_path.clone() + "/logs", "full.log"); + let (file_writer, guard) = tracing_appender::non_blocking(file_appender); + Box::leak(Box::new(guard)); + + let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!( + "{}=debug,tower_http=debug,axum::rejection=trace", + env!("CARGO_CRATE_NAME") + ) + .into() + }); + + let file_layer = tracing_subscriber::fmt::layer() + .pretty() + .with_writer(file_writer); tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| format!( - "{}=debug,tower_http=debug,axum::rejection=trace", - env!("CARGO_CRATE_NAME") - ).into()), + // stdout layer, to view everything in the console + fmt::layer() + .compact() + .with_writer(io::stderr) + .with_filter(env_filter) + ) + .with( + file_layer + .with_ansi(false) + .with_filter(filter::LevelFilter::DEBUG), ) - .with(tracing_subscriber::fmt::layer()) .init(); let port = std::env::var("PORT").unwrap_or(String::from("3000"));