diff --git a/VERSION b/VERSION index 6048310..3df20f5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.64 +0.0.65 diff --git a/src/relay_fetch.c b/src/relay_fetch.c index 05557f3..25e323b 100644 --- a/src/relay_fetch.c +++ b/src/relay_fetch.c @@ -28,6 +28,10 @@ #define MAX_RELAYS 32 /* Relay query timeout in seconds. */ + +/* Forward declaration — defined below. */ +static gboolean merge_settings_idle(gpointer data); + #define RELAY_TIMEOUT_SECONDS 15 /* Forward declaration — defined after relay_fetch_bootstrap. */ @@ -120,11 +124,18 @@ int relay_fetch_bootstrap(const char *pubkey_hex, /* Store in SQLite first, then try to merge into local settings. * settings_sync_merge_from_nostr checks the d-tag and only * merges if it's the shared "user-settings" event (or the - * legacy "sovereign_browser" event, which is migrated). */ + * legacy "sovereign_browser" event, which is migrated). + * + * IMPORTANT: The merge calls settings_load() which writes to + * the global g_settings struct. This must run on the main + * thread to avoid a data race with the GTK main loop. */ if (db_store_event(results[i]) == 0) { stored++; } - settings_sync_merge_from_nostr(results[i]); + cJSON *event_copy = cJSON_Duplicate(results[i], 1); + if (event_copy) { + g_idle_add(merge_settings_idle, event_copy); + } } else { if (db_store_event(results[i]) == 0) { stored++; @@ -208,6 +219,19 @@ static gboolean avatar_refresh_idle(gpointer data) { return G_SOURCE_REMOVE; } +/* Idle callback to merge NIP-78 settings on the main thread. + * settings_sync_merge_from_nostr calls settings_load() which writes to + * the global g_settings struct, so it must run on the GTK main thread + * to avoid data races with the main loop. Takes ownership of event_cjson. */ +static gboolean merge_settings_idle(gpointer data) { + cJSON *event = (cJSON *)data; + if (event) { + settings_sync_merge_from_nostr(event); + cJSON_Delete(event); + } + return FALSE; /* run once */ +} + /* ── Background thread ─────────────────────────────────────────────── */ gpointer relay_fetch_thread(gpointer data) { diff --git a/src/version.h b/src/version.h index 9341b2d..3aa975c 100644 --- a/src/version.h +++ b/src/version.h @@ -11,9 +11,9 @@ #ifndef SOVEREIGN_BROWSER_VERSION_H #define SOVEREIGN_BROWSER_VERSION_H -#define SB_VERSION "v0.0.64" +#define SB_VERSION "v0.0.65" #define SB_VERSION_MAJOR 0 #define SB_VERSION_MINOR 0 -#define SB_VERSION_PATCH 64 +#define SB_VERSION_PATCH 65 #endif /* SOVEREIGN_BROWSER_VERSION_H */