-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.php
More file actions
119 lines (97 loc) · 3.12 KB
/
App.php
File metadata and controls
119 lines (97 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types=1);
namespace Ardillo\Examples\Dns;
use Ardillo\{
Menu,
ReactApp,
TableModel,
Size,
};
use React\Dns\Model\Message;
class App extends ReactApp
{
public const QUERY_TYPES = [
Message::TYPE_A => 'A',
Message::TYPE_AAAA => 'AAAA',
Message::TYPE_CNAME => 'CNAME',
Message::TYPE_MX => 'MX',
Message::TYPE_NS => 'NS',
Message::TYPE_PTR => 'PTR',
Message::TYPE_SOA => 'SOA',
Message::TYPE_SRV => 'SRV',
Message::TYPE_TXT => 'TXT',
];
/** @var array<int, bool> */
public array $querySelection = [
Message::TYPE_A => true,
Message::TYPE_AAAA => true,
Message::TYPE_CNAME => true,
Message::TYPE_MX => true,
Message::TYPE_NS => true,
Message::TYPE_PTR => true,
Message::TYPE_SOA => true,
Message::TYPE_SRV => true,
Message::TYPE_TXT => true,
];
public string $nameserver = '8.8.8.8';
public Main\Window $win;
public Prefs\Window $prefsWin;
public Handler $handler;
public TableModel $model;
public function onShouldQuit(): bool
{
/* Manually unset the window so the Table object is destroyed before the TableModel */
unset($this->win);
return true;
}
public function onMenuItemClicked(int $id): void
{
switch ($id) {
case 1:
$path = $this->win->saveFile();
if ($path) {
$this->handler->export($path);
}
break;
case 3:
if (!isset($this->prefsWin) || !$this->prefsWin->isValid()) {
$this->prefsWin = new Prefs\Window('DNS Preferences', new Size(300, 100), false);
$this->prefsWin->setup();
}
$this->prefsWin->show();
break;
case 4:
$this->win->messageBox(
Main\Window::MESSAGE_BOX_DEFAULT, 'Ardillo DNS',
"DNS client built with Ardillo\nhttps://ardillo.org"
);
break;
}
}
public function setupMenu(): void
{
$file = $this->appendMenu(null, Menu::Top, 0, 'File');
$this->appendMenu($file, Menu::Item, 1, 'Export as CSV');
$this->appendMenu($file, Menu::Quit, 2, null);
$edit = $this->appendMenu(null, Menu::Top, 0, 'Edit');
$this->appendMenu($edit, Menu::Preferences, 3, null);
$help = $this->appendMenu(null, Menu::Top, 0, 'Help');
$this->appendMenu($help, Menu::About, 4, null);
}
public function onSigInt(int $signo): void
{
echo 'Caught SIGINT ...' . PHP_EOL;
unset($this->win);
$this->stop();
}
protected function OnInit(): void
{
$this->setupMenu();
$this->handler = new Handler;
$this->model = new TableModel($this->handler);
$this->win = new Main\Window('Ardillo DNS', new Size(640, 480), true);
$this->win->setup();
$this->win->show();
$this->loop->addSignal(self::SIGINT, $this->onSigInt(...));
}
}