From c29cdb831b7586bb8421ca48e9e78a3a2183aca7 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Mon, 13 Apr 2026 02:55:36 +0800 Subject: feat: implement persistent cookie storage and migrate configuration files to ~/.ricochet directory --- src/core/browser.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/core/browser.cc') diff --git a/src/core/browser.cc b/src/core/browser.cc index e9f1fce..03c34bc 100644 --- a/src/core/browser.cc +++ b/src/core/browser.cc @@ -23,10 +23,12 @@ #include "ricochet/render/renderer.hh" #include "ricochet/tui/terminal.hh" #include +#include #include #include #include #include +#include namespace ricochet::core { @@ -47,6 +49,14 @@ struct HttpRequest namespace { +std::string get_config_path( const std::string& filename ) +{ + const char* home = std::getenv( "HOME" ); // NOLINT(concurrency-mt-unsafe) + const std::string dir = ( home != nullptr ) ? std::string( home ) + "/.ricochet" : ".ricochet"; + static_cast( mkdir( dir.c_str(), 0755 ) ); + return dir + "/" + filename; +} + std::string extract_title( const parser::DomNode& root_node ) { std::vector stack; @@ -93,7 +103,7 @@ void save_bookmark( const std::string& title, // NOLINT(bugprone-easily-swappabl if ( url == "ricochet://bookmarks" ) { return; } - std::ofstream file( "bookmarks.txt", std::ios::app ); + std::ofstream file( get_config_path( "bookmarks.txt" ), std::ios::app ); if ( !file.is_open() ) { return; } @@ -112,7 +122,7 @@ void save_bookmark( const std::string& title, // NOLINT(bugprone-easily-swappabl std::string generate_bookmarks_html() { - std::ifstream file( "bookmarks.txt" ); + std::ifstream file( get_config_path( "bookmarks.txt" ) ); std::string html = "My Bookmarks

Saved Bookmarks

    "; if ( !file.is_open() ) { html += "
  • No bookmarks found. Press 'b' on any page to add one!
  • "; -- cgit v1.2.3