diff --git a/.gitignore b/.gitignore index cf1d164..f97e1d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /vendor/ /composer.lock -/db.sqlite \ No newline at end of file +/database.sqlite \ No newline at end of file diff --git a/README.md b/README.md index 4cffa55..320b68a 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,11 @@ At this moment project under development! * [x] Custom DNS resolver with memory cache, oriented to alt networks like [Yggdrasil](https://github.com/yggdrasil-network/yggdrasil-go) * [x] Flexible settings in `config.json`, then UI * [x] Native GTK environment, no custom colors until you change it in `css` -* [x] Page tabs -* [ ] Local pages history snaps to make it accessible even offline +* [x] Multi-tabs +* [ ] Navigation history * [ ] Bookmarks * [ ] Certificate features +* [ ] Local snaps to make resources accessible even offline * [ ] `Gemfeed` reader * [ ] Search engine integrations, probably [Yo!](https://github.com/YGGverse/Yo/tree/gemini) Search by default * [ ] Machine translations (e.g. [Lingva](https://github.com/thedaviddelta/lingva-translate) API) diff --git a/config.json b/config.json index e913902..8ce3fef 100644 --- a/config.json +++ b/config.json @@ -2,6 +2,12 @@ "app": { "theme":"Default", + "database": + { + "name":"database.sqlite", + "username":null, + "password":null + }, "header": { "enabled":true, @@ -123,6 +129,10 @@ } } } + }, + "history": + { + "enabled":true } } } diff --git a/src/Entity/App.php b/src/Entity/App.php index 92f07ba..8ea4ece 100644 --- a/src/Entity/App.php +++ b/src/Entity/App.php @@ -6,6 +6,8 @@ namespace Yggverse\Yoda\Entity; class App { + public \Yggverse\Yoda\Model\Database $database; + public \GtkWindow $window; public \GtkHeaderBar $header; public \GtkNotebook $tabs; @@ -17,6 +19,13 @@ class App // Init config $this->config = \Yggverse\Yoda\Model\File::getConfig()->app; // @TODO + // Init database + $this->database = new \Yggverse\Yoda\Model\Database( + $this->config->database->name, + $this->config->database->username, + $this->config->database->password + ); + // Init theme $css = new \GtkCssProvider(); diff --git a/src/Model/Database.php b/src/Model/Database.php index 6e64cda..40409cb 100644 --- a/src/Model/Database.php +++ b/src/Model/Database.php @@ -6,6 +6,52 @@ namespace Yggverse\Yoda\Model; class Database { - public function __construct() - {} + public \PDO $database; + + public function __construct( + string $database, + ?string $username = null, + ?string $password = null + ) { + try + { + $this->database = new \PDO( + sprintf( + 'sqlite:%s', + $database + ), + $username, + $password + ); + + $this->database->setAttribute( + \PDO::ATTR_ERRMODE, + \PDO::ERRMODE_EXCEPTION + ); + + $this->database->setAttribute( + \PDO::ATTR_DEFAULT_FETCH_MODE, + \PDO::FETCH_OBJ + ); + + $this->database->query(' + CREATE TABLE IF NOT EXISTS "history" + ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "time" INTEGER NOT NULL, + "address" VARCHAR(1024) NOT NULL + ) + '); + } + + catch (\PDOException $exception) + { + exit( + print_r( + $exception->getMessage(), + true + ) + ); + } + } } \ No newline at end of file