Merge branch 'master' into virtmic-rewrite

This commit is contained in:
Malte Jürgens 2023-03-17 13:58:08 +01:00
commit e919e3ea25
No known key found for this signature in database
GPG Key ID: D29FBD5F93C0CFC3
10 changed files with 88 additions and 21 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/build
.vscode
/submodules/arrpc

1
assets/arrpc.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
setTimeout((i=>{let t,a,s,e={};new WebSocket("ws://127.0.0.1:1337").onmessage=async i=>{if(msg=JSON.parse(i.data),console.log(msg),!t){const i=window.webpackChunkdiscord_app.push([[Symbol()],{},i=>i]),e=i.c;window.webpackChunkdiscord_app.pop();for(const i in e){let a=e[i].exports;if(a=a&&(a.Z??a.ZP),a&&a.register&&a.wait){t=a;break}}const n=i.m;for(const t in n)if(n[t].toString().includes("getAssetImage: size must === [number, number] for Twitch")){const s=i(t),e=Object.values(s).find((i=>"function"==typeof i&&i.toString().includes("apply(")));a=async(i,t)=>(await e(i,[t,void 0]))[0];break}for(const t in n)if(n[t].toString().includes("e.application={")){const a=i(t),e=Object.values(a).find((i=>"function"==typeof i&&i.toString().includes("e.application={")));s=async i=>{let t={};return await e(t,i),t.application};break}}if(msg.activity?.assets?.large_image&&(msg.activity.assets.large_image=await a(msg.activity.application_id,msg.activity.assets.large_image)),msg.activity?.assets?.small_image&&(msg.activity.assets.small_image=await a(msg.activity.application_id,msg.activity.assets.small_image)),msg.activity){const i=msg.activity.application_id;e[i]||(e[i]=await s(i));const t=e[i];msg.activity.name||(msg.activity.name=t.name)}t.dispatch({type:"LOCAL_ACTIVITY_UPDATE",...msg})}}),1e4);

View File

@ -139,10 +139,12 @@ setTimeout(() => {
function main() {
userscript.muteToggled.connect(() => {
console.log("Toggling mute");
muteBtn && muteBtn.click();
});
userscript.deafenToggled.connect(() => {
console.log("Toggling deafen");
deafenBtn && deafenBtn.click();
});
@ -285,15 +287,11 @@ function main() {
}
muteBtn = buttonContainer
? buttonContainer.getElementsByClassName(
"button-12Fmur enabled-9OeuTA button-f2h6uQ lookBlank-21BCro colorBrand-I6CyqQ grow-2sR_-F"
)[0]
? buttonContainer.getElementsByTagName("button")[0]
: null;
deafenBtn = buttonContainer
? buttonContainer.getElementsByClassName(
"button-12Fmur enabled-9OeuTA button-f2h6uQ lookBlank-21BCro colorBrand-I6CyqQ grow-2sR_-F"
)[1]
? buttonContainer.getElementsByTagName("button")[1]
: null;
if (resolutionString) {
@ -330,17 +328,17 @@ function main() {
})
);
section.appendChild(
createButton("Install Theme", () => {
userscript.showThemeDialog();
})
);
// section.appendChild(
// createButton("Install Theme", () => {
// userscript.showThemeDialog();
// })
// );
section.appendChild(
createButton("Uninstall Theme", () => {
userscript.installUserStyles("");
})
);
// section.appendChild(
// createButton("Uninstall Theme", () => {
// userscript.installUserStyles("");
// })
// );
section.appendChild(
createSwitch(

View File

@ -2,6 +2,8 @@
<RCC>
<qresource>
<file>assets/userscript.js</file>
<file>assets/arrpc_bridge_mod.js</file>
<file>assets/arrpc.js</file>
<file>assets/de.shorsh.discord-screenaudio.png</file>
</qresource>
</RCC>

36
scripts/build_arrpc.sh Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/bash
set -e
cd "$(dirname "$0")/../submodules"
echo_status() {
echo
echo
echo "-> $1..."
}
if [ ! -d "arrpc" ]; then
echo_status "Cloning arRPC"
git clone https://github.com/OpenAsar/arrpc.git
cd arrpc
else
echo_status "Fetching arRPC changes"
cd arrpc
git fetch
fi
echo_status "Checking out latest commit"
git reset --hard HEAD
git checkout main
echo_status "Installing dependencies"
pnpm i -D @vercel/ncc
echo_status "Patching arRPC"
sed -i 's/"type": "module",//' package.json
echo_status "Building arRPC"
pnpm exec ncc build -m src/index.js
echo_status "Copying built file"
cp -v ./dist/index.js ../../assets/arrpc.js

View File

@ -9,6 +9,7 @@
#include <QFileInfo>
#include <QMessageBox>
#include <QNetworkReply>
#include <QTemporaryFile>
#include <QTimer>
#include <QWebChannel>
#include <QWebEngineScript>
@ -37,6 +38,7 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
":/assets/userscript.js");
setupUserStyles();
setupArrpc();
}
void DiscordPage::setupPermissions() {
@ -291,3 +293,19 @@ void DiscordPage::javaScriptConsoleMessage(
}
UserScript *DiscordPage::userScript() { return &m_userScript; }
void DiscordPage::setupArrpc() {
QFile nodejs("/usr/bin/node");
if (nodejs.exists()) {
auto arrpcSource = QTemporaryFile::createNativeFile(":/assets/arrpc.js");
qDebug(mainLog).noquote()
<< "NodeJS found, starting arRPC located at" << arrpcSource->fileName();
m_arrpcProcess.setProcessChannelMode(QProcess::ForwardedChannels);
m_arrpcProcess.setProgram(nodejs.fileName());
m_arrpcProcess.setArguments(QStringList{arrpcSource->fileName()});
m_arrpcProcess.start();
injectFile(&DiscordPage::injectScript, "arrpc_bridge_mod.js",
":/assets/arrpc_bridge_mod.js");
}
}

View File

@ -5,6 +5,7 @@
#include <QDir>
#include <QFile>
#include <QNetworkAccessManager>
#include <QProcess>
#include <QStandardPaths>
#include <QWebEngineFullScreenRequest>
#include <QWebEnginePage>
@ -22,10 +23,12 @@ private:
QFile *m_userStylesFile;
QString m_userStylesContent;
QNetworkAccessManager m_networkAccessManager;
QProcess m_arrpcProcess;
const QDir m_configLocation =
QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
void setupPermissions();
void setupUserStyles();
void setupArrpc();
void fetchUserStyles();
bool acceptNavigationRequest(const QUrl &url,
QWebEnginePage::NavigationType type,

View File

@ -30,8 +30,12 @@ MainWindow::MainWindow(bool useNotifySend, QWidget *parent)
m_centralWidget = new CentralWidget(this);
setCentralWidget(m_centralWidget);
setupTrayIcon();
resize(1000, 700);
showMaximized();
if (m_settings->contains("geometry")) {
restoreGeometry(m_settings->value("geometry").toByteArray());
} else {
resize(1000, 700);
showMaximized();
}
if (m_settings->value("trayIcon", false).toBool() &&
m_settings->value("startHidden", false).toBool()) {
hide();
@ -95,7 +99,8 @@ void MainWindow::cleanTrayIcon() {
}
void MainWindow::setupSettings() {
m_settings = new QSettings("maltejur", "discord-screenaudio", this);
m_settings =
new QSettings("discord-screenaudio", "discord-screenaudio", this);
m_settings->beginGroup("settings");
m_settings->endGroup();
}
@ -114,8 +119,10 @@ void MainWindow::setTrayIcon(bool enabled) {
void MainWindow::closeEvent(QCloseEvent *event) {
if (m_settings->value("trayIcon", false).toBool()) {
hide();
} else
} else {
m_settings->setValue("geometry", saveGeometry());
QApplication::quit();
}
}
MainWindow *MainWindow::instance() { return m_instance; }

View File

@ -66,7 +66,7 @@ void UserScript::setupShortcutsDialog() {
auto toggleDeafenAction = new QAction(this);
toggleDeafenAction->setText("Toggle Deafen");
toggleDeafenAction->setIcon(QIcon::fromTheme("audio-volume-muted"));
connect(toggleMuteAction, &QAction::triggered, this,
connect(toggleDeafenAction, &QAction::triggered, this,
&UserScript::deafenToggled);
m_actionCollection = new KActionCollection(this);