mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
save session on browser close only
This commit is contained in:
parent
196b55e072
commit
48198668fd
4 changed files with 38 additions and 79 deletions
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Yggverse\Yoda\Entity;
|
namespace Yggverse\Yoda\Entity;
|
||||||
|
|
||||||
|
use \Gtk;
|
||||||
use \GtkWindow;
|
use \GtkWindow;
|
||||||
|
|
||||||
use \Yggverse\Yoda\Entity\Browser\Header;
|
use \Yggverse\Yoda\Entity\Browser\Header;
|
||||||
|
|
@ -78,5 +79,31 @@ class Browser
|
||||||
// @TODO render data wordwrap by $window->get_size()
|
// @TODO render data wordwrap by $window->get_size()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->gtk->connect(
|
||||||
|
'destroy',
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
// Save session
|
||||||
|
$pid = pcntl_fork();
|
||||||
|
|
||||||
|
if ($pid === 0)
|
||||||
|
{
|
||||||
|
$this->database->cleanSession();
|
||||||
|
|
||||||
|
foreach ($this->container->tab->pages as $page)
|
||||||
|
{
|
||||||
|
$this->database->addSession(
|
||||||
|
$page->navbar->request->getValue()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit application
|
||||||
|
Gtk::main_quit();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||||
namespace Yggverse\Yoda\Entity\Browser\Container\Page\Navbar;
|
namespace Yggverse\Yoda\Entity\Browser\Container\Page\Navbar;
|
||||||
|
|
||||||
use \GdkEvent;
|
use \GdkEvent;
|
||||||
use \Gtk;
|
|
||||||
use \GtkEntry;
|
use \GtkEntry;
|
||||||
|
|
||||||
use \Yggverse\Yoda\Abstract\Entity\Entry;
|
use \Yggverse\Yoda\Abstract\Entity\Entry;
|
||||||
|
|
@ -17,9 +16,6 @@ class Request extends Entry
|
||||||
// Defaults
|
// Defaults
|
||||||
public const PLACEHOLDER = 'URL or search term...';
|
public const PLACEHOLDER = 'URL or search term...';
|
||||||
|
|
||||||
// Extras
|
|
||||||
private ?int $_changed = null;
|
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
public Navbar $navbar;
|
public Navbar $navbar;
|
||||||
|
|
||||||
|
|
@ -57,8 +53,6 @@ class Request extends Entry
|
||||||
$this->navbar->page->open(
|
$this->navbar->page->open(
|
||||||
$this->getValue()
|
$this->getValue()
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->navbar->page->container->tab->update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _onKeyRelease(
|
protected function _onKeyRelease(
|
||||||
|
|
@ -81,33 +75,6 @@ class Request extends Entry
|
||||||
|
|
||||||
// Show suggestions autocomplete
|
// Show suggestions autocomplete
|
||||||
$this->completion->refresh();
|
$this->completion->refresh();
|
||||||
|
|
||||||
// Update session
|
|
||||||
if (isset($this->navbar->page->container->tab))
|
|
||||||
{
|
|
||||||
// Reset keyup time
|
|
||||||
if ($this->_changed)
|
|
||||||
{
|
|
||||||
Gtk::source_remove(
|
|
||||||
$this->_changed
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->_changed = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for one second to apply act
|
|
||||||
$this->_changed = Gtk::timeout_add(
|
|
||||||
1000,
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
$this->navbar->page->container->tab->update();
|
|
||||||
|
|
||||||
$this->_changed = null;
|
|
||||||
|
|
||||||
return false; // stop
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _onFocusOut(
|
protected function _onFocusOut(
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class Tab
|
||||||
public const SCROLLABLE = true;
|
public const SCROLLABLE = true;
|
||||||
|
|
||||||
// Extras
|
// Extras
|
||||||
private array $_page = [];
|
public array $pages = [];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Container $container
|
Container $container
|
||||||
|
|
@ -119,7 +119,7 @@ class Tab
|
||||||
{
|
{
|
||||||
// Extendable classes not supported by PHP-GTK3 #117
|
// Extendable classes not supported by PHP-GTK3 #117
|
||||||
// create internal pages registry
|
// create internal pages registry
|
||||||
$this->_page[] = $page = new Page(
|
$this->pages[] = $page = new Page(
|
||||||
$this->container
|
$this->container
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -204,13 +204,13 @@ class Tab
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate page index exists
|
// Validate page index exists
|
||||||
if (empty($this->_page[$page_num]))
|
if (empty($this->pages[$page_num]))
|
||||||
{
|
{
|
||||||
throw new Exception;
|
throw new Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return page entity
|
// Return page entity
|
||||||
return $this->_page[$page_num];
|
return $this->pages[$page_num];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(
|
public function close(
|
||||||
|
|
@ -229,14 +229,12 @@ class Tab
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reorder(
|
public function reorder(): void
|
||||||
bool $session = true
|
|
||||||
): void
|
|
||||||
{
|
{
|
||||||
// Init new index
|
// Init new index
|
||||||
$_page = [];
|
$pages = [];
|
||||||
|
|
||||||
foreach ($this->_page as $page)
|
foreach ($this->pages as $page)
|
||||||
{
|
{
|
||||||
// Get current entity $page_num
|
// Get current entity $page_num
|
||||||
$page_num = $this->gtk->page_num(
|
$page_num = $this->gtk->page_num(
|
||||||
|
|
@ -253,39 +251,14 @@ class Tab
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update position
|
// Update position
|
||||||
$_page[$page_num] = $page;
|
$pages[$page_num] = $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reorder entities
|
// Reorder entities
|
||||||
$this->_page = $_page;
|
$this->pages = $pages;
|
||||||
|
|
||||||
ksort(
|
ksort(
|
||||||
$this->_page
|
$this->pages
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update session
|
|
||||||
if ($session)
|
|
||||||
{
|
|
||||||
$this->update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(): void
|
|
||||||
{
|
|
||||||
$pid = pcntl_fork();
|
|
||||||
|
|
||||||
if ($pid === 0)
|
|
||||||
{
|
|
||||||
$this->container->browser->database->cleanSession();
|
|
||||||
|
|
||||||
foreach ($this->_page as $page)
|
|
||||||
{
|
|
||||||
$this->container->browser->database->addSession(
|
|
||||||
$page->navbar->request->getValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10
src/Yoda.php
10
src/Yoda.php
|
|
@ -24,18 +24,10 @@ $database = new \Yggverse\Yoda\Model\Database(
|
||||||
\Gtk::init();
|
\Gtk::init();
|
||||||
|
|
||||||
// Init browser
|
// Init browser
|
||||||
$browser = new \Yggverse\Yoda\Entity\Browser(
|
new \Yggverse\Yoda\Entity\Browser(
|
||||||
$database
|
$database
|
||||||
);
|
);
|
||||||
|
|
||||||
$browser->gtk->connect(
|
|
||||||
'destroy',
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
\Gtk::main_quit();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Init theme
|
// Init theme
|
||||||
$css = new \GtkCssProvider;
|
$css = new \GtkCssProvider;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue