diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-04-13 02:55:36 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-04-13 02:55:36 +0800 |
| commit | c29cdb831b7586bb8421ca48e9e78a3a2183aca7 (patch) | |
| tree | 6e7dd7e14f53541ee885a20047c7d2290aaa8b7e /src/core | |
| parent | 24c36f5250e4c2b4232186ba3d17f949d70f5de2 (diff) | |
| download | rwebbrowser-c29cdb831b7586bb8421ca48e9e78a3a2183aca7.tar.gz rwebbrowser-c29cdb831b7586bb8421ca48e9e78a3a2183aca7.tar.xz | |
feat: implement persistent cookie storage and migrate configuration files to ~/.ricochet directory
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/browser.cc | 14 |
1 files changed, 12 insertions, 2 deletions
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 <cstddef> +#include <cstdlib> #include <exception> #include <fstream> #include <iostream> #include <ranges> +#include <sys/stat.h> 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<void>( mkdir( dir.c_str(), 0755 ) ); + return dir + "/" + filename; +} + std::string extract_title( const parser::DomNode& root_node ) { std::vector<const parser::DomNode*> 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 = "<html><head><title>My Bookmarks</title></head><body><h1>Saved Bookmarks</h1><ul>"; if ( !file.is_open() ) { html += "<li>No bookmarks found. Press 'b' on any page to add one!</li>"; |
