mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
implement window/tab title update
This commit is contained in:
parent
46d27ebfe8
commit
88ab363b4a
3 changed files with 133 additions and 55 deletions
18
config.json
18
config.json
|
|
@ -1,11 +1,19 @@
|
||||||
{
|
{
|
||||||
"app":
|
"app":
|
||||||
{
|
{
|
||||||
"title":"Yoda",
|
|
||||||
"theme":"Default",
|
"theme":"Default",
|
||||||
"header":
|
"header":
|
||||||
{
|
{
|
||||||
"enabled":true,
|
"enabled":true,
|
||||||
|
"title":
|
||||||
|
{
|
||||||
|
"default":"Yoda",
|
||||||
|
"postfix":" - Yoda",
|
||||||
|
"length":
|
||||||
|
{
|
||||||
|
"max":32
|
||||||
|
}
|
||||||
|
},
|
||||||
"button":
|
"button":
|
||||||
{
|
{
|
||||||
"close":true
|
"close":true
|
||||||
|
|
@ -17,6 +25,14 @@
|
||||||
{
|
{
|
||||||
"page":
|
"page":
|
||||||
{
|
{
|
||||||
|
"title":
|
||||||
|
{
|
||||||
|
"default":"New page",
|
||||||
|
"length":
|
||||||
|
{
|
||||||
|
"max":32
|
||||||
|
}
|
||||||
|
},
|
||||||
"redirect":
|
"redirect":
|
||||||
{
|
{
|
||||||
"follow":
|
"follow":
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ namespace Yggverse\Yoda\Entity;
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
public \GtkWindow $window;
|
public \GtkWindow $window;
|
||||||
public \GtkNotebook $tab;
|
public \GtkHeaderBar $header;
|
||||||
|
public \GtkNotebook $tabs;
|
||||||
|
|
||||||
public object $config;
|
public object $config;
|
||||||
|
|
||||||
|
|
@ -24,18 +25,18 @@ class App
|
||||||
|
|
||||||
if ($this->config->header->enabled)
|
if ($this->config->header->enabled)
|
||||||
{
|
{
|
||||||
$header = new \GtkHeaderBar();
|
$this->header = new \GtkHeaderBar();
|
||||||
|
|
||||||
$header->set_title(
|
$this->header->set_title(
|
||||||
$this->config->title
|
$this->config->header->title->default
|
||||||
);
|
);
|
||||||
|
|
||||||
$header->set_show_close_button(
|
$this->header->set_show_close_button(
|
||||||
$this->config->header->button->close
|
$this->config->header->button->close
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->window->set_titlebar(
|
$this->window->set_titlebar(
|
||||||
$header
|
$this->header
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,43 +48,67 @@ class App
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$page = new \Yggverse\Yoda\Entity\Tab\Page(
|
$this->tabs = new \GtkNotebook();
|
||||||
$this
|
|
||||||
);
|
|
||||||
|
|
||||||
$page->open(
|
$this->tabs->set_scrollable(
|
||||||
$this->config->tab->page->header->button->home->url
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->tab = new \GtkNotebook();
|
|
||||||
|
|
||||||
$this->tab->set_scrollable(
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->tab->append_page(
|
|
||||||
$page->box,
|
|
||||||
new \GtkLabel(
|
|
||||||
'New page' // @TODO
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->tab->set_menu_label(
|
|
||||||
$page->box,
|
|
||||||
new \GtkLabel(
|
|
||||||
'2' // @TODO
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->tab->set_tab_reorderable(
|
|
||||||
$page->box,
|
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->window->add(
|
$this->window->add(
|
||||||
$this->tab
|
$this->tabs
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->openPage(
|
||||||
|
$this->config->tab->page->header->button->home->url // @TODO
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->window->show_all();
|
$this->window->show_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function openPage(
|
||||||
|
string $url
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$page = new \Yggverse\Yoda\Entity\Tab\Page(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->tabs->append_page(
|
||||||
|
$page->box,
|
||||||
|
new \GtkLabel(
|
||||||
|
$this->config->tab->page->title->default
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->tabs->set_tab_reorderable(
|
||||||
|
$page->box,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$page->open(
|
||||||
|
$url
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTitle(
|
||||||
|
?string $value = null
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
if ($value)
|
||||||
|
{
|
||||||
|
$title = urldecode(
|
||||||
|
strlen($value) > $this->config->header->title->length->max ? substr($value, 0, $this->config->header->title->length->max) . '...'
|
||||||
|
: $value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$title = $this->config->header->title->default;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->header->set_title(
|
||||||
|
$title
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -350,7 +350,7 @@ class Page
|
||||||
{
|
{
|
||||||
case str_starts_with($url, 'gemini://'):
|
case str_starts_with($url, 'gemini://'):
|
||||||
|
|
||||||
$this->_gemini(
|
$this->_openGemini(
|
||||||
$url,
|
$url,
|
||||||
$code
|
$code
|
||||||
);
|
);
|
||||||
|
|
@ -359,18 +359,23 @@ class Page
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
$this->_yoda(
|
$this->_openYoda(
|
||||||
$url
|
$url
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _gemini(
|
private function _openGemini(
|
||||||
string $url,
|
string $url,
|
||||||
int $code = 0,
|
int $code = 0,
|
||||||
int $redirects = 0
|
int $redirects = 0
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
|
// Init base URL
|
||||||
|
$origin = new \Yggverse\Net\Address(
|
||||||
|
$url
|
||||||
|
);
|
||||||
|
|
||||||
// Track response time
|
// Track response time
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
|
||||||
|
|
@ -430,7 +435,7 @@ class Page
|
||||||
{
|
{
|
||||||
if ($redirects > $this->config->redirect->follow->max)
|
if ($redirects > $this->config->redirect->follow->max)
|
||||||
{
|
{
|
||||||
$this->_yoda(
|
$this->_openYoda(
|
||||||
'yoda://redirect'
|
'yoda://redirect'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -457,7 +462,7 @@ class Page
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->_yoda(
|
$this->_openYoda(
|
||||||
'yoda://redirect'
|
'yoda://redirect'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -468,7 +473,7 @@ class Page
|
||||||
// Process error codes
|
// Process error codes
|
||||||
if (20 != $response->getCode()) // not found
|
if (20 != $response->getCode()) // not found
|
||||||
{
|
{
|
||||||
$this->_yoda(
|
$this->_openYoda(
|
||||||
'yoda://nothing'
|
'yoda://nothing'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -487,16 +492,23 @@ class Page
|
||||||
|
|
||||||
if ($h1 = $body->getH1())
|
if ($h1 = $body->getH1())
|
||||||
{
|
{
|
||||||
$this->app->window->set_title(
|
$title = $h1[0] .
|
||||||
sprintf(
|
$this->app->config->header->title->postfix;
|
||||||
'%s - %s',
|
}
|
||||||
empty($h1[0]) ? $address->getHost() : $h1[0],
|
|
||||||
$this->app->config->title
|
else
|
||||||
)
|
{
|
||||||
|
$title = $origin->getHost() .
|
||||||
|
$this->app->config->header->title->postfix;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->app->setTitle(
|
||||||
|
$title
|
||||||
);
|
);
|
||||||
|
|
||||||
// @TODO update tab title
|
$this->setTitle(
|
||||||
}
|
$title
|
||||||
|
);
|
||||||
|
|
||||||
$this->status->set_markup(
|
$this->status->set_markup(
|
||||||
str_replace( // Custom macros mask from config.json
|
str_replace( // Custom macros mask from config.json
|
||||||
|
|
@ -533,7 +545,7 @@ class Page
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _yoda(
|
private function _openYoda(
|
||||||
string $url
|
string $url
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
|
|
@ -556,11 +568,36 @@ class Page
|
||||||
|
|
||||||
if ($h1 = $body->getH1())
|
if ($h1 = $body->getH1())
|
||||||
{
|
{
|
||||||
$this->app->window->set_title(
|
$this->app->setTitle(
|
||||||
$h1[0]
|
$h1[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
// @TODO update tab title
|
$this->setTitle(
|
||||||
|
$h1[0]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setTitle(
|
||||||
|
?string $value = null
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
if ($value)
|
||||||
|
{
|
||||||
|
$title = urldecode(
|
||||||
|
strlen($value) > $this->config->title->length->max ? substr($value, 0, $this->config->title->length->max) . '...'
|
||||||
|
: $value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$title = $this->config->title->default;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->app->tabs->set_tab_label_text(
|
||||||
|
$this->box,
|
||||||
|
$title
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue