
Some checks failed
FanslySync Build & Test / FanslySync Test Runner (push) Failing after 23m7s
137 lines
4.6 KiB
Rust
137 lines
4.6 KiB
Rust
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
mod commands;
|
|
mod handlers;
|
|
mod structs;
|
|
|
|
use std::fs;
|
|
use std::io;
|
|
|
|
use commands::config::{get_config, init_config, save_config};
|
|
use commands::fansly::{
|
|
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_dialog::DialogExt;
|
|
use tauri_plugin_dialog::MessageDialogKind;
|
|
use tauri_plugin_log::{Target, TargetKind};
|
|
|
|
fn get_log_path() -> io::Result<String> {
|
|
let mut config_dir = dirs::config_dir().ok_or_else(|| {
|
|
io::Error::new(
|
|
io::ErrorKind::NotFound,
|
|
"Could not determine user's config directory",
|
|
)
|
|
})?;
|
|
config_dir.push("FanslySync");
|
|
fs::create_dir_all(&config_dir)?;
|
|
config_dir.push("runtime");
|
|
|
|
// Return the path as a 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()
|
|
.plugin(tauri_plugin_process::init())
|
|
.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,
|
|
))
|
|
.plugin(tauri_plugin_notification::init())
|
|
.plugin(tauri_plugin_clipboard_manager::init())
|
|
.plugin(tauri_plugin_dialog::init())
|
|
.plugin(tauri_plugin_os::init())
|
|
.plugin(tauri_plugin_updater::Builder::new().build())
|
|
.plugin(
|
|
tauri_plugin_log::Builder::new()
|
|
.targets([
|
|
Target::new(TargetKind::Stdout),
|
|
Target::new(TargetKind::LogDir {
|
|
file_name: Some(get_log_path().unwrap()),
|
|
}),
|
|
Target::new(TargetKind::Webview),
|
|
])
|
|
.rotation_strategy(tauri_plugin_log::RotationStrategy::KeepOne)
|
|
.max_file_size(1024 * 1024 * 5)
|
|
.build(),
|
|
)
|
|
.plugin(tauri_plugin_single_instance::init(|app,_args,_cwd| {
|
|
// Show a dialog if the app is already running
|
|
app.dialog()
|
|
.message("FanslySync is already running in the background. Please left click the tray icon -> Show Window to open the app.")
|
|
.title("FanslySync")
|
|
.kind(MessageDialogKind::Warning)
|
|
.blocking_show();
|
|
}))
|
|
.invoke_handler(tauri::generate_handler![
|
|
init_config,
|
|
get_config,
|
|
save_config,
|
|
quit,
|
|
fansly_set_token,
|
|
fansly_get_me,
|
|
fansly_sync,
|
|
fansly_upload_auto_sync_data,
|
|
fansly_check_sync_token,
|
|
fansly_get_sync_status
|
|
])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|