[desktop] Add tauri logs
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![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_plugin_cli::CliExt;
|
||||
|
||||
@@ -18,8 +19,9 @@ mod portmaster;
|
||||
mod traymenu;
|
||||
mod window;
|
||||
|
||||
use log::{debug, error, info};
|
||||
use log::{debug, error, info, LevelFilter};
|
||||
use portmaster::PortmasterExt;
|
||||
use tauri_plugin_log::RotationStrategy;
|
||||
use traymenu::setup_tray_menu;
|
||||
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;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
const LOG_LEVEL: LevelFilter = LevelFilter::Warn;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
const LOG_LEVEL: LevelFilter = LevelFilter::Debug;
|
||||
|
||||
#[derive(Clone, serde::Serialize)]
|
||||
struct Payload {
|
||||
args: Vec<String>,
|
||||
@@ -41,6 +49,16 @@ struct WsHandler {
|
||||
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 {
|
||||
fn name(&self) -> String {
|
||||
"main-handler".to_string()
|
||||
@@ -114,11 +132,41 @@ fn main() {
|
||||
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()
|
||||
// Shell plugin for open_external support
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
// 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
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
// Dialog (Save/Open) support
|
||||
@@ -148,7 +196,6 @@ fn main() {
|
||||
.setup(|app| {
|
||||
setup_tray_menu(app)?;
|
||||
portmaster::setup(app.handle().clone());
|
||||
|
||||
// Setup the single-instance event listener that will create/focus the main window
|
||||
// or the splash-screen.
|
||||
let handle = app.handle().clone();
|
||||
|
||||
@@ -29,6 +29,7 @@ pub fn create_main_window(app: &AppHandle) -> Result<WebviewWindow> {
|
||||
.title("Portmaster")
|
||||
.visible(false)
|
||||
.inner_size(1200.0, 700.0)
|
||||
.min_inner_size(800.0, 600.0)
|
||||
.theme(Some(Theme::Dark))
|
||||
.build();
|
||||
|
||||
@@ -114,7 +115,7 @@ pub fn open_window(app: &AppHandle) -> Result<WebviewWindow> {
|
||||
match app.get_webview_window("main") {
|
||||
Some(win) => {
|
||||
app.portmaster().show_window();
|
||||
|
||||
let _ = win.set_focus();
|
||||
Ok(win)
|
||||
}
|
||||
None => {
|
||||
|
||||
Reference in New Issue
Block a user