blob: e40f387eab0890e8b973ad21ed1c4e5fb275247e (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <QtWidgets/QApplication>
#include <iostream>
#include "permissionmanager.hpp"
#include "tray.hpp"
#include "webwindow.hpp"
const QWebEnginePage::Feature features[] = {
QWebEnginePage::Feature::MouseLock,
QWebEnginePage::Feature::Notifications,
QWebEnginePage::Feature::Notifications,
QWebEnginePage::Feature::DesktopVideoCapture,
QWebEnginePage::Feature::DesktopAudioVideoCapture,
QWebEnginePage::Feature::MediaAudioCapture,
QWebEnginePage::Feature::MediaVideoCapture,
};
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");
for (auto feature : features) {
tray.set_permission(feature, webwindow.permissions().get(feature));
}
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.permissions().set(feature, value);
});
tray.connect_reset_cookies([&]() { webwindow.reset_cookies(); });
webwindow.show();
if (start_hidden) {
webwindow.hide();
}
return app.exec();
}
|