feat: app 2.0
Some checks failed
FanslySync Build & Test / FanslySync Test Runner (push) Has been cancelled
Some checks failed
FanslySync Build & Test / FanslySync Test Runner (push) Has been cancelled
This commit is contained in:
@ -10,10 +10,15 @@ use std::io;
|
||||
|
||||
use commands::config::{get_config, init_config, save_config};
|
||||
use commands::fansly::{
|
||||
fansly_check_sync_token, fansly_get_me, fansly_set_token, fansly_sync,
|
||||
fansly_upload_auto_sync_data, fansly_get_sync_status
|
||||
fansly_check_sync_token, fansly_get_me, fansly_get_sync_status, fansly_set_token, fansly_sync,
|
||||
fansly_upload_auto_sync_data,
|
||||
};
|
||||
use commands::utils::quit;
|
||||
use tauri::menu::Menu;
|
||||
use tauri::menu::MenuItem;
|
||||
use tauri::tray::TrayIconBuilder;
|
||||
use tauri::AppHandle;
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_log::{Target, TargetKind};
|
||||
|
||||
@ -32,9 +37,55 @@ fn get_log_path() -> io::Result<String> {
|
||||
Ok(config_dir.to_string_lossy().to_string())
|
||||
}
|
||||
|
||||
fn handle_menu(app: &tauri::AppHandle, event: &tauri::menu::MenuEvent) {
|
||||
match event.id().as_ref() {
|
||||
"quit" => {
|
||||
app.exit(0);
|
||||
}
|
||||
"show_window" => {
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
// Setup menu items for the tray
|
||||
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
||||
let show_window_i =
|
||||
MenuItem::with_id(app, "show_window", "Show Window", true, None::<&str>)?;
|
||||
|
||||
// Create our Menu and add the items to it
|
||||
let menu = Menu::with_items(app, &[&quit_i, &show_window_i])?;
|
||||
|
||||
// Create our Tray using TrayIconBuilder and add the menu to it
|
||||
TrayIconBuilder::new()
|
||||
.icon(app.default_window_icon().unwrap().clone())
|
||||
.title("FanslySync")
|
||||
.tooltip("FanslySync")
|
||||
.menu(&menu)
|
||||
.show_menu_on_left_click(true)
|
||||
.on_menu_event(|app: &AppHandle, event: tauri::menu::MenuEvent| {
|
||||
handle_menu(app, &event)
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|app, event| {
|
||||
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.hide();
|
||||
api.prevent_close();
|
||||
}
|
||||
}
|
||||
})
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
MacosLauncher::LaunchAgent,
|
||||
None,
|
||||
|
Reference in New Issue
Block a user