Hold config state from the generated schedule; avoids desync issues when changing configs and re-exporting data without generating new schedule
This commit is contained in:
@@ -22,6 +22,7 @@ pub mod workload;
|
||||
struct AppState {
|
||||
schedule: Mutex<MonthlySchedule>,
|
||||
tracker: Mutex<WorkloadTracker>,
|
||||
config: Mutex<UserConfig>,
|
||||
}
|
||||
|
||||
/// argument to this must be the rota state including all
|
||||
@@ -34,8 +35,8 @@ fn generate(
|
||||
) -> Result<MonthlySchedule, String> {
|
||||
let mut schedule = MonthlySchedule::new();
|
||||
let mut tracker = WorkloadTracker::default();
|
||||
let scheduler =
|
||||
Scheduler::new_with_config(UserConfig::try_from(config).map_err(|e| e.to_string())?);
|
||||
let config = UserConfig::try_from(config).map_err(|e| e.to_string())?;
|
||||
let scheduler = Scheduler::new_with_config(config.clone());
|
||||
|
||||
scheduler
|
||||
.run(&mut schedule, &mut tracker)
|
||||
@@ -49,21 +50,20 @@ fn generate(
|
||||
|
||||
let mut internal_schedule = state.schedule.lock().unwrap();
|
||||
let mut internal_tracker = state.tracker.lock().unwrap();
|
||||
let mut internal_config = state.config.lock().unwrap();
|
||||
|
||||
*internal_schedule = schedule.clone();
|
||||
*internal_tracker = tracker.clone();
|
||||
*internal_config = config.clone();
|
||||
|
||||
Ok(schedule)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn export(config: UserConfigDTO, state: tauri::State<'_, AppState>) -> Result<(), String> {
|
||||
let config = UserConfig::try_from(config)
|
||||
.inspect_err(|e| error!("{e}"))
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
fn export(state: tauri::State<'_, AppState>) -> Result<(), String> {
|
||||
let schedule = state.schedule.lock().unwrap();
|
||||
let tracker = state.tracker.lock().unwrap();
|
||||
let config = state.config.lock().unwrap();
|
||||
|
||||
schedule
|
||||
.export(FileType::Docx, &config, &tracker)
|
||||
@@ -88,6 +88,7 @@ pub fn run() {
|
||||
.manage(AppState {
|
||||
schedule: Mutex::new(MonthlySchedule::new()),
|
||||
tracker: Mutex::new(WorkloadTracker::default()),
|
||||
config: Mutex::new(UserConfig::default()),
|
||||
})
|
||||
.plugin(
|
||||
tauri_plugin_log::Builder::new()
|
||||
|
||||
Reference in New Issue
Block a user