refactor: clean up main.rs by removing unused imports and simplifying main window initialization

This commit is contained in:
PandaDEV 2024-12-30 12:04:23 +10:00
parent 4004b3509f
commit 0a08ce95d2
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C

View file

@ -7,14 +7,12 @@ mod api;
mod db; mod db;
mod utils; mod utils;
use sqlx::sqlite::SqlitePoolOptions;
use std::fs; use std::fs;
use tauri::Manager; use tauri::Manager;
use tauri::WebviewUrl; use tauri_plugin_aptabase::{EventTracker, InitOptions};
use tauri::WebviewWindow;
use sqlx::sqlite::SqlitePoolOptions;
use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_prevent_default::Flags; use tauri_plugin_prevent_default::Flags;
use tauri_plugin_aptabase::{EventTracker, InitOptions};
fn main() { fn main() {
let runtime = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime"); let runtime = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime");
@ -27,19 +25,27 @@ fn main() {
.plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_updater::Builder::default().build()) .plugin(tauri_plugin_updater::Builder::default().build())
.plugin(tauri_plugin_aptabase::Builder::new("A-SH-8937252746") .plugin(
.with_options(InitOptions { tauri_plugin_aptabase::Builder::new("A-SH-8937252746")
host: Some("https://aptabase.pandadev.net".to_string()), .with_options(InitOptions {
flush_interval: None, host: Some("https://aptabase.pandadev.net".to_string()),
}) flush_interval: None,
.with_panic_hook(Box::new(|client, info, msg| { })
let location = info.location().map(|loc| format!("{}:{}:{}", loc.file(), loc.line(), loc.column())).unwrap_or_else(|| "".to_string()); .with_panic_hook(Box::new(|client, info, msg| {
let location = info
.location()
.map(|loc| format!("{}:{}:{}", loc.file(), loc.line(), loc.column()))
.unwrap_or_else(|| "".to_string());
let _ = client.track_event("panic", Some(serde_json::json!({ let _ = client.track_event(
"info": format!("{} ({})", msg, location), "panic",
}))); Some(serde_json::json!({
})) "info": format!("{} ({})", msg, location),
.build()) })),
);
}))
.build(),
)
.plugin(tauri_plugin_autostart::init( .plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent, MacosLauncher::LaunchAgent,
Some(vec![]), Some(vec![]),
@ -76,22 +82,7 @@ fn main() {
app_handle_clone.manage(pool); app_handle_clone.manage(pool);
}); });
let main_window = if let Some(window) = app.get_webview_window("main") { let main_window = app.get_webview_window("main");
window
} else {
WebviewWindow::builder(app.handle(), "main", WebviewUrl::App("index.html".into()))
.title("Qopy")
.resizable(false)
.fullscreen(false)
.inner_size(750.0, 474.0)
.focused(true)
.skip_taskbar(true)
.visible(false)
.decorations(false)
.transparent(true)
.always_on_top(false)
.build()?
};
let _ = db::database::setup(app); let _ = db::database::setup(app);
api::hotkeys::setup(app_handle.clone()); api::hotkeys::setup(app_handle.clone());
@ -99,8 +90,8 @@ fn main() {
api::clipboard::setup(app.handle()); api::clipboard::setup(app.handle());
let _ = api::clipboard::start_monitor(app_handle.clone()); let _ = api::clipboard::start_monitor(app_handle.clone());
utils::commands::center_window_on_current_monitor(&main_window); utils::commands::center_window_on_current_monitor(main_window.as_ref().unwrap());
main_window.hide()?; main_window.as_ref().map(|w| w.hide()).unwrap_or(Ok(()))?;
let _ = app.track_event("app_started", None); let _ = app.track_event("app_started", None);