fix: enforce only one instance of the app
All checks were successful
FanslySync Build & Test / FanslySync Test Runner (push) Successful in 11m51s

This commit is contained in:
Sticks 2025-04-23 20:20:39 -04:00
parent f4565ab580
commit d4d9d2ebce
5 changed files with 28 additions and 2 deletions

16
src-tauri/Cargo.lock generated
View File

@ -108,6 +108,7 @@ dependencies = [
"tauri-plugin-log", "tauri-plugin-log",
"tauri-plugin-notification", "tauri-plugin-notification",
"tauri-plugin-os", "tauri-plugin-os",
"tauri-plugin-single-instance",
"tauri-plugin-updater", "tauri-plugin-updater",
"thiserror 2.0.12", "thiserror 2.0.12",
"tokio", "tokio",
@ -4846,6 +4847,21 @@ dependencies = [
"thiserror 2.0.12", "thiserror 2.0.12",
] ]
[[package]]
name = "tauri-plugin-single-instance"
version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1320af4d866a7fb5f5721d299d14d0dd9e4e6bc0359ff3e263124a2bf6814efa"
dependencies = [
"serde",
"serde_json",
"tauri",
"thiserror 2.0.12",
"tracing",
"windows-sys 0.59.0",
"zbus",
]
[[package]] [[package]]
name = "tauri-plugin-updater" name = "tauri-plugin-updater"
version = "2.7.0" version = "2.7.0"

View File

@ -40,3 +40,4 @@ custom-protocol = ["tauri/custom-protocol"]
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-autostart = "2.3.0" tauri-plugin-autostart = "2.3.0"
tauri-plugin-single-instance = "2"

View File

@ -1,3 +1,4 @@
use crate::handlers::fansly::{SyncProgress, PROGRESS};
use crate::{ use crate::{
handlers::fansly::Fansly, handlers::fansly::Fansly,
structs::{FanslyAccountResponse, FanslyBaseResponse, SyncDataResponse}, structs::{FanslyAccountResponse, FanslyBaseResponse, SyncDataResponse},
@ -5,7 +6,6 @@ use crate::{
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde_json::Value; use serde_json::Value;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use crate::handlers::fansly::{SyncProgress, PROGRESS};
lazy_static! { lazy_static! {
static ref FANSLY: Mutex<Fansly> = Mutex::new(Fansly::new(None)); static ref FANSLY: Mutex<Fansly> = Mutex::new(Fansly::new(None));

View File

@ -405,7 +405,6 @@ impl Fansly {
response.response.len() response.response.len()
); );
// Collect followers // Collect followers
for follower in response.response.clone() { for follower in response.response.clone() {
followers.push(follower.follower_id); followers.push(follower.follower_id);

View File

@ -20,6 +20,8 @@ use tauri::tray::TrayIconBuilder;
use tauri::AppHandle; use tauri::AppHandle;
use tauri::Manager; use tauri::Manager;
use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_dialog::DialogExt;
use tauri_plugin_dialog::MessageDialogKind;
use tauri_plugin_log::{Target, TargetKind}; use tauri_plugin_log::{Target, TargetKind};
fn get_log_path() -> io::Result<String> { fn get_log_path() -> io::Result<String> {
@ -108,6 +110,14 @@ async fn main() {
.max_file_size(1024 * 1024 * 5) .max_file_size(1024 * 1024 * 5)
.build(), .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![ .invoke_handler(tauri::generate_handler![
init_config, init_config,
get_config, get_config,