add setting to start hidden to tray

This commit is contained in:
Malte Jürgens 2023-02-07 11:53:10 +01:00
parent a10cfda56d
commit 0b12487dfd
No known key found for this signature in database
GPG key ID: D29FBD5F93C0CFC3
3 changed files with 28 additions and 2 deletions

View file

@ -99,7 +99,7 @@ function createSwitch(text, enabled, onClick) {
container.appendChild(svg);
function setSvgDisabled() {
svg.innerHTML = `<div class="container-1QtPKm default-colors disabled-3_3z1m" style="opacity: 0.3; background-color: rgb(114, 118, 125);"><svg class="slider-HJFN2i" viewBox="0 0 28 20" preserveAspectRatio="xMinYMid meet" aria-hidden="true" style="left: -3px;"><rect fill="white" x="4" y="0" height="20" width="20" rx="10"></rect><svg viewBox="0 0 20 20" fill="none"><path fill="rgba(114, 118, 125, 1)" d="M5.13231 6.72963L6.7233 5.13864L14.855 13.2704L13.264 14.8614L5.13231 6.72963Z"></path><path fill="rgba(114, 118, 125, 1)" d="M13.2704 5.13864L14.8614 6.72963L6.72963 14.8614L5.13864 13.2704L13.2704 5.13864Z"></path></svg></svg><input id="uid_75" type="checkbox" class="input-125oad" tabindex="-1" disabled=""></div>`;
svg.innerHTML = `<div class="container-1QtPKm default-colors" style="opacity: 1; background-color: rgb(114, 118, 125);"><svg class="slider-HJFN2i" viewBox="0 0 28 20" preserveAspectRatio="xMinYMid meet" aria-hidden="true" style="left: -3px;"><rect fill="white" x="4" y="0" height="20" width="20" rx="10"></rect><svg viewBox="0 0 20 20" fill="none"><path fill="rgba(114, 118, 125, 1)" d="M5.13231 6.72963L6.7233 5.13864L14.855 13.2704L13.264 14.8614L5.13231 6.72963Z"></path><path fill="rgba(114, 118, 125, 1)" d="M13.2704 5.13864L14.8614 6.72963L6.72963 14.8614L5.13864 13.2704L13.2704 5.13864Z"></path></svg></svg><input id="uid_84" type="checkbox" class="input-125oad" tabindex="0"></div>`;
}
function setSvgEnabled() {
@ -302,6 +302,17 @@ setInterval(() => {
)
);
section.appendChild(
createSwitch(
"Start discord-screenaudio hidden to tray",
window.discordScreenaudioStartHidden,
(hidden) => {
window.discordScreenaudioStartHidden = hidden;
console.log(`!discord-screenaudio-starthidden-${hidden}`);
}
)
);
const divider = document.createElement("div");
divider.className = "divider-3nqZNm marginTop40-Q4o1tS";

View file

@ -57,11 +57,16 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
injectScriptText("vars.js",
QString("window.discordScreenaudioVersion = '%1'; "
"window.discordScreenaudioTrayEnabled = %2;")
"window.discordScreenaudioTrayEnabled = %2; "
"window.discordScreenaudioStartHidden = %3;")
.arg(QApplication::applicationVersion())
.arg(MainWindow::instance()
->settings()
->value("trayIcon", false)
.toBool())
.arg(MainWindow::instance()
->settings()
->value("startHidden", false)
.toBool()));
#ifdef KXMLGUI
@ -230,6 +235,10 @@ void DiscordPage::javaScriptConsoleMessage(
MainWindow::instance()->setTrayIcon(true);
} else if (message == "!discord-screenaudio-tray-false") {
MainWindow::instance()->setTrayIcon(false);
} else if (message == "!discord-screenaudio-starthidden-true") {
MainWindow::instance()->settings()->setValue("startHidden", true);
} else if (message == "!discord-screenaudio-starthidden-false") {
MainWindow::instance()->settings()->setValue("startHidden", false);
} else if (message.startsWith("dsa: ")) {
qDebug(userscriptLog) << message.mid(5).toUtf8().constData();
} else {

View file

@ -14,6 +14,7 @@
#include <QPushButton>
#include <QSpacerItem>
#include <QThread>
#include <QTimer>
#include <QUrl>
#include <QWebEngineNotification>
#include <QWebEngineProfile>
@ -34,6 +35,11 @@ MainWindow::MainWindow(bool useNotifySend, QWidget *parent)
setupTrayIcon();
resize(1000, 700);
showMaximized();
if (m_settings->value("trayIcon", false).toBool() &&
m_settings->value("startHidden", false).toBool()) {
hide();
QTimer::singleShot(0, [=]() { hide(); });
}
}
void MainWindow::setupWebView() {