From 41e43ba35fbde833ad917b021df2aa70ad074e45 Mon Sep 17 00:00:00 2001 From: Francisco Salgueiro Date: Sun, 28 Jan 2024 18:24:13 +0000 Subject: [PATCH] improve logging --- src-tauri/src/main.rs | 7 ++++++- src-tauri/src/oauth.rs | 2 ++ src/App.tsx | 13 ++++++++----- src/atoms/utils.ts | 3 +++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4f64f6b0..3ab984f1 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -172,7 +172,9 @@ fn main() { ) .plugin(specta_builder) .setup(|app| { - // Check if all the required directories exist, and create them if they don't + log::info!("Setting up application"); + + log::info!("Checking for required directories"); for (dir, path) in REQUIRED_DIRS.iter() { let path = resolve_path( &app.config(), @@ -183,11 +185,13 @@ fn main() { ); if let Ok(path) = path { if !Path::new(&path).exists() { + log::info!("Creating directory {}", path.to_string_lossy()); create_dir_all(&path).unwrap(); } }; } + log::info!("Checking for required files"); for (dir, path) in REQUIRED_FILES.iter() { let path = resolve_path( &app.config(), @@ -198,6 +202,7 @@ fn main() { ) .unwrap(); if !Path::new(&path).exists() { + log::info!("Creating file {}", path.to_string_lossy()); std::fs::write(&path, "").unwrap(); } } diff --git a/src-tauri/src/oauth.rs b/src-tauri/src/oauth.rs index 9e4ab143..8aa56d81 100644 --- a/src-tauri/src/oauth.rs +++ b/src-tauri/src/oauth.rs @@ -1,4 +1,5 @@ use axum::{extract::Query, response::IntoResponse, routing::get, Extension, Router}; +use log::info; use oauth2::{ basic::BasicClient, reqwest::async_http_client, AuthUrl, AuthorizationCode, ClientId, CsrfToken, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, Scope, TokenResponse, TokenUrl, @@ -60,6 +61,7 @@ pub async fn authenticate( state: tauri::State<'_, AppState>, app: tauri::AppHandle, ) -> Result<(), Error> { + info!("Authenticating user {}", username); let (auth_url, _) = state .auth .client diff --git a/src/App.tsx b/src/App.tsx index 009201a0..851b2b63 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,7 +23,7 @@ import { getVersion } from "@tauri-apps/api/app"; import { getMatches } from "@tauri-apps/api/cli"; import { appWindow } from "@tauri-apps/api/window"; import { Helmet } from "react-helmet"; -import { attachConsole } from "tauri-plugin-log-api"; +import { attachConsole, info } from "tauri-plugin-log-api"; import { SideBar } from "./components/Sidebar"; import { ask, message, open } from "@tauri-apps/api/dialog"; @@ -370,13 +370,16 @@ export default function App() { (async () => { await commands.closeSplashscreen(); const detach = await attachConsole(); + info("React app started successfully"); const matches = await getMatches(); if (matches.args.file.occurrences > 0) { - if (typeof matches.args.file.value !== "string") return; - const file = matches.args.file.value; - router.navigate("/boards", { replace: true }); - openFile(file, setTabs, setActiveTab); + info(`Opening file from command line: ${matches.args.file.value}`); + if (typeof matches.args.file.value === "string") { + const file = matches.args.file.value; + router.navigate("/boards", { replace: true }); + openFile(file, setTabs, setActiveTab); + } } return () => { diff --git a/src/atoms/utils.ts b/src/atoms/utils.ts index b53da07f..368e4c2c 100644 --- a/src/atoms/utils.ts +++ b/src/atoms/utils.ts @@ -38,6 +38,9 @@ export function createZodStorage( return { getItem(key, initialValue) { const storedValue = storage.getItem(key); + if (storedValue === null) { + return initialValue; + } try { return schema.parse(JSON.parse(storedValue ?? "")); } catch {