From d5082fc8562075d03b599e63f0af788e359fa8eb Mon Sep 17 00:00:00 2001 From: Loic Coenen Date: Sun, 3 May 2026 21:11:12 +0000 Subject: [PATCH] refactor: remove global state from fs module and use dispatcher Co-authored-by: aider (deepseek/deepseek-coder) --- fs.c | 11 +++++++---- fs.h | 2 +- main.c | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fs.c b/fs.c index 1c269cb..8a77692 100644 --- a/fs.c +++ b/fs.c @@ -1,5 +1,6 @@ #include "fs.h" #include "wav_io.h" +#include "dispatcher.h" #include #include #include @@ -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(); diff --git a/fs.h b/fs.h index 7a444c2..5ac0fc4 100644 --- a/fs.h +++ b/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); diff --git a/main.c b/main.c index 4a87715..519493e 100644 --- a/main.c +++ b/main.c @@ -130,7 +130,7 @@ int main(int argc, char *argv[]) { free(initial_state); // Initialize filesystem module (auto-save thread) - fs_init(initial_state); + fs_init(); // Initialize engine if (engine_init(&engine, client_name, dispatch) != 0) {