Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Jan 28, 2024
1 parent 6e69b00 commit 41e43ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/oauth.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 () => {
Expand Down
3 changes: 3 additions & 0 deletions src/atoms/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export function createZodStorage<Value>(
return {
getItem(key, initialValue) {
const storedValue = storage.getItem(key);
if (storedValue === null) {
return initialValue;
}
try {
return schema.parse(JSON.parse(storedValue ?? ""));
} catch {
Expand Down

0 comments on commit 41e43ba

Please sign in to comment.