aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp19
-rw-r--r--src/permissionmanager.cpp66
-rw-r--r--src/permissionmanager.hpp13
-rw-r--r--src/tray.cpp37
-rw-r--r--src/tray.hpp1
-rw-r--r--src/webwindow.cpp69
-rw-r--r--src/webwindow.hpp10
7 files changed, 126 insertions, 89 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 9c6b3c4..e40f387 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,6 +6,16 @@
#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)
{
@@ -34,6 +44,10 @@ main(int argc, char **argv)
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();
@@ -47,8 +61,9 @@ main(int argc, char **argv)
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_permission_changed([&](auto feature, auto value) {
+ webwindow.permissions().set(feature, value);
+ });
tray.connect_reset_cookies([&]() { webwindow.reset_cookies(); });
webwindow.show();
diff --git a/src/permissionmanager.cpp b/src/permissionmanager.cpp
index 0687c8a..22a7110 100644
--- a/src/permissionmanager.cpp
+++ b/src/permissionmanager.cpp
@@ -1,4 +1,5 @@
#include "permissionmanager.hpp"
+#include <iostream>
PermissionManager::PermissionManager(std::string path)
: path(path)
@@ -6,13 +7,12 @@ PermissionManager::PermissionManager(std::string path)
if (std::filesystem::exists(this->path)) {
std::ifstream in(path);
std::string content;
- in >> this->_lock_mouse;
- in >> this->_location;
- in >> this->_notification;
- in >> this->_media_audio_capture;
- in >> this->_media_video_capture;
- in >> this->_desktop_video_capture;
- in >> this->_desktop_audio_video_capture;
+ in >> this->lock_mouse;
+ in >> this->location;
+ in >> this->notification;
+ in >> this->media_audio_capture;
+ in >> this->media_video_capture;
+ in >> this->desktop_audio_video_capture;
}
}
@@ -25,13 +25,17 @@ void
PermissionManager::save()
{
std::ofstream out(this->path);
- out << this->_lock_mouse;
- out << this->_location;
- out << this->_notification;
- out << this->_media_audio_capture;
- out << this->_media_video_capture;
- out << this->_desktop_video_capture;
- out << this->_desktop_audio_video_capture;
+ out << this->lock_mouse;
+ out << " ";
+ out << this->location;
+ out << " ";
+ out << this->notification;
+ out << " ";
+ out << this->media_audio_capture;
+ out << " ";
+ out << this->media_video_capture;
+ out << " ";
+ out << this->desktop_audio_video_capture;
}
bool
@@ -39,21 +43,21 @@ PermissionManager::get(QWebEnginePage::Feature feature)
{
switch (feature) {
case QWebEnginePage::Feature::MouseLock:
- return this->_lock_mouse;
+ return this->lock_mouse;
case QWebEnginePage::Feature::Geolocation:
- return this->_location;
+ return this->location;
case QWebEnginePage::Feature::Notifications:
- return this->_notification;
+ return this->notification;
case QWebEnginePage::Feature::MediaAudioCapture:
- return this->_media_audio_capture;
+ return this->media_audio_capture;
case QWebEnginePage::Feature::MediaVideoCapture:
- return this->_media_video_capture;
+ return this->media_video_capture;
case QWebEnginePage::Feature::MediaAudioVideoCapture:
- return this->_media_video_capture && this->_media_audio_capture;
+ return this->media_video_capture && this->media_audio_capture;
case QWebEnginePage::Feature::DesktopVideoCapture:
- return this->_desktop_video_capture;
+ return this->desktop_audio_video_capture;
case QWebEnginePage::Feature::DesktopAudioVideoCapture:
- return this->_desktop_audio_video_capture;
+ return this->desktop_audio_video_capture;
default:
/* unreachable except QWebEnginePage::Feature gets new entries */
return false;
@@ -65,29 +69,29 @@ PermissionManager::set(QWebEnginePage::Feature feature, bool value)
{
switch (feature) {
case QWebEnginePage::Feature::MouseLock:
- this->_lock_mouse = value;
+ this->lock_mouse = value;
break;
case QWebEnginePage::Feature::Geolocation:
- this->_location = value;
+ this->location = value;
break;
case QWebEnginePage::Feature::Notifications:
- this->_notification = value;
+ this->notification = value;
break;
case QWebEnginePage::Feature::MediaAudioCapture:
- this->_media_audio_capture = value;
+ this->media_audio_capture = value;
break;
case QWebEnginePage::Feature::MediaVideoCapture:
- this->_media_video_capture = value;
+ this->media_video_capture = value;
break;
case QWebEnginePage::Feature::MediaAudioVideoCapture:
- this->_media_audio_capture = value;
- this->_media_video_capture = value;
+ this->media_audio_capture = value;
+ this->media_video_capture = value;
break;
case QWebEnginePage::Feature::DesktopVideoCapture:
- this->_desktop_video_capture = value;
+ this->desktop_audio_video_capture = value;
break;
case QWebEnginePage::Feature::DesktopAudioVideoCapture:
- this->_desktop_audio_video_capture = value;
+ this->desktop_audio_video_capture = value;
break;
}
}
diff --git a/src/permissionmanager.hpp b/src/permissionmanager.hpp
index 70c17e9..8d53597 100644
--- a/src/permissionmanager.hpp
+++ b/src/permissionmanager.hpp
@@ -9,13 +9,12 @@ class PermissionManager
{
private:
std::string path;
- bool _lock_mouse = false;
- bool _location = false;
- bool _notification = false;
- bool _media_audio_capture = false;
- bool _media_video_capture = false;
- bool _desktop_video_capture = false;
- bool _desktop_audio_video_capture = false;
+ bool lock_mouse = false;
+ bool location = false;
+ bool notification = false;
+ bool media_audio_capture = false;
+ bool media_video_capture = false;
+ bool desktop_audio_video_capture = false;
public:
PermissionManager(std::string path);
diff --git a/src/tray.cpp b/src/tray.cpp
index c6e48a8..8503cb7 100644
--- a/src/tray.cpp
+++ b/src/tray.cpp
@@ -11,8 +11,6 @@ Tray::Tray()
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.system_audio =
- this->settings.addAction("Allow System Audio Record");
this->permissions.notifications =
this->settings.addAction("Allow Notifications");
this->permissions.location = this->settings.addAction("Allow Location");
@@ -23,7 +21,6 @@ Tray::Tray()
this->permissions.camera->setCheckable(true);
this->permissions.microphone->setCheckable(true);
this->permissions.screenshare->setCheckable(true);
- this->permissions.system_audio->setCheckable(true);
this->permissions.notifications->setCheckable(true);
this->permissions.location->setCheckable(true);
this->permissions.lock_mouse->setCheckable(true);
@@ -59,14 +56,9 @@ Tray::Tray()
QWebEnginePage::Feature::MediaAudioCapture,
this->permissions.microphone->isChecked());
- } else if (action == this->permissions.system_audio) {
- this->permission_changed_signal(
- QWebEnginePage::Feature::DesktopAudioVideoCapture,
- this->permissions.system_audio->isChecked());
-
} else if (action == this->permissions.screenshare) {
this->permission_changed_signal(
- QWebEnginePage::Feature::DesktopVideoCapture,
+ QWebEnginePage::Feature::DesktopAudioVideoCapture,
this->permissions.screenshare->isChecked());
} else if (action == this->permissions.notifications) {
@@ -133,4 +125,31 @@ Tray::send_notification(std::unique_ptr<QWebEngineNotification> notification)
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;
+ }
}
diff --git a/src/tray.hpp b/src/tray.hpp
index 427cdc8..865c586 100644
--- a/src/tray.hpp
+++ b/src/tray.hpp
@@ -19,7 +19,6 @@ private:
QAction *camera;
QAction *microphone;
QAction *screenshare;
- QAction *system_audio;
QAction *notifications;
QAction *location;
QAction *lock_mouse;
diff --git a/src/webwindow.cpp b/src/webwindow.cpp
index 36e1818..d7c25f9 100644
--- a/src/webwindow.cpp
+++ b/src/webwindow.cpp
@@ -8,53 +8,54 @@
WebWindow::WebWindow(const QString &url)
: QMainWindow()
- , _profile(QUrl(url).host())
- , _page(&_profile)
- , _permissions((QUrl(url).host() + "/permissions.state").toStdString())
+ , profile(QUrl(url).host())
+ , page(&profile)
+ , perm((profile.persistentStoragePath() + "/permissions.state").toStdString())
{
this->web_configure();
- this->_profile.setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
+ this->profile.setPersistentCookiesPolicy(
+ QWebEngineProfile::ForcePersistentCookies);
- this->_view.setPage(&this->_page);
- this->_view.setUrl(url);
+ this->view.setPage(&this->page);
+ this->view.setUrl(url);
- this->setCentralWidget(&this->_view);
+ this->setCentralWidget(&this->view);
}
void
WebWindow::web_configure()
{
- this->_page.settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled,
- true);
+ this->page.settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled,
+ true);
- this->_page.settings()->setAttribute(
+ this->page.settings()->setAttribute(
QWebEngineSettings::WebRTCPublicInterfacesOnly, false);
- this->_page.settings()->setAttribute(
- QWebEngineSettings::ScrollAnimatorEnabled, false);
+ this->page.settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled,
+ false);
- this->_profile.setPushServiceEnabled(true);
+ this->profile.setPushServiceEnabled(true);
- this->_page.connect(&this->_page,
- &QWebEnginePage::featurePermissionRequested,
- [&](const QUrl origin, QWebEnginePage::Feature feature) {
- this->permission_requested(origin, feature);
- });
+ this->page.connect(&this->page,
+ &QWebEnginePage::featurePermissionRequested,
+ [&](const QUrl origin, QWebEnginePage::Feature feature) {
+ this->permission_requested(origin, feature);
+ });
}
void
WebWindow::permission_requested(const QUrl origin,
QWebEnginePage::Feature feature)
{
- if (this->_permissions.get(feature)) {
- this->_page.setFeaturePermission(
+ if (this->perm.get(feature)) {
+ this->page.setFeaturePermission(
origin, feature, QWebEnginePage::PermissionGrantedByUser);
} else {
- this->_page.setFeaturePermission(
+ this->page.setFeaturePermission(
origin, feature, QWebEnginePage::PermissionDeniedByUser);
}
- this->_page.setFeaturePermission(
+ this->page.setFeaturePermission(
origin, feature, QWebEnginePage::PermissionUnknown);
}
@@ -68,37 +69,37 @@ WebWindow::closeEvent(QCloseEvent *event)
void
WebWindow::connect_icon_changed(std::function<void(const QIcon)> fn)
{
- this->_view.connect(&this->_view, &QWebEngineView::iconChanged, fn);
+ this->view.connect(&this->view, &QWebEngineView::iconChanged, fn);
}
void
WebWindow::connect_notification(
std::function<void(std::unique_ptr<QWebEngineNotification>)> fn)
{
- this->_profile.setNotificationPresenter(fn);
+ this->profile.setNotificationPresenter(fn);
}
void
WebWindow::connect_title_changed(std::function<void(const QString)> fn)
{
- this->_view.connect(&this->_view, &QWebEngineView::titleChanged, fn);
+ this->view.connect(&this->view, &QWebEngineView::titleChanged, fn);
}
-void
-WebWindow::set_feature(QWebEnginePage::Feature feature, bool value)
+PermissionManager &
+WebWindow::permissions()
{
- this->_permissions.set(feature, value);
+ return this->perm;
}
void
WebWindow::reset_cookies()
{
- this->_profile.cookieStore()->deleteAllCookies();
- this->_profile.cookieStore()->loadAllCookies();
- this->_profile.clearHttpCache();
- this->_profile.clearAllVisitedLinks();
- this->_profile.clientCertificateStore();
- this->_view.reload();
+ this->profile.cookieStore()->deleteAllCookies();
+ this->profile.cookieStore()->loadAllCookies();
+ this->profile.clearHttpCache();
+ this->profile.clearAllVisitedLinks();
+ this->profile.clientCertificateStore();
+ this->view.reload();
}
void
diff --git a/src/webwindow.hpp b/src/webwindow.hpp
index 49b2394..1d4a83e 100644
--- a/src/webwindow.hpp
+++ b/src/webwindow.hpp
@@ -14,10 +14,10 @@
class WebWindow : public QMainWindow
{
private:
- QWebEngineProfile _profile;
- QWebEnginePage _page;
- QWebEngineView _view;
- PermissionManager _permissions;
+ QWebEngineProfile profile;
+ QWebEnginePage page;
+ QWebEngineView view;
+ PermissionManager perm;
void web_configure();
void permission_requested(const QUrl origin, QWebEnginePage::Feature feature);
@@ -28,7 +28,7 @@ public:
void connect_icon_changed(std::function<void(const QIcon)> fn);
void connect_title_changed(std::function<void(const QString)> fn);
void connect_notification(std::function<void(std::unique_ptr<QWebEngineNotification>)> fn);
- void set_feature(QWebEnginePage::Feature feature, bool value);
+ PermissionManager &permissions();
void reset_cookies();
void toggle_visibility();
void quit();