refactor: remove global state from fs module and use dispatcher
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
11
fs.c
11
fs.c
@@ -1,5 +1,6 @@
|
||||
#include "fs.h"
|
||||
#include "wav_io.h"
|
||||
#include "dispatcher.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -19,7 +20,6 @@ static pthread_mutex_t autosave_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_cond_t autosave_cond = PTHREAD_COND_INITIALIZER;
|
||||
static volatile bool autosave_running = false;
|
||||
static volatile bool autosave_pending = false;
|
||||
static AppState *g_state = NULL;
|
||||
static time_t last_autosave_time = 0;
|
||||
|
||||
// Directory for autosave files
|
||||
@@ -56,6 +56,10 @@ static void* autosave_thread_func(void *arg) {
|
||||
// Only autosave if at least 10 seconds have passed since last save
|
||||
time_t now = time(NULL);
|
||||
if (now - last_autosave_time >= 10) {
|
||||
// Get current state from dispatcher
|
||||
AppState state;
|
||||
dispatcher_get_state(&state);
|
||||
|
||||
// Generate autosave filename with timestamp
|
||||
char filename[512];
|
||||
time_t t = time(NULL);
|
||||
@@ -66,7 +70,7 @@ static void* autosave_thread_func(void *arg) {
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
|
||||
// Save the project
|
||||
fs_save_project(filename, g_state);
|
||||
fs_save_project(filename, &state);
|
||||
last_autosave_time = now;
|
||||
|
||||
// Remove old autosaves (keep last 10)
|
||||
@@ -96,8 +100,7 @@ static void* autosave_thread_func(void *arg) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void fs_init(AppState *state) {
|
||||
g_state = state;
|
||||
void fs_init(void) {
|
||||
autosave_running = true;
|
||||
autosave_pending = false;
|
||||
ensure_autosave_dir();
|
||||
|
||||
2
fs.h
2
fs.h
@@ -4,7 +4,7 @@
|
||||
#include "dispatcher.h"
|
||||
|
||||
// Initialize the auto-save thread
|
||||
void fs_init(AppState *state);
|
||||
void fs_init(void);
|
||||
|
||||
// Cleanup the auto-save thread
|
||||
void fs_cleanup(void);
|
||||
|
||||
Reference in New Issue
Block a user