Fixes
This commit is contained in:
parent
1a60367c0a
commit
a8d7965c43
|
@ -340,7 +340,17 @@ function main() {
|
||||||
// })
|
// })
|
||||||
// );
|
// );
|
||||||
|
|
||||||
section.appendChild(
|
section.appendChild(
|
||||||
|
createSwitch(
|
||||||
|
"Allow audio from your mic (and audio you pass through) to become stereo",
|
||||||
|
await userscript.getBoolPref("stereoMic", false),
|
||||||
|
(enabled) => {
|
||||||
|
userscript.setStereoMic(enabled);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
section.appendChild(
|
||||||
createSwitch(
|
createSwitch(
|
||||||
"Move discord-awesomeaudio to the system tray instead of closing",
|
"Move discord-awesomeaudio to the system tray instead of closing",
|
||||||
await userscript.getBoolPref("trayIcon", false),
|
await userscript.getBoolPref("trayIcon", false),
|
||||||
|
|
|
@ -18,129 +18,148 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QWebEngineFullScreenRequest>
|
#include <QWebEngineFullScreenRequest>
|
||||||
|
#include <QWebEngineProfile>
|
||||||
|
#include <QWebEngineUrlRequestInterceptor>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
// Custom network interceptor class
|
||||||
|
class NetworkInterceptor : public QWebEngineUrlRequestInterceptor {
|
||||||
|
public:
|
||||||
|
NetworkInterceptor(QObject* parent = nullptr) : QWebEngineUrlRequestInterceptor(parent) {}
|
||||||
|
|
||||||
|
void interceptRequest(QWebEngineUrlRequestInfo& info) override {
|
||||||
|
// Modify the request headers here as needed
|
||||||
|
info.setHttpHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
info.setHttpHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
MainWindow *MainWindow::m_instance = nullptr;
|
MainWindow *MainWindow::m_instance = nullptr;
|
||||||
|
|
||||||
MainWindow::MainWindow(bool useNotifySend, QWidget *parent)
|
MainWindow::MainWindow(bool useNotifySend, QWidget *parent)
|
||||||
: QMainWindow(parent) {
|
: QMainWindow(parent) {
|
||||||
assert(MainWindow::m_instance == nullptr);
|
assert(MainWindow::m_instance == nullptr);
|
||||||
MainWindow::m_instance = this;
|
MainWindow::m_instance = this;
|
||||||
setupSettings();
|
setupSettings();
|
||||||
m_settings->setValue("useNotifySend", useNotifySend);
|
m_settings->setValue("useNotifySend", useNotifySend);
|
||||||
m_centralWidget = new CentralWidget(this);
|
m_centralWidget = new CentralWidget(this);
|
||||||
setCentralWidget(m_centralWidget);
|
setCentralWidget(m_centralWidget);
|
||||||
setupTrayIcon();
|
|
||||||
setMinimumSize(800, 300);
|
// Create and install the network interceptor
|
||||||
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this),
|
NetworkInterceptor* networkInterceptor = new NetworkInterceptor(this);
|
||||||
&QShortcut::activated, this, &MainWindow::toggleOrCloseWindow);
|
QWebEngineProfile::defaultProfile()->setRequestInterceptor(networkInterceptor);
|
||||||
if (m_settings->contains("geometry")) {
|
|
||||||
restoreGeometry(m_settings->value("geometry").toByteArray());
|
setupTrayIcon();
|
||||||
} else {
|
setMinimumSize(800, 300);
|
||||||
resize(1000, 700);
|
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this),
|
||||||
showMaximized();
|
&QShortcut::activated, this, &MainWindow::toggleOrCloseWindow);
|
||||||
}
|
if (m_settings->contains("geometry")) {
|
||||||
if (m_settings->value("trayIcon", false).toBool() &&
|
restoreGeometry(m_settings->value("geometry").toByteArray());
|
||||||
m_settings->value("startHidden", false).toBool()) {
|
} else {
|
||||||
hide();
|
resize(1000, 700);
|
||||||
QTimer::singleShot(0, [=]() { hide(); });
|
showMaximized();
|
||||||
}
|
}
|
||||||
|
if (m_settings->value("trayIcon", false).toBool() &&
|
||||||
|
m_settings->value("startHidden", false).toBool()) {
|
||||||
|
hide();
|
||||||
|
QTimer::singleShot(0, [=]() { hide(); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::fullScreenRequested(
|
void MainWindow::fullScreenRequested(
|
||||||
QWebEngineFullScreenRequest fullScreenRequest) {
|
QWebEngineFullScreenRequest fullScreenRequest) {
|
||||||
fullScreenRequest.accept();
|
fullScreenRequest.accept();
|
||||||
if (fullScreenRequest.toggleOn()) {
|
if (fullScreenRequest.toggleOn()) {
|
||||||
m_wasMaximized = isMaximized();
|
m_wasMaximized = isMaximized();
|
||||||
if (!m_wasMaximized) {
|
if (!m_wasMaximized) {
|
||||||
showNormal();
|
showNormal();
|
||||||
|
}
|
||||||
|
showFullScreen();
|
||||||
|
} else {
|
||||||
|
m_wasMaximized ? showMaximized() : showNormal();
|
||||||
}
|
}
|
||||||
showFullScreen();
|
|
||||||
} else {
|
|
||||||
m_wasMaximized ? showMaximized() : showNormal();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setupTrayIcon() {
|
void MainWindow::setupTrayIcon() {
|
||||||
if (m_settings->value("trayIcon", false).toBool() == false ||
|
if (m_settings->value("trayIcon", false).toBool() == false ||
|
||||||
m_trayIcon != nullptr)
|
m_trayIcon != nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto aboutAction = new QAction(
|
auto aboutAction = new QAction(
|
||||||
"discord-awesomeaudio v" + QString(DISCORD_SCEENAUDIO_VERSION_FULL), this);
|
"discord-awesomeaudio v" + QString(DISCORD_SCEENAUDIO_VERSION_FULL), this);
|
||||||
aboutAction->setIcon(QIcon(":assets/de.shorsh.discord-screenaudio.png"));
|
aboutAction->setIcon(QIcon(":assets/de.shorsh.discord-screenaudio.png"));
|
||||||
aboutAction->setEnabled(false);
|
aboutAction->setEnabled(false);
|
||||||
|
|
||||||
auto exitAction = new QAction("Exit", this);
|
auto exitAction = new QAction("Exit", this);
|
||||||
connect(exitAction, &QAction::triggered, []() { QApplication::quit(); });
|
connect(exitAction, &QAction::triggered, []() { QApplication::quit(); });
|
||||||
|
|
||||||
m_trayIconMenu = new QMenu(this);
|
m_trayIconMenu = new QMenu(this);
|
||||||
m_trayIconMenu->addAction(aboutAction);
|
m_trayIconMenu->addAction(aboutAction);
|
||||||
m_trayIconMenu->addAction(exitAction);
|
m_trayIconMenu->addAction(exitAction);
|
||||||
|
|
||||||
m_trayIcon = new QSystemTrayIcon(this);
|
m_trayIcon = new QSystemTrayIcon(this);
|
||||||
m_trayIcon->setContextMenu(m_trayIconMenu);
|
m_trayIcon->setContextMenu(m_trayIconMenu);
|
||||||
m_trayIcon->setIcon(QIcon(":assets/de.shorsh.discord-screenaudio.png"));
|
m_trayIcon->setIcon(QIcon(":assets/de.shorsh.discord-screenaudio.png"));
|
||||||
m_trayIcon->show();
|
m_trayIcon->show();
|
||||||
|
|
||||||
connect(m_trayIcon, &QSystemTrayIcon::activated, [this](auto reason) {
|
connect(m_trayIcon, &QSystemTrayIcon::activated, [this](auto reason) {
|
||||||
if (reason == QSystemTrayIcon::Trigger) {
|
if (reason == QSystemTrayIcon::Trigger) {
|
||||||
toggleOrCloseWindow();
|
toggleOrCloseWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::cleanTrayIcon() {
|
void MainWindow::cleanTrayIcon() {
|
||||||
if (m_trayIcon == nullptr)
|
if (m_trayIcon == nullptr)
|
||||||
return;
|
return;
|
||||||
m_trayIcon->hide();
|
m_trayIcon->hide();
|
||||||
m_trayIconMenu->deleteLater();
|
m_trayIconMenu->deleteLater();
|
||||||
m_trayIcon->deleteLater();
|
m_trayIcon->deleteLater();
|
||||||
m_trayIconMenu = nullptr;
|
m_trayIconMenu = nullptr;
|
||||||
m_trayIcon = nullptr;
|
m_trayIcon = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setupSettings() {
|
void MainWindow::setupSettings() {
|
||||||
m_settings =
|
m_settings =
|
||||||
new QSettings("discord-awesomeaudio", "discord-awesomeaudio", this);
|
new QSettings("discord-awesomeaudio", "discord-awesomeaudio", this);
|
||||||
m_settings->beginGroup("settings");
|
m_settings->beginGroup("settings");
|
||||||
m_settings->endGroup();
|
m_settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings *MainWindow::settings() const { return m_settings; }
|
QSettings *MainWindow::settings() const { return m_settings; }
|
||||||
|
|
||||||
void MainWindow::setTrayIcon(bool enabled) {
|
void MainWindow::setTrayIcon(bool enabled) {
|
||||||
m_settings->setValue("trayIcon", enabled);
|
m_settings->setValue("trayIcon", enabled);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
setupTrayIcon();
|
setupTrayIcon();
|
||||||
} else {
|
} else {
|
||||||
cleanTrayIcon();
|
cleanTrayIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||||
if (m_settings->value("trayIcon", false).toBool()) {
|
if (m_settings->value("trayIcon", false).toBool()) {
|
||||||
hide();
|
hide();
|
||||||
} else {
|
} else {
|
||||||
m_settings->setValue("geometry", saveGeometry());
|
m_settings->setValue("geometry", saveGeometry());
|
||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow *MainWindow::instance() { return m_instance; }
|
MainWindow *MainWindow::instance() { return m_instance; }
|
||||||
|
|
||||||
CentralWidget *MainWindow::centralWidget() {
|
CentralWidget *MainWindow::centralWidget() {
|
||||||
return instance()->m_centralWidget;
|
return instance()->m_centralWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
void MainWindow::toggleOrCloseWindow() {
|
void MainWindow::toggleOrCloseWindow() {
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
if (m_trayIcon == nullptr)
|
if (m_trayIcon == nullptr)
|
||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
else
|
else
|
||||||
hide();
|
hide();
|
||||||
} else {
|
} else {
|
||||||
show();
|
show();
|
||||||
activateWindow();
|
activateWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,31 +10,31 @@
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QWebEngineUrlRequestInterceptor>
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(bool useNotifySend = false, QWidget *parent = nullptr);
|
explicit MainWindow(bool useNotifySend = false, QWidget *parent = nullptr);
|
||||||
static MainWindow *instance();
|
static MainWindow *instance();
|
||||||
QSettings *settings() const;
|
QSettings *settings() const;
|
||||||
static CentralWidget *centralWidget();
|
static CentralWidget *centralWidget();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupTrayIcon();
|
void setupTrayIcon();
|
||||||
void cleanTrayIcon();
|
void cleanTrayIcon();
|
||||||
void setupSettings();
|
void setupSettings();
|
||||||
QWebEngineProfile *prepareProfile();
|
void closeEvent(QCloseEvent *event) override;
|
||||||
void closeEvent(QCloseEvent *event) override;
|
QSystemTrayIcon *m_trayIcon = nullptr;
|
||||||
QSystemTrayIcon *m_trayIcon = nullptr;
|
QMenu *m_trayIconMenu;
|
||||||
QMenu *m_trayIconMenu;
|
QSettings *m_settings;
|
||||||
QSettings *m_settings;
|
bool m_wasMaximized;
|
||||||
bool m_wasMaximized;
|
static MainWindow *m_instance;
|
||||||
static MainWindow *m_instance;
|
CentralWidget *m_centralWidget;
|
||||||
CentralWidget *m_centralWidget;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setTrayIcon(bool enabled);
|
void setTrayIcon(bool enabled);
|
||||||
void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
|
void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
|
||||||
void toggleOrCloseWindow();
|
void toggleOrCloseWindow();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue