From 2bc5ec777112282f9f15e011612373fdb5dadc4b Mon Sep 17 00:00:00 2001 From: Laan Tungir Date: Wed, 29 Jul 2026 10:41:13 -0400 Subject: [PATCH] v0.0.62 - Release: remember last save directory in download file chooser --- VERSION | 2 +- src/version.h | 4 ++-- src/web_context.c | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 72189de..7eb3665 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.61 +0.0.62 diff --git a/src/version.h b/src/version.h index d6135fb..086f59b 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.61" +#define SB_VERSION "v0.0.62" #define SB_VERSION_MAJOR 0 #define SB_VERSION_MINOR 0 -#define SB_VERSION_PATCH 61 +#define SB_VERSION_PATCH 62 #endif /* SOVEREIGN_BROWSER_VERSION_H */ diff --git a/src/web_context.c b/src/web_context.c index d2d5062..4bf2414 100644 --- a/src/web_context.c +++ b/src/web_context.c @@ -94,6 +94,13 @@ static void on_download_failed(WebKitDownload *dl, GError *err, gpointer user) { * dialog, set the destination, and return TRUE. Returning TRUE without * setting a destination is explicitly supported since 2.40 and pauses * the download until we set one (or cancel). */ + +/* Remember the directory the user last saved a download to, so the next + * save dialog opens in the same folder instead of the default. Owned by + * this module (g_free'd on teardown). NULL until the first successful + * save. */ +static char *g_last_save_dir = NULL; + static gboolean on_download_decide_destination(WebKitDownload *dl, const char *suggested, gpointer user) { @@ -115,6 +122,14 @@ static gboolean on_download_decide_destination(WebKitDownload *dl, if (parent) g_object_unref(parent); GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog); + + /* If the user saved a download before, open the dialog in that same + * directory. Otherwise GTK falls back to the current working + * directory / last-used folder for the application. */ + if (g_last_save_dir != NULL && g_last_save_dir[0] != '\0') { + gtk_file_chooser_set_current_folder(chooser, g_last_save_dir); + } + gtk_file_chooser_set_current_name(chooser, default_name); gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE); @@ -131,6 +146,16 @@ static gboolean on_download_decide_destination(WebKitDownload *dl, return TRUE; /* we handled it (by cancelling) */ } + /* Remember the directory the user chose for next time. */ + char *dir = g_path_get_dirname(path); + if (dir != NULL && dir[0] != '\0' && + (g_last_save_dir == NULL || + g_strcmp0(dir, g_last_save_dir) != 0)) { + g_free(g_last_save_dir); + g_last_save_dir = g_strdup(dir); + } + g_free(dir); + char *uri = g_filename_to_uri(path, NULL, NULL); g_free(path); if (uri == NULL) {