load userstyles on demand
This commit is contained in:
parent
78d43991ab
commit
63180f5d53
|
@ -157,6 +157,22 @@ function main() {
|
||||||
streamStartBtnClone.remove();
|
streamStartBtnClone.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function updateUserstyles() {
|
||||||
|
userscript.log("Loading userstyles...");
|
||||||
|
let stylesheet = document.getElementById("discordScreenaudioUserstyles");
|
||||||
|
if (!stylesheet) {
|
||||||
|
stylesheet = document.createElement("style");
|
||||||
|
stylesheet.id = "discordScreenaudioUserstyles";
|
||||||
|
stylesheet.type = "text/css";
|
||||||
|
document.head.appendChild(stylesheet);
|
||||||
|
}
|
||||||
|
stylesheet.innerText = userscript.userstyles;
|
||||||
|
userscript.log("Finished loading userstyles");
|
||||||
|
}
|
||||||
|
|
||||||
|
userscript.userstylesChanged.connect(updateUserstyles);
|
||||||
|
setTimeout(() => updateUserstyles());
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
const streamActive =
|
const streamActive =
|
||||||
document.getElementsByClassName("panel-2ZFCRb activityPanel-9icbyU")
|
document.getElementsByClassName("panel-2ZFCRb activityPanel-9icbyU")
|
||||||
|
|
|
@ -20,6 +20,8 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
|
||||||
|
|
||||||
connect(this, &QWebEnginePage::featurePermissionRequested, this,
|
connect(this, &QWebEnginePage::featurePermissionRequested, this,
|
||||||
&DiscordPage::featurePermissionRequested);
|
&DiscordPage::featurePermissionRequested);
|
||||||
|
connect(this, &DiscordPage::fullScreenRequested, MainWindow::instance(),
|
||||||
|
&MainWindow::fullScreenRequested);
|
||||||
|
|
||||||
setupPermissions();
|
setupPermissions();
|
||||||
|
|
||||||
|
@ -113,8 +115,8 @@ void DiscordPage::fetchUserStyles(QFile *file) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
injectFile(&DiscordPage::injectStylesheet, "userstyles.js", file->fileName());
|
qDebug(userstylesLog) << "Injecting userstyles";
|
||||||
file->close();
|
m_userScript.setProperty("userstyles", fileContent);
|
||||||
file->deleteLater();
|
file->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ UserScript::UserScript() : QObject() {
|
||||||
setupShortcutsDialog();
|
setupShortcutsDialog();
|
||||||
setupStreamDialog();
|
setupStreamDialog();
|
||||||
setupVirtmic();
|
setupVirtmic();
|
||||||
|
// connect(this, &UserScript::loadingMessageChanged, MainWindow::instance(),
|
||||||
|
// &MainWindow::setLoadingIndicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserScript::setupHelpMenu() {
|
void UserScript::setupHelpMenu() {
|
||||||
|
@ -162,4 +164,4 @@ void UserScript::showStreamDialog() {
|
||||||
else
|
else
|
||||||
m_streamDialog->activateWindow();
|
m_streamDialog->activateWindow();
|
||||||
m_streamDialog->updateTargets();
|
m_streamDialog->updateTargets();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,12 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef KNOTIFICATIONS
|
||||||
|
#include <KNotification>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <KJob>
|
||||||
|
|
||||||
class UserScript : public QObject {
|
class UserScript : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -27,18 +33,26 @@ public:
|
||||||
Q_PROPERTY(QString version READ version CONSTANT);
|
Q_PROPERTY(QString version READ version CONSTANT);
|
||||||
Q_PROPERTY(bool kxmlgui MEMBER m_kxmlgui CONSTANT);
|
Q_PROPERTY(bool kxmlgui MEMBER m_kxmlgui CONSTANT);
|
||||||
Q_PROPERTY(bool kglobalaccel MEMBER m_kglobalaccel CONSTANT);
|
Q_PROPERTY(bool kglobalaccel MEMBER m_kglobalaccel CONSTANT);
|
||||||
|
Q_PROPERTY(QString userstyles MEMBER m_userstyles NOTIFY userstylesChanged);
|
||||||
|
Q_PROPERTY(QString loadingMessage MEMBER m_loadingMessage NOTIFY
|
||||||
|
loadingMessageChanged);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QProcess m_virtmicProcess;
|
QProcess m_virtmicProcess;
|
||||||
StreamDialog *m_streamDialog;
|
StreamDialog *m_streamDialog;
|
||||||
bool m_kxmlgui = false;
|
bool m_kxmlgui = false;
|
||||||
bool m_kglobalaccel = false;
|
bool m_kglobalaccel = false;
|
||||||
|
QString m_userstyles;
|
||||||
|
QString m_loadingMessage;
|
||||||
#ifdef KXMLGUI
|
#ifdef KXMLGUI
|
||||||
KHelpMenu *m_helpMenu;
|
KHelpMenu *m_helpMenu;
|
||||||
#ifdef KGLOBALACCEL
|
#ifdef KGLOBALACCEL
|
||||||
KActionCollection *m_actionCollection;
|
KActionCollection *m_actionCollection;
|
||||||
KShortcutsDialog *m_shortcutsDialog;
|
KShortcutsDialog *m_shortcutsDialog;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifdef KNOTIFICATIONS
|
||||||
|
KJob *m_loadingJob = nullptr;
|
||||||
#endif
|
#endif
|
||||||
void setupHelpMenu();
|
void setupHelpMenu();
|
||||||
void setupShortcutsDialog();
|
void setupShortcutsDialog();
|
||||||
|
@ -49,6 +63,8 @@ Q_SIGNALS:
|
||||||
void muteToggled();
|
void muteToggled();
|
||||||
void deafenToggled();
|
void deafenToggled();
|
||||||
void streamStarted(bool video, int width, int height, int frameRate);
|
void streamStarted(bool video, int width, int height, int frameRate);
|
||||||
|
void userstylesChanged();
|
||||||
|
void loadingMessageChanged();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void log(QString message);
|
void log(QString message);
|
||||||
|
|
Loading…
Reference in New Issue