diff --git a/config.json b/config.json index 512ea50a..4e671a2a 100644 --- a/config.json +++ b/config.json @@ -1,229 +1,226 @@ { - "app": + "name":"Yoda", + "theme":"Default", + "database": { - "name":"Yoda", - "theme":"Default", - "database": + "name":"database.sqlite", + "username":null, + "password":null + }, + "header": + { + "enabled":true, + "button": { - "name":"database.sqlite", - "username":null, - "password":null - }, - "header": + "close":true + } + }, + "width":640, + "height":480, + "tab": + { + "page": { - "enabled":true, - "button": + "title": { - "close":true - } - }, - "width":640, - "height":480, - "tab": - { - "page": + "default":"New page", + "width": + { + "chars":32 + }, + "ellipsize": + { + "mode":3 + }, + "postfix": + { + "hostname":true + } + }, + "redirect": { - "title": - { - "default":"New page", - "width": - { - "chars":32 - }, - "ellipsize": - { - "mode":3 - }, - "postfix": - { - "hostname":true - } - }, - "redirect": - { - "follow": - { - "enabled":true, - "max":5, - "code": - [ - 30, - 31 - ] - } - }, - "resolver": + "follow": { "enabled":true, - "request": - { - "timeout":1, - "host": - [ - "1.1.1.1", - "8.8.8.8" - ], - "record": - [ - "A", - "AAAA" - ] - }, - "result": - { - "shuffle":false, - "cache": - { - "timeout":3600 - } - } - }, - "history": + "max":5, + "code": + [ + 30, + 31 + ] + } + }, + "resolver": + { + "enabled":true, + "request": { - "memory": - { - "enabled":true - }, - "database": - { - "enabled":true, - "mode": - { - "renew":true - } - } + "timeout":1, + "host": + [ + "1.1.1.1", + "8.8.8.8" + ], + "record": + [ + "A", + "AAAA" + ] }, - "progressbar": + "result": { - "visible":true - }, - "header": - { - "margin":8, - "button": + "shuffle":false, + "cache": { - "home": - { - "visible":true, - "label":"Home", - "url":"yoda://welcome" - }, - "back": - { - "visible":true, - "label":"Back" - }, - "forward": - { - "visible":true, - "label":"Forward" - }, - "base": - { - "visible":true, - "label":"Base" - }, - "go": - { - "visible":true, - "label":"Go" - } - }, - "entry": - { - "request": - { - "placeholder":"URL or any search term...", - "length": - { - "max":1024 - }, - "autocomplete": - { - "enabled":true, - "inline": - { - "completion":true, - "selection":true - }, - "key": - { - "length":1 - }, - "ignore": - { - "keycode": - [ - 111, - 116 - ] - }, - "result": - { - "limit":15 - } - } - } - } - }, - "body": - { - "margin":8 - }, - "footer": - { - "margin":8, - "status": - { - "open": - { - "complete":"{REQUEST_BASE_URL} | {TIME_C} | {RESPONSE_META} | {RESPONSE_LENGTH} bytes | {RESPONSE_SECONDS} seconds" - } + "timeout":3600 } } }, "history": { - "enabled":true, - "label":"History", - "clean": + "memory": { - "timeout":null + "enabled":true }, - "time": + "database": { - "format":"c" - }, - "header": - { - "margin":8, - "button": + "enabled":true, + "mode": { - "open": - { - "visible":true, - "label":"Open" - }, - "delete": - { - "visible":true, - "label":"Delete" - }, - "search": - { - "visible":true, - "label":"Search" - } + "renew":true + } + } + }, + "progressbar": + { + "visible":true + }, + "header": + { + "margin":8, + "button": + { + "home": + { + "visible":true, + "label":"Home", + "url":"yoda://welcome" }, - "filter": + "back": { - "placeholder":"Search in history..." + "visible":true, + "label":"Back" + }, + "forward": + { + "visible":true, + "label":"Forward" + }, + "base": + { + "visible":true, + "label":"Base" + }, + "go": + { + "visible":true, + "label":"Go" } }, - "body": + "entry": { - "margin":8 + "request": + { + "placeholder":"URL or any search term...", + "length": + { + "max":1024 + }, + "autocomplete": + { + "enabled":true, + "inline": + { + "completion":true, + "selection":true + }, + "key": + { + "length":1 + }, + "ignore": + { + "keycode": + [ + 111, + 116 + ] + }, + "result": + { + "limit":15 + } + } + } } + }, + "body": + { + "margin":8 + }, + "footer": + { + "margin":8, + "status": + { + "open": + { + "complete":"{REQUEST_BASE_URL} | {TIME_C} | {RESPONSE_META} | {RESPONSE_LENGTH} bytes | {RESPONSE_SECONDS} seconds" + } + } + } + }, + "history": + { + "enabled":true, + "label":"History", + "clean": + { + "timeout":null + }, + "time": + { + "format":"c" + }, + "header": + { + "margin":8, + "button": + { + "open": + { + "visible":true, + "label":"Open" + }, + "delete": + { + "visible":true, + "label":"Delete" + }, + "search": + { + "visible":true, + "label":"Search" + } + }, + "filter": + { + "placeholder":"Search in history..." + } + }, + "body": + { + "margin":8 } } } diff --git a/src/Entity/App.php b/src/Entity/App.php index e671e770..652107db 100644 --- a/src/Entity/App.php +++ b/src/Entity/App.php @@ -6,6 +6,7 @@ namespace Yggverse\Yoda\Entity; class App { + public \Yggverse\Yoda\Model\Config $config; public \Yggverse\Yoda\Model\Database $database; public \Yggverse\Yoda\Entity\Tab\History $history; @@ -14,12 +15,10 @@ class App public \GtkHeaderBar $header; public \GtkNotebook $tabs; - public object $config; - public function __construct() { // Init config - $this->config = \Yggverse\Yoda\Model\File::getConfig()->app; // @TODO + $this->config = new \Yggverse\Yoda\Model\Config; // Init database $this->database = new \Yggverse\Yoda\Model\Database( diff --git a/src/Entity/Tab/History.php b/src/Entity/Tab/History.php index 0528bebe..486ed063 100644 --- a/src/Entity/Tab/History.php +++ b/src/Entity/Tab/History.php @@ -30,8 +30,8 @@ class History // Init app $this->app = $app; - // Init config - $this->config = \Yggverse\Yoda\Model\File::getConfig()->app->tab->history; + // Init config namespace + $this->config = $app->config->tab->history; // Cleanup expired history if ($this->config->clean->timeout) diff --git a/src/Entity/Tab/Page.php b/src/Entity/Tab/Page.php index 721f2cc7..e6a06f2e 100644 --- a/src/Entity/Tab/Page.php +++ b/src/Entity/Tab/Page.php @@ -43,8 +43,8 @@ class Page // Init app $this->app = $app; - // Init config - $this->config = \Yggverse\Yoda\Model\File::getConfig()->app->tab->page; + // Init config namespace + $this->config = $app->config->tab->page; // Init DNS memory $this->dns = new \Yggverse\Yoda\Model\Memory; diff --git a/src/Model/Config.php b/src/Model/Config.php new file mode 100644 index 00000000..c3d891e2 --- /dev/null +++ b/src/Model/Config.php @@ -0,0 +1,45 @@ + $value) + { + $this->{$key} = $value; // @TODO + } + } +} \ No newline at end of file diff --git a/src/Model/File.php b/src/Model/File.php index ca4055d3..2d7fdc7d 100644 --- a/src/Model/File.php +++ b/src/Model/File.php @@ -6,30 +6,6 @@ namespace Yggverse\Yoda\Model; class File { - public static function getConfig(): object - { - $filename = __DIR__ . - DIRECTORY_SEPARATOR . '..' . - DIRECTORY_SEPARATOR . '..' . - DIRECTORY_SEPARATOR . 'config.json'; - - if (file_exists($filename) && is_readable($filename)) - { - $result = json_decode( - file_get_contents( - $filename - ) - ); - } - - if (empty($result)) - { - throw new \Exception(); // @TODO - } - - return $result; - } - public static function getTheme(string $name): string { $filename = __DIR__ .