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 "fs.h"
|
||||||
#include "wav_io.h"
|
#include "wav_io.h"
|
||||||
|
#include "dispatcher.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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 pthread_cond_t autosave_cond = PTHREAD_COND_INITIALIZER;
|
||||||
static volatile bool autosave_running = false;
|
static volatile bool autosave_running = false;
|
||||||
static volatile bool autosave_pending = false;
|
static volatile bool autosave_pending = false;
|
||||||
static AppState *g_state = NULL;
|
|
||||||
static time_t last_autosave_time = 0;
|
static time_t last_autosave_time = 0;
|
||||||
|
|
||||||
// Directory for autosave files
|
// 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
|
// Only autosave if at least 10 seconds have passed since last save
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
if (now - last_autosave_time >= 10) {
|
if (now - last_autosave_time >= 10) {
|
||||||
|
// Get current state from dispatcher
|
||||||
|
AppState state;
|
||||||
|
dispatcher_get_state(&state);
|
||||||
|
|
||||||
// Generate autosave filename with timestamp
|
// Generate autosave filename with timestamp
|
||||||
char filename[512];
|
char filename[512];
|
||||||
time_t t = time(NULL);
|
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);
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||||
|
|
||||||
// Save the project
|
// Save the project
|
||||||
fs_save_project(filename, g_state);
|
fs_save_project(filename, &state);
|
||||||
last_autosave_time = now;
|
last_autosave_time = now;
|
||||||
|
|
||||||
// Remove old autosaves (keep last 10)
|
// Remove old autosaves (keep last 10)
|
||||||
@@ -96,8 +100,7 @@ static void* autosave_thread_func(void *arg) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fs_init(AppState *state) {
|
void fs_init(void) {
|
||||||
g_state = state;
|
|
||||||
autosave_running = true;
|
autosave_running = true;
|
||||||
autosave_pending = false;
|
autosave_pending = false;
|
||||||
ensure_autosave_dir();
|
ensure_autosave_dir();
|
||||||
|
|||||||
2
fs.h
2
fs.h
@@ -4,7 +4,7 @@
|
|||||||
#include "dispatcher.h"
|
#include "dispatcher.h"
|
||||||
|
|
||||||
// Initialize the auto-save thread
|
// Initialize the auto-save thread
|
||||||
void fs_init(AppState *state);
|
void fs_init(void);
|
||||||
|
|
||||||
// Cleanup the auto-save thread
|
// Cleanup the auto-save thread
|
||||||
void fs_cleanup(void);
|
void fs_cleanup(void);
|
||||||
|
|||||||
2
main.c
2
main.c
@@ -130,7 +130,7 @@ int main(int argc, char *argv[]) {
|
|||||||
free(initial_state);
|
free(initial_state);
|
||||||
|
|
||||||
// Initialize filesystem module (auto-save thread)
|
// Initialize filesystem module (auto-save thread)
|
||||||
fs_init(initial_state);
|
fs_init();
|
||||||
|
|
||||||
// Initialize engine
|
// Initialize engine
|
||||||
if (engine_init(&engine, client_name, dispatch) != 0) {
|
if (engine_init(&engine, client_name, dispatch) != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user