mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
initial commit
This commit is contained in:
parent
ad638650ac
commit
8c2cf42ca7
16 changed files with 541 additions and 0 deletions
145
src/Box/Main.php
Normal file
145
src/Box/Main.php
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Box;
|
||||
|
||||
class Main
|
||||
{
|
||||
public \GtkBox $box;
|
||||
|
||||
public \Yggverse\Yoda\Box\Menu $menu;
|
||||
public \Yggverse\Yoda\Box\Navigation $navigation;
|
||||
public \Yggverse\Yoda\Label\Content $content;
|
||||
public \Yggverse\Yoda\Label\Tray $tray;
|
||||
|
||||
public function __construct(
|
||||
string $name = 'boxMain'
|
||||
) {
|
||||
$this->box = new \GtkBox(
|
||||
\GtkOrientation::VERTICAL
|
||||
);
|
||||
|
||||
$this->box->set_name(
|
||||
$name
|
||||
);
|
||||
|
||||
// Init dependencies
|
||||
$this->menu = new \Yggverse\Yoda\Box\Menu();
|
||||
|
||||
$this->box->pack_start(
|
||||
$this->menu->box,
|
||||
false,
|
||||
true,
|
||||
0
|
||||
);
|
||||
|
||||
$this->navigation = new \Yggverse\Yoda\Box\Navigation();
|
||||
|
||||
$this->box->pack_start(
|
||||
$this->navigation->box,
|
||||
false,
|
||||
true,
|
||||
0
|
||||
);
|
||||
|
||||
$this->content = new \Yggverse\Yoda\Label\Content();
|
||||
|
||||
$scroll = new \GtkScrolledWindow();
|
||||
|
||||
$scroll->add(
|
||||
$this->content->label
|
||||
);
|
||||
|
||||
$this->box->pack_start(
|
||||
$scroll,
|
||||
true,
|
||||
true,
|
||||
10
|
||||
);
|
||||
|
||||
$this->tray = new \Yggverse\Yoda\Label\Tray();
|
||||
|
||||
$this->box->pack_start(
|
||||
$this->tray->label,
|
||||
false,
|
||||
true,
|
||||
0
|
||||
);
|
||||
|
||||
$this->navigation->address->entry->connect(
|
||||
'activate',
|
||||
function ($entry)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$host = null;
|
||||
|
||||
if ($config->resolver->enabled)
|
||||
{
|
||||
$resolve = new \Yggverse\Net\Resolve(
|
||||
$config->resolver->request->record,
|
||||
$config->resolver->request->host,
|
||||
$config->resolver->request->timeout,
|
||||
$config->resolver->result->shuffle
|
||||
);
|
||||
|
||||
$address = new \Yggverse\Net\Address(
|
||||
$entry->get_text()
|
||||
);
|
||||
|
||||
$resolved = $resolve->address(
|
||||
$address
|
||||
);
|
||||
|
||||
if ($resolved)
|
||||
{
|
||||
$host = $resolved->getHost(); // @TODO memory cache
|
||||
}
|
||||
}
|
||||
|
||||
$request = new \Yggverse\Gemini\Client\Request(
|
||||
$entry->get_text(),
|
||||
$host
|
||||
);
|
||||
|
||||
$this->tray->label->set_text(
|
||||
sprintf(
|
||||
'Open %s...',
|
||||
$entry->get_text()
|
||||
)
|
||||
);
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
$raw = $request->getResponse();
|
||||
|
||||
$end = microtime(true);
|
||||
|
||||
$response = new \Yggverse\Gemini\Client\Response(
|
||||
$raw
|
||||
);
|
||||
|
||||
$this->content->label->set_markup(
|
||||
$response->getBody()
|
||||
);
|
||||
|
||||
$this->tray->label->set_text(
|
||||
sprintf(
|
||||
'%s | %s | %d bytes | %s seconds',
|
||||
date('c'),
|
||||
$response->getMeta() ? $response->getMeta() : $response->getCode(),
|
||||
number_format(
|
||||
mb_strlen(
|
||||
$raw
|
||||
)
|
||||
),
|
||||
round(
|
||||
$end - $start, 2
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
30
src/Box/Menu.php
Normal file
30
src/Box/Menu.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Box;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public \GtkBox $box;
|
||||
|
||||
public \Yggverse\Yoda\Menu\Bar\Main $main;
|
||||
|
||||
public function __construct(
|
||||
string $name = 'boxMenu'
|
||||
) {
|
||||
$this->box = new \GtkBox(
|
||||
\GtkOrientation::VERTICAL
|
||||
);
|
||||
|
||||
$this->box->set_name(
|
||||
$name
|
||||
);
|
||||
|
||||
$this->main = new \Yggverse\Yoda\Menu\Bar\Main();
|
||||
|
||||
$this->box->add(
|
||||
$this->main->bar
|
||||
);
|
||||
}
|
||||
}
|
||||
34
src/Box/Navigation.php
Normal file
34
src/Box/Navigation.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Box;
|
||||
|
||||
class Navigation
|
||||
{
|
||||
public \GtkBox $box;
|
||||
|
||||
public \Yggverse\Yoda\Entry\Address $address;
|
||||
|
||||
public function __construct(
|
||||
string $name = 'boxNavigation'
|
||||
) {
|
||||
global $config;
|
||||
|
||||
$this->box = new \GtkBox(
|
||||
\GtkOrientation::VERTICAL
|
||||
);
|
||||
|
||||
$this->box->set_name(
|
||||
$name
|
||||
);
|
||||
|
||||
$this->address = new \Yggverse\Yoda\Entry\Address(
|
||||
$config->homepage
|
||||
);
|
||||
|
||||
$this->box->add(
|
||||
$this->address->entry
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue