mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-22 05:34:04 +02:00
restructure
This commit is contained in:
parent
96f9f475df
commit
266b6ff3e1
12 changed files with 158 additions and 103 deletions
|
@ -3,46 +3,13 @@
|
|||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
mod clipboard;
|
||||
mod database;
|
||||
mod hotkeys;
|
||||
mod tray;
|
||||
mod updater;
|
||||
mod api;
|
||||
mod utils;
|
||||
|
||||
use tauri::Manager;
|
||||
use tauri::PhysicalPosition;
|
||||
use tauri::{Manager, Listener};
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_prevent_default::Flags;
|
||||
|
||||
pub fn center_window_on_current_monitor(window: &tauri::WebviewWindow) {
|
||||
if let Some(monitor) = window.available_monitors().unwrap().iter().find(|m| {
|
||||
let primary_monitor = window
|
||||
.primary_monitor()
|
||||
.unwrap()
|
||||
.expect("Failed to get primary monitor");
|
||||
let mouse_position = primary_monitor.position();
|
||||
let monitor_position = m.position();
|
||||
let monitor_size = m.size();
|
||||
mouse_position.x >= monitor_position.x
|
||||
&& mouse_position.x < monitor_position.x + monitor_size.width as i32
|
||||
&& mouse_position.y >= monitor_position.y
|
||||
&& mouse_position.y < monitor_position.y + monitor_size.height as i32
|
||||
}) {
|
||||
let monitor_size = monitor.size();
|
||||
let window_size = window.outer_size().unwrap();
|
||||
|
||||
let x = (monitor_size.width as i32 - window_size.width as i32) / 2;
|
||||
let y = (monitor_size.height as i32 - window_size.height as i32) / 2;
|
||||
|
||||
window
|
||||
.set_position(PhysicalPosition::new(
|
||||
monitor.position().x + x,
|
||||
monitor.position().y + y,
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_clipboard::init())
|
||||
|
@ -54,6 +21,11 @@ fn main() {
|
|||
MacosLauncher::LaunchAgent,
|
||||
Some(vec![]),
|
||||
))
|
||||
.plugin(api::updater::init())
|
||||
.plugin(api::database::init())
|
||||
.plugin(api::tray::init())
|
||||
.plugin(api::hotkeys::init())
|
||||
.plugin(api::clipboard::init())
|
||||
.plugin(
|
||||
tauri_plugin_prevent_default::Builder::new()
|
||||
.with_flags(Flags::all().difference(Flags::CONTEXT_MENU))
|
||||
|
@ -61,51 +33,43 @@ fn main() {
|
|||
)
|
||||
.setup(|app| {
|
||||
let app_handle = app.handle().clone();
|
||||
|
||||
hotkeys::setup(app_handle.clone());
|
||||
tray::setup(app)?;
|
||||
database::setup(app)?;
|
||||
clipboard::setup(app.handle());
|
||||
let _ = clipboard::start_monitor(app_handle.clone());
|
||||
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
center_window_on_current_monitor(&window);
|
||||
window.hide().unwrap();
|
||||
}
|
||||
|
||||
// #[cfg(dev)]
|
||||
// {
|
||||
// let window = app.get_webview_window("main").unwrap();
|
||||
// window.open_devtools();
|
||||
// window.close_devtools();
|
||||
// }
|
||||
|
||||
|
||||
let app_data_dir = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.expect("Failed to get app data directory");
|
||||
clipboard::set_app_data_dir(app_data_dir);
|
||||
api::clipboard::set_app_data_dir(app_data_dir);
|
||||
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
utils::commands::center_window_on_current_monitor(&window);
|
||||
window.hide().unwrap();
|
||||
}
|
||||
|
||||
let update_handle = app_handle.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
updater::check_for_updates(app_handle).await;
|
||||
api::updater::check_for_updates(update_handle).await;
|
||||
});
|
||||
|
||||
let monitor_handle = app_handle.clone();
|
||||
app_handle.listen("database_initialized", move |_| {
|
||||
let _ = api::clipboard::start_monitor(monitor_handle.clone());
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|app, event| match event {
|
||||
.on_window_event(|app, event| {
|
||||
#[cfg(not(dev))]
|
||||
tauri::WindowEvent::Focused(false) => {
|
||||
if let WindowEvent::Focused(false) = event {
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
window.hide().unwrap();
|
||||
let _ = window.hide();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
clipboard::simulate_paste,
|
||||
clipboard::get_image_path,
|
||||
clipboard::read_image
|
||||
api::clipboard::simulate_paste,
|
||||
api::clipboard::get_image_path,
|
||||
api::clipboard::read_image
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue