Merge branch 'arrpc'

This commit is contained in:
Malte Jürgens 2023-03-04 13:15:11 +01:00
commit 4b782133ae
No known key found for this signature in database
GPG Key ID: D29FBD5F93C0CFC3
7 changed files with 5695 additions and 4 deletions

1
.gitignore vendored
View File

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

5635
assets/arrpc.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,8 @@
<RCC>
<qresource>
<file>assets/userscript.js</file>
<file>assets/bridge_mod.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 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>
@ -36,10 +37,8 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
injectFile(&DiscordPage::injectScript, "userscript.js",
":/assets/userscript.js");
injectFile(&DiscordPage::injectScript, "bridge_mod.js",
":/assets/bridge_mod.js");
setupUserStyles();
setupArrpc();
}
void DiscordPage::setupPermissions() {
@ -294,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,