mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 08:12:44 +10:00
* refactor: Rename StoredManifest to DropData Signed-off-by: quexeky <git@quexeky.dev> * fix: Downloads when resuming would truncate files which had not been finished Signed-off-by: quexeky <git@quexeky.dev> * chore: Didn't import debug macro Signed-off-by: quexeky <git@quexeky.dev> * fix: Download chunks with wrong indexes Migrated to using checksums as indexes instead Signed-off-by: quexeky <git@quexeky.dev> * feat: Resume download button Also added DBWrite and DBRead structs to make database management easier Signed-off-by: quexeky <git@quexeky.dev> * feat: Download resuming Signed-off-by: quexeky <git@quexeky.dev> * feat: Resume button and PartiallyInstalled status Signed-off-by: quexeky <git@quexeky.dev> * feat: Download validation Signed-off-by: quexeky <git@quexeky.dev> * chore: Ran cargo fix & cargo fmt Signed-off-by: quexeky <git@quexeky.dev> * fix: download validation, installs, etc * chore: version bump --------- Signed-off-by: quexeky <git@quexeky.dev> Co-authored-by: quexeky <git@quexeky.dev>
76 lines
2.1 KiB
Rust
76 lines
2.1 KiB
Rust
use crate::database::db::{borrow_db_checked, borrow_db_mut_checked};
|
|
use log::debug;
|
|
use tauri::AppHandle;
|
|
use tauri_plugin_autostart::ManagerExt;
|
|
|
|
pub fn toggle_autostart_logic(app: AppHandle, enabled: bool) -> Result<(), String> {
|
|
let manager = app.autolaunch();
|
|
if enabled {
|
|
manager.enable().map_err(|e| e.to_string())?;
|
|
debug!("enabled autostart");
|
|
} else {
|
|
manager.disable().map_err(|e| e.to_string())?;
|
|
debug!("eisabled autostart");
|
|
}
|
|
|
|
// Store the state in DB
|
|
let mut db_handle = borrow_db_mut_checked();
|
|
db_handle.settings.autostart = enabled;
|
|
drop(db_handle);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn get_autostart_enabled_logic(app: AppHandle) -> Result<bool, tauri_plugin_autostart::Error> {
|
|
// First check DB state
|
|
let db_handle = borrow_db_checked();
|
|
let db_state = db_handle.settings.autostart;
|
|
drop(db_handle);
|
|
|
|
// Get actual system state
|
|
let manager = app.autolaunch();
|
|
let system_state = manager.is_enabled()?;
|
|
|
|
// If they don't match, sync to DB state
|
|
if db_state != system_state {
|
|
if db_state {
|
|
manager.enable()?;
|
|
} else {
|
|
manager.disable()?;
|
|
}
|
|
}
|
|
|
|
Ok(db_state)
|
|
}
|
|
|
|
// New function to sync state on startup
|
|
pub fn sync_autostart_on_startup(app: &AppHandle) -> Result<(), String> {
|
|
let db_handle = borrow_db_checked();
|
|
let should_be_enabled = db_handle.settings.autostart;
|
|
drop(db_handle);
|
|
|
|
let manager = app.autolaunch();
|
|
let current_state = manager.is_enabled().map_err(|e| e.to_string())?;
|
|
|
|
if current_state != should_be_enabled {
|
|
if should_be_enabled {
|
|
manager.enable().map_err(|e| e.to_string())?;
|
|
debug!("synced autostart: enabled");
|
|
} else {
|
|
manager.disable().map_err(|e| e.to_string())?;
|
|
debug!("synced autostart: disabled");
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
#[tauri::command]
|
|
pub fn toggle_autostart(app: AppHandle, enabled: bool) -> Result<(), String> {
|
|
toggle_autostart_logic(app, enabled)
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn get_autostart_enabled(app: AppHandle) -> Result<bool, tauri_plugin_autostart::Error> {
|
|
get_autostart_enabled_logic(app)
|
|
}
|