diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 936cbd9..157d9af 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -7,6 +7,7 @@ name = "ace" version = "3.0.0" dependencies = [ "discord-rich-presence", + "log", "matchit", "notify", "notify-debouncer-mini", @@ -14,6 +15,7 @@ dependencies = [ "serde_json", "tauri", "tauri-build", + "tauri-plugin-log", "uuid 1.2.2", "window-shadows", ] @@ -100,6 +102,17 @@ dependencies = [ "url", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -169,6 +182,16 @@ version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +[[package]] +name = "byte-unit" +version = "4.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da78b32057b8fdfc352504708feeba7216dcd65a2c9ab02978cbd288d1279b6c" +dependencies = [ + "serde", + "utf8-width", +] + [[package]] name = "bytemuck" version = "1.12.3" @@ -304,6 +327,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + [[package]] name = "combine" version = "4.6.6" @@ -614,6 +648,16 @@ dependencies = [ "instant", ] +[[package]] +name = "fern" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f0c14694cbd524c8720dd69b0e3179344f04ebb5f90f2e4a440c6ea3b2f1ee" +dependencies = [ + "colored", + "log", +] + [[package]] name = "field-offset" version = "0.3.4" @@ -1373,6 +1417,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", + "value-bag", ] [[package]] @@ -1678,6 +1723,15 @@ dependencies = [ "syn", ] +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + [[package]] name = "objc" version = "0.2.7" @@ -2879,6 +2933,21 @@ dependencies = [ "tauri-utils", ] +[[package]] +name = "tauri-plugin-log" +version = "0.0.0" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#efcc3df3fe9467e8993d49c465f21fe7760d233b" +dependencies = [ + "byte-unit", + "fern", + "log", + "serde", + "serde_json", + "serde_repr", + "tauri", + "time", +] + [[package]] name = "tauri-runtime" version = "0.12.0" @@ -3025,6 +3094,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" dependencies = [ "itoa 1.0.4", + "libc", + "num_threads", "serde", "time-core", "time-macros", @@ -3210,6 +3281,12 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf8-width" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" + [[package]] name = "uuid" version = "0.8.2" @@ -3236,6 +3313,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.0.0-alpha.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" +dependencies = [ + "ctor", + "version_check", +] + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3cdbce4..6d3f038 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -14,14 +14,16 @@ rust-version = "1.57" tauri-build = {version = "1.2", features = [] } [dependencies] -serde_json = "1.0" +discord-rich-presence = "0.2.3" +log = "^0.4" +matchit = "0.7.0" +notify = { version = "5.0.0", features = ["serde"] } +notify-debouncer-mini = "0.2.1" serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" tauri = { version = "1.2", features = ["api-all"] } +tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1", features = ["colored"] } uuid = { version = "1.2.2", features = ["v4", "fast-rng", "serde"] } -notify = { version = "5.0.0", features = ["serde"] } -notify-debouncer-mini = "0.2.1" -matchit = "0.7.0" -discord-rich-presence = "0.2.3" window-shadows = "0.2.1" [features] diff --git a/src-tauri/src/discord.rs b/src-tauri/src/discord.rs index 51ce327..869f016 100644 --- a/src-tauri/src/discord.rs +++ b/src-tauri/src/discord.rs @@ -1,5 +1,6 @@ use discord_rich_presence::activity::{Activity, Timestamps}; use discord_rich_presence::{DiscordIpc, DiscordIpcClient}; +use log::{error, info}; use std::ops::DerefMut; use std::sync::RwLock; use std::time::{SystemTime, UNIX_EPOCH}; @@ -10,8 +11,14 @@ impl DiscordClient { pub fn new() -> Self { let mut discord = DiscordIpcClient::new("1046278806685622302").unwrap(); let ipc = match discord.connect() { - Ok(_) => Some(discord), - Err(_) => None, + Ok(_) => { + info!("Connected to Discord IPC"); + Some(discord) + } + Err(err) => { + error!("{err}"); + None + } }; let client = DiscordClient(RwLock::new(ipc)); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index ebffbea..ca2f5b6 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -3,33 +3,63 @@ windows_subsystem = "windows" )] -use tauri::Manager; use crate::discord::DiscordClient; use crate::project::ActiveProject; use crate::server::ResourceRouter; use crate::watcher::FileWatcher; +use log::LevelFilter; +use tauri::Manager; +use tauri_plugin_log::fern::colors::{Color, ColoredLevelConfig}; +use tauri_plugin_log::LogTarget; use window_shadows::set_shadow; pub mod discord; pub mod project; pub mod server; -pub mod watcher; pub mod simvars; +pub mod watcher; fn main() { + let log_color_config = ColoredLevelConfig::default() + .info(Color::Blue) + .debug(Color::Cyan) + .trace(Color::BrightWhite); + tauri::Builder::default() + .plugin( + tauri_plugin_log::Builder::default() + .format(move |out, message, record| { + out.finish(format_args!( + "{:<5} [{}] {}", + log_color_config.color(record.level()), + record.target(), + message, + )); + }) + .targets([LogTarget::LogDir, LogTarget::Stdout]) + .level(if cfg!(debug_assertions) { + LevelFilter::Debug + } else { + LevelFilter::Info + }) + .build(), + ) .setup(move |app| { + // Window shadow and (on Windows) rounded corners since we disabled `decorations`. if cfg!(target_os = "windows") || cfg!(target_os = "linux") { let window = app.get_window("main").unwrap(); set_shadow(&window, true).unwrap_or_default(); } + + // Configure manage state here so that `tauri_plugin_log` can capture messages. + app.manage(ActiveProject::default()); + app.manage(FileWatcher::default()); + app.manage(ResourceRouter::new()); + app.manage(DiscordClient::new()); + Ok(()) }) .register_uri_scheme_protocol("ace", server::handle_ace_request) - .manage(ActiveProject::default()) - .manage(FileWatcher::default()) - .manage(ResourceRouter::new()) - .manage(DiscordClient::new()) .invoke_handler(tauri::generate_handler![ project::commands::create_project, project::commands::update_project, diff --git a/src-tauri/src/server.rs b/src-tauri/src/server.rs index 489ebec..9839d6b 100644 --- a/src-tauri/src/server.rs +++ b/src-tauri/src/server.rs @@ -1,4 +1,5 @@ use crate::project::ActiveProject; +use log::{error, info}; use matchit::Router; use std::error::Error; use std::fs; @@ -27,6 +28,7 @@ pub enum ResourceType { } pub fn handle_ace_request(app: &AppHandle, req: &Request) -> Result> { + info!("{} {}", req.method(), req.uri()); let resource_router = app.state::().inner(); let active_project = app.state::().inner(); @@ -52,22 +54,29 @@ pub fn handle_ace_request(app: &AppHandle, req: &Request) -> Result ResponseBuilder::new() .status(200) .header("Access-Control-Allow-Origin", "*") .body(data) .unwrap(), - Err(_) => ResponseBuilder::new() - .status(404) - .body("Unknown path".as_bytes().to_vec()) - .unwrap(), + Err(err) => { + error!("{err}"); + ResponseBuilder::new() + .status(404) + .body("Unknown path".as_bytes().to_vec()) + .unwrap() + } } } - Err(_) => ResponseBuilder::new() - .status(404) - .body("Unknown path".as_bytes().to_vec()) - .unwrap(), + Err(err) => { + error!("{err}"); + ResponseBuilder::new() + .status(404) + .body("Unknown path".as_bytes().to_vec()) + .unwrap() + } }; Ok(response)