mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
init config model
This commit is contained in:
parent
cba3676d73
commit
789db97319
6 changed files with 247 additions and 230 deletions
395
config.json
395
config.json
|
|
@ -1,229 +1,226 @@
|
||||||
{
|
{
|
||||||
"app":
|
"name":"Yoda",
|
||||||
|
"theme":"Default",
|
||||||
|
"database":
|
||||||
{
|
{
|
||||||
"name":"Yoda",
|
"name":"database.sqlite",
|
||||||
"theme":"Default",
|
"username":null,
|
||||||
"database":
|
"password":null
|
||||||
|
},
|
||||||
|
"header":
|
||||||
|
{
|
||||||
|
"enabled":true,
|
||||||
|
"button":
|
||||||
{
|
{
|
||||||
"name":"database.sqlite",
|
"close":true
|
||||||
"username":null,
|
}
|
||||||
"password":null
|
},
|
||||||
},
|
"width":640,
|
||||||
"header":
|
"height":480,
|
||||||
|
"tab":
|
||||||
|
{
|
||||||
|
"page":
|
||||||
{
|
{
|
||||||
"enabled":true,
|
"title":
|
||||||
"button":
|
|
||||||
{
|
{
|
||||||
"close":true
|
"default":"New page",
|
||||||
}
|
"width":
|
||||||
},
|
{
|
||||||
"width":640,
|
"chars":32
|
||||||
"height":480,
|
},
|
||||||
"tab":
|
"ellipsize":
|
||||||
{
|
{
|
||||||
"page":
|
"mode":3
|
||||||
|
},
|
||||||
|
"postfix":
|
||||||
|
{
|
||||||
|
"hostname":true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"redirect":
|
||||||
{
|
{
|
||||||
"title":
|
"follow":
|
||||||
{
|
|
||||||
"default":"New page",
|
|
||||||
"width":
|
|
||||||
{
|
|
||||||
"chars":32
|
|
||||||
},
|
|
||||||
"ellipsize":
|
|
||||||
{
|
|
||||||
"mode":3
|
|
||||||
},
|
|
||||||
"postfix":
|
|
||||||
{
|
|
||||||
"hostname":true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"redirect":
|
|
||||||
{
|
|
||||||
"follow":
|
|
||||||
{
|
|
||||||
"enabled":true,
|
|
||||||
"max":5,
|
|
||||||
"code":
|
|
||||||
[
|
|
||||||
30,
|
|
||||||
31
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"resolver":
|
|
||||||
{
|
{
|
||||||
"enabled":true,
|
"enabled":true,
|
||||||
"request":
|
"max":5,
|
||||||
{
|
"code":
|
||||||
"timeout":1,
|
[
|
||||||
"host":
|
30,
|
||||||
[
|
31
|
||||||
"1.1.1.1",
|
]
|
||||||
"8.8.8.8"
|
}
|
||||||
],
|
},
|
||||||
"record":
|
"resolver":
|
||||||
[
|
{
|
||||||
"A",
|
"enabled":true,
|
||||||
"AAAA"
|
"request":
|
||||||
]
|
|
||||||
},
|
|
||||||
"result":
|
|
||||||
{
|
|
||||||
"shuffle":false,
|
|
||||||
"cache":
|
|
||||||
{
|
|
||||||
"timeout":3600
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"history":
|
|
||||||
{
|
{
|
||||||
"memory":
|
"timeout":1,
|
||||||
{
|
"host":
|
||||||
"enabled":true
|
[
|
||||||
},
|
"1.1.1.1",
|
||||||
"database":
|
"8.8.8.8"
|
||||||
{
|
],
|
||||||
"enabled":true,
|
"record":
|
||||||
"mode":
|
[
|
||||||
{
|
"A",
|
||||||
"renew":true
|
"AAAA"
|
||||||
}
|
]
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"progressbar":
|
"result":
|
||||||
{
|
{
|
||||||
"visible":true
|
"shuffle":false,
|
||||||
},
|
"cache":
|
||||||
"header":
|
|
||||||
{
|
|
||||||
"margin":8,
|
|
||||||
"button":
|
|
||||||
{
|
{
|
||||||
"home":
|
"timeout":3600
|
||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"history":
|
"history":
|
||||||
{
|
{
|
||||||
"enabled":true,
|
"memory":
|
||||||
"label":"History",
|
|
||||||
"clean":
|
|
||||||
{
|
{
|
||||||
"timeout":null
|
"enabled":true
|
||||||
},
|
},
|
||||||
"time":
|
"database":
|
||||||
{
|
{
|
||||||
"format":"c"
|
"enabled":true,
|
||||||
},
|
"mode":
|
||||||
"header":
|
|
||||||
{
|
|
||||||
"margin":8,
|
|
||||||
"button":
|
|
||||||
{
|
{
|
||||||
"open":
|
"renew":true
|
||||||
{
|
}
|
||||||
"visible":true,
|
}
|
||||||
"label":"Open"
|
},
|
||||||
},
|
"progressbar":
|
||||||
"delete":
|
{
|
||||||
{
|
"visible":true
|
||||||
"visible":true,
|
},
|
||||||
"label":"Delete"
|
"header":
|
||||||
},
|
{
|
||||||
"search":
|
"margin":8,
|
||||||
{
|
"button":
|
||||||
"visible":true,
|
{
|
||||||
"label":"Search"
|
"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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace Yggverse\Yoda\Entity;
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
|
public \Yggverse\Yoda\Model\Config $config;
|
||||||
public \Yggverse\Yoda\Model\Database $database;
|
public \Yggverse\Yoda\Model\Database $database;
|
||||||
|
|
||||||
public \Yggverse\Yoda\Entity\Tab\History $history;
|
public \Yggverse\Yoda\Entity\Tab\History $history;
|
||||||
|
|
@ -14,12 +15,10 @@ class App
|
||||||
public \GtkHeaderBar $header;
|
public \GtkHeaderBar $header;
|
||||||
public \GtkNotebook $tabs;
|
public \GtkNotebook $tabs;
|
||||||
|
|
||||||
public object $config;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
// Init config
|
// Init config
|
||||||
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app; // @TODO
|
$this->config = new \Yggverse\Yoda\Model\Config;
|
||||||
|
|
||||||
// Init database
|
// Init database
|
||||||
$this->database = new \Yggverse\Yoda\Model\Database(
|
$this->database = new \Yggverse\Yoda\Model\Database(
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ class History
|
||||||
// Init app
|
// Init app
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
|
|
||||||
// Init config
|
// Init config namespace
|
||||||
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app->tab->history;
|
$this->config = $app->config->tab->history;
|
||||||
|
|
||||||
// Cleanup expired history
|
// Cleanup expired history
|
||||||
if ($this->config->clean->timeout)
|
if ($this->config->clean->timeout)
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ class Page
|
||||||
// Init app
|
// Init app
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
|
|
||||||
// Init config
|
// Init config namespace
|
||||||
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app->tab->page;
|
$this->config = $app->config->tab->page;
|
||||||
|
|
||||||
// Init DNS memory
|
// Init DNS memory
|
||||||
$this->dns = new \Yggverse\Yoda\Model\Memory;
|
$this->dns = new \Yggverse\Yoda\Model\Memory;
|
||||||
|
|
|
||||||
45
src/Model/Config.php
Normal file
45
src/Model/Config.php
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Model;
|
||||||
|
|
||||||
|
class Config
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
?string $filename = null
|
||||||
|
) {
|
||||||
|
if (empty($filename))
|
||||||
|
{
|
||||||
|
$filename = __DIR__ .
|
||||||
|
DIRECTORY_SEPARATOR . '..' .
|
||||||
|
DIRECTORY_SEPARATOR . '..' .
|
||||||
|
DIRECTORY_SEPARATOR . 'config.json';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($filename))
|
||||||
|
{
|
||||||
|
throw new \Exception; // @TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_readable($filename))
|
||||||
|
{
|
||||||
|
throw new \Exception; // @TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$data = file_get_contents($filename))
|
||||||
|
{
|
||||||
|
throw new \Exception; // @TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$config = @json_decode($data))
|
||||||
|
{
|
||||||
|
throw new \Exception; // @TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($config as $key => $value)
|
||||||
|
{
|
||||||
|
$this->{$key} = $value; // @TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,30 +6,6 @@ namespace Yggverse\Yoda\Model;
|
||||||
|
|
||||||
class File
|
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
|
public static function getTheme(string $name): string
|
||||||
{
|
{
|
||||||
$filename = __DIR__ .
|
$filename = __DIR__ .
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue