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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#include "tray.hpp"
Tray::Tray()
{
this->app_toggle = this->menu.addAction("");
this->menu.addSeparator();
this->menu.addMenu(&this->settings)->setText("Settings");
this->menu.addSeparator();
this->quit = this->menu.addAction("Quit");
this->permissions.camera = this->settings.addAction("Allow Camera");
this->permissions.microphone = this->settings.addAction("Allow Microphone");
this->permissions.screenshare = this->settings.addAction("Allow Screenshare");
this->permissions.notifications =
this->settings.addAction("Allow Notifications");
this->permissions.location = this->settings.addAction("Allow Location");
this->permissions.lock_mouse = this->settings.addAction("Allow Lock Mouse");
this->settings.addSeparator();
this->reset_storage = this->settings.addAction("Reset Storage");
this->permissions.camera->setCheckable(true);
this->permissions.microphone->setCheckable(true);
this->permissions.screenshare->setCheckable(true);
this->permissions.notifications->setCheckable(true);
this->permissions.location->setCheckable(true);
this->permissions.lock_mouse->setCheckable(true);
this->connect(this,
&QSystemTrayIcon::activated,
[&](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::ActivationReason::Trigger) {
this->toggle_signal();
}
});
this->menu.connect(&this->menu, &QMenu::triggered, [&](QAction *action) {
if (action == this->app_toggle) {
this->toggle_signal();
} else if (action == quit) {
this->quit_signal();
}
});
this->settings.connect(
&this->settings, &QMenu::triggered, [&](QAction *action) {
if (action == this->reset_storage) {
this->reset_cookies_signal();
} else if (action == this->permissions.camera) {
this->permission_changed_signal(
QWebEnginePage::Feature::MediaVideoCapture,
this->permissions.camera->isChecked());
} else if (action == this->permissions.microphone) {
this->permission_changed_signal(
QWebEnginePage::Feature::MediaAudioCapture,
this->permissions.microphone->isChecked());
} else if (action == this->permissions.screenshare) {
this->permission_changed_signal(
QWebEnginePage::Feature::DesktopAudioVideoCapture,
this->permissions.screenshare->isChecked());
} else if (action == this->permissions.notifications) {
this->permission_changed_signal(
QWebEnginePage::Feature::Notifications,
this->permissions.notifications->isChecked());
} else if (action == this->permissions.location) {
this->permission_changed_signal(
QWebEnginePage::Feature::Geolocation,
this->permissions.location->isChecked());
} else if (action == this->permissions.lock_mouse) {
this->permission_changed_signal(
QWebEnginePage::Feature::MouseLock,
this->permissions.lock_mouse->isChecked());
}
});
this->setContextMenu(&this->menu);
}
void
Tray::connect_toggle(std::function<void()> fn)
{
this->toggle_signal = fn;
}
void
Tray::connect_quit(std::function<void()> fn)
{
this->quit_signal = fn;
}
void
Tray::connect_reset_cookies(std::function<void()> fn)
{
this->reset_cookies_signal = fn;
}
void
Tray::connect_permission_changed(
std::function<void(QWebEnginePage::Feature, bool)> fn)
{
this->permission_changed_signal = fn;
}
void
Tray::set_title(const QString &title)
{
this->setToolTip(title);
this->app_toggle->setText(title);
}
void
Tray::send_notification(std::unique_ptr<QWebEngineNotification> notification)
{
this->showMessage(notification->title(),
notification->message(),
QSystemTrayIcon::MessageIcon::Information,
2000);
}
void
Tray::set_permission(QWebEnginePage::Feature feature, bool value)
{
switch (feature) {
case QWebEnginePage::Feature::MouseLock:
this->permissions.lock_mouse->setChecked(value);
break;
case QWebEnginePage::Feature::Geolocation:
this->permissions.location->setChecked(value);
break;
case QWebEnginePage::Feature::Notifications:
this->permissions.notifications->setChecked(value);
break;
case QWebEnginePage::Feature::MediaAudioCapture:
this->permissions.microphone->setChecked(value);
break;
case QWebEnginePage::Feature::MediaVideoCapture:
this->permissions.camera->setChecked(value);
break;
case QWebEnginePage::Feature::MediaAudioVideoCapture:
this->permissions.microphone->setChecked(value);
this->permissions.camera->setChecked(value);
break;
case QWebEnginePage::Feature::DesktopVideoCapture:
this->permissions.screenshare->setChecked(value);
break;
case QWebEnginePage::Feature::DesktopAudioVideoCapture:
this->permissions.screenshare->setChecked(value);
break;
}
}
|