blob: 9c6b3c409fd1b12a4d83d028c85429084c281d9b (
plain)
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
|
#include <QtWidgets/QApplication>
#include <iostream>
#include "permissionmanager.hpp"
#include "tray.hpp"
#include "webwindow.hpp"
QString
extract_url(const QStringList arguments)
{
for (const auto &argument : arguments) {
if (!argument.endsWith("webtray") && !argument.startsWith("--")) {
return argument;
}
}
return "";
}
int
main(int argc, char **argv)
{
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
QString url = extract_url(app.arguments());
if (url.isEmpty()) {
std::cerr << "webtray [--open-at-startup] <url>\n";
return -1;
}
WebWindow webwindow(url);
Tray tray;
bool start_hidden = not app.arguments().contains("--open-at-startup");
webwindow.connect_icon_changed([&](auto icon) {
tray.setIcon(icon);
tray.show();
});
webwindow.connect_title_changed([&](auto title) { tray.set_title(title); });
webwindow.connect_notification([&](auto notification) {
tray.send_notification(std::move(notification));
});
tray.connect_toggle([&]() { webwindow.toggle_visibility(); });
tray.connect_quit([&]() { webwindow.quit(); });
tray.connect_permission_changed(
[&](auto feature, auto value) { webwindow.set_feature(feature, value); });
tray.connect_reset_cookies([&]() { webwindow.reset_cookies(); });
webwindow.show();
if (start_hidden) {
webwindow.hide();
}
return app.exec();
}
|