Skip to content

Commit

Permalink
refactor: clean up main.rs by removing unused imports and simplifying…
Browse files Browse the repository at this point in the history
… main window initialization
  • Loading branch information
0PandaDEV committed Dec 30, 2024
1 parent 4004b35 commit 0a08ce9
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ mod api;
mod db;
mod utils;

use sqlx::sqlite::SqlitePoolOptions;
use std::fs;
use tauri::Manager;
use tauri::WebviewUrl;
use tauri::WebviewWindow;
use sqlx::sqlite::SqlitePoolOptions;
use tauri_plugin_aptabase::{EventTracker, InitOptions};
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_prevent_default::Flags;
use tauri_plugin_aptabase::{EventTracker, InitOptions};

fn main() {
let runtime = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime");
Expand All @@ -27,19 +25,27 @@ fn main() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_updater::Builder::default().build())
.plugin(tauri_plugin_aptabase::Builder::new("A-SH-8937252746")
.with_options(InitOptions {
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());

let _ = client.track_event("panic", Some(serde_json::json!({
"info": format!("{} ({})", msg, location),
})));
}))
.build())
.plugin(
tauri_plugin_aptabase::Builder::new("A-SH-8937252746")
.with_options(InitOptions {
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());

let _ = client.track_event(
"panic",
Some(serde_json::json!({
"info": format!("{} ({})", msg, location),
})),
);
}))
.build(),
)
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
Some(vec![]),
Expand All @@ -52,7 +58,7 @@ fn main() {
.setup(|app| {
let app_data_dir = app.path().app_data_dir().unwrap();
utils::logger::init_logger(&app_data_dir).expect("Failed to initialize logger");

fs::create_dir_all(&app_data_dir).expect("Failed to create app data directory");

let db_path = app_data_dir.join("data.db");
Expand All @@ -76,31 +82,16 @@ fn main() {
app_handle_clone.manage(pool);
});

let main_window = if let Some(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 main_window = app.get_webview_window("main");

let _ = db::database::setup(app);
api::hotkeys::setup(app_handle.clone());
api::tray::setup(app)?;
api::clipboard::setup(app.handle());
let _ = api::clipboard::start_monitor(app_handle.clone());

utils::commands::center_window_on_current_monitor(&main_window);
main_window.hide()?;
utils::commands::center_window_on_current_monitor(main_window.as_ref().unwrap());
main_window.as_ref().map(|w| w.hide()).unwrap_or(Ok(()))?;

let _ = app.track_event("app_started", None);

Expand Down

0 comments on commit 0a08ce9

Please sign in to comment.