[desktop] Add tauri logs
This commit is contained in:
6
desktop/tauri/src-tauri/Cargo.lock
generated
6
desktop/tauri/src-tauri/Cargo.lock
generated
@@ -209,6 +209,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_matches",
|
"assert_matches",
|
||||||
"cached",
|
"cached",
|
||||||
|
"clap 4.5.9",
|
||||||
"ctor",
|
"ctor",
|
||||||
"dark-light",
|
"dark-light",
|
||||||
"dataurl",
|
"dataurl",
|
||||||
@@ -7679,9 +7680,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-plugin-log"
|
name = "tauri-plugin-log"
|
||||||
version = "2.0.0-beta.8"
|
version = "2.0.0-beta.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4cc0912ad72022b4d931c909582f06edb0c5e696cb945f16189ed6abf48a0ebd"
|
checksum = "80f80d78a6e8102acf05a1e735f006991a2abfc71566d4e484f820b7495cd52c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android_logger",
|
"android_logger",
|
||||||
"byte-unit",
|
"byte-unit",
|
||||||
@@ -7695,6 +7696,7 @@ dependencies = [
|
|||||||
"swift-rs",
|
"swift-rs",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-plugin",
|
"tauri-plugin",
|
||||||
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,10 @@ tauri-plugin-single-instance = "2.0.0-beta"
|
|||||||
tauri-plugin-cli = "2.0.0-beta"
|
tauri-plugin-cli = "2.0.0-beta"
|
||||||
tauri-plugin-notification = "2.0.0-beta"
|
tauri-plugin-notification = "2.0.0-beta"
|
||||||
tauri-plugin-log = "2.0.0-beta"
|
tauri-plugin-log = "2.0.0-beta"
|
||||||
tauri-plugin-window-state = "2.0.0-beta.11"
|
tauri-plugin-window-state = "2.0.0-beta"
|
||||||
|
|
||||||
tauri-cli = "2.0.0-beta.21"
|
tauri-cli = "2.0.0-beta.21"
|
||||||
|
clap = { version = "4", features = [ "derive" ] }
|
||||||
|
|
||||||
# General
|
# General
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::{env, path::Path, time::Duration};
|
||||||
|
|
||||||
|
use clap::{command, Parser};
|
||||||
use tauri::{AppHandle, Emitter, Listener, Manager, RunEvent, WindowEvent};
|
use tauri::{AppHandle, Emitter, Listener, Manager, RunEvent, WindowEvent};
|
||||||
use tauri_plugin_cli::CliExt;
|
use tauri_plugin_cli::CliExt;
|
||||||
|
|
||||||
@@ -18,8 +19,9 @@ mod portmaster;
|
|||||||
mod traymenu;
|
mod traymenu;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info, LevelFilter};
|
||||||
use portmaster::PortmasterExt;
|
use portmaster::PortmasterExt;
|
||||||
|
use tauri_plugin_log::RotationStrategy;
|
||||||
use traymenu::setup_tray_menu;
|
use traymenu::setup_tray_menu;
|
||||||
use window::{close_splash_window, create_main_window};
|
use window::{close_splash_window, create_main_window};
|
||||||
|
|
||||||
@@ -28,6 +30,12 @@ extern crate lazy_static;
|
|||||||
|
|
||||||
const FALLBACK_TO_OLD_UI_EXIT_CODE: i32 = 77;
|
const FALLBACK_TO_OLD_UI_EXIT_CODE: i32 = 77;
|
||||||
|
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
const LOG_LEVEL: LevelFilter = LevelFilter::Warn;
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
const LOG_LEVEL: LevelFilter = LevelFilter::Debug;
|
||||||
|
|
||||||
#[derive(Clone, serde::Serialize)]
|
#[derive(Clone, serde::Serialize)]
|
||||||
struct Payload {
|
struct Payload {
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
@@ -41,6 +49,16 @@ struct WsHandler {
|
|||||||
is_first_connect: bool,
|
is_first_connect: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(version, about, long_about = None)]
|
||||||
|
struct BasicCli {
|
||||||
|
#[arg(long)]
|
||||||
|
data: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
log: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
impl portmaster::Handler for WsHandler {
|
impl portmaster::Handler for WsHandler {
|
||||||
fn name(&self) -> String {
|
fn name(&self) -> String {
|
||||||
"main-handler".to_string()
|
"main-handler".to_string()
|
||||||
@@ -114,11 +132,41 @@ fn main() {
|
|||||||
std::process::exit(show_webview_not_installed_dialog());
|
std::process::exit(show_webview_not_installed_dialog());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut target = tauri_plugin_log::Target::new(tauri_plugin_log::TargetKind::Stdout);
|
||||||
|
|
||||||
|
let cli = BasicCli::parse();
|
||||||
|
if let Some(data_dir) = cli.data {
|
||||||
|
target = tauri_plugin_log::Target::new(tauri_plugin_log::TargetKind::Folder {
|
||||||
|
path: Path::new(&format!("{}/logs/app2", data_dir)).into(),
|
||||||
|
file_name: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut log_level = LOG_LEVEL;
|
||||||
|
if let Some(level) = cli.log {
|
||||||
|
match level.as_str() {
|
||||||
|
"off" => log_level = LevelFilter::Off,
|
||||||
|
"error" => log_level = LevelFilter::Error,
|
||||||
|
"warn" => log_level = LevelFilter::Warn,
|
||||||
|
"info" => log_level = LevelFilter::Info,
|
||||||
|
"debug" => log_level = LevelFilter::Debug,
|
||||||
|
"trace" => log_level = LevelFilter::Trace,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let app = tauri::Builder::default()
|
let app = tauri::Builder::default()
|
||||||
// Shell plugin for open_external support
|
// Shell plugin for open_external support
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
// Initialize Logging plugin.
|
// Initialize Logging plugin.
|
||||||
.plugin(tauri_plugin_log::Builder::default().build())
|
.plugin(
|
||||||
|
tauri_plugin_log::Builder::default()
|
||||||
|
.level(log_level)
|
||||||
|
.rotation_strategy(RotationStrategy::KeepAll)
|
||||||
|
.clear_targets()
|
||||||
|
.target(target)
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
// Clipboard support
|
// Clipboard support
|
||||||
.plugin(tauri_plugin_clipboard_manager::init())
|
.plugin(tauri_plugin_clipboard_manager::init())
|
||||||
// Dialog (Save/Open) support
|
// Dialog (Save/Open) support
|
||||||
@@ -148,7 +196,6 @@ fn main() {
|
|||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
setup_tray_menu(app)?;
|
setup_tray_menu(app)?;
|
||||||
portmaster::setup(app.handle().clone());
|
portmaster::setup(app.handle().clone());
|
||||||
|
|
||||||
// Setup the single-instance event listener that will create/focus the main window
|
// Setup the single-instance event listener that will create/focus the main window
|
||||||
// or the splash-screen.
|
// or the splash-screen.
|
||||||
let handle = app.handle().clone();
|
let handle = app.handle().clone();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ pub fn create_main_window(app: &AppHandle) -> Result<WebviewWindow> {
|
|||||||
.title("Portmaster")
|
.title("Portmaster")
|
||||||
.visible(false)
|
.visible(false)
|
||||||
.inner_size(1200.0, 700.0)
|
.inner_size(1200.0, 700.0)
|
||||||
|
.min_inner_size(800.0, 600.0)
|
||||||
.theme(Some(Theme::Dark))
|
.theme(Some(Theme::Dark))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ pub fn open_window(app: &AppHandle) -> Result<WebviewWindow> {
|
|||||||
match app.get_webview_window("main") {
|
match app.get_webview_window("main") {
|
||||||
Some(win) => {
|
Some(win) => {
|
||||||
app.portmaster().show_window();
|
app.portmaster().show_window();
|
||||||
|
let _ = win.set_focus();
|
||||||
Ok(win)
|
Ok(win)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
"name": "background",
|
"name": "background",
|
||||||
"description": "Start in the background without opening a window"
|
"description": "Start in the background without opening a window"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "log",
|
||||||
|
"description": "Log level to use: off, error, warn, info, debug, trace",
|
||||||
|
"takesValue": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "with-notifications",
|
"name": "with-notifications",
|
||||||
"description": "Enable experimental notifications via Tauri. Replaces the notifier app."
|
"description": "Enable experimental notifications via Tauri. Replaces the notifier app."
|
||||||
@@ -29,7 +34,7 @@
|
|||||||
{
|
{
|
||||||
"name": "with-prompts",
|
"name": "with-prompts",
|
||||||
"description": "Enable experimental prompt support via Tauri. Replaces the notifier app."
|
"description": "Enable experimental prompt support via Tauri. Replaces the notifier app."
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user