further work on vencord
This commit is contained in:
parent
0493a76117
commit
9eae8bbe4f
|
@ -21,9 +21,9 @@ window.VencordNative = {
|
||||||
webclass.vencordSend(event, args);
|
webclass.vencordSend(event, args);
|
||||||
},
|
},
|
||||||
sendSync: (event: string, ...args: any[]) => {
|
sendSync: (event: string, ...args: any[]) => {
|
||||||
|
// We need this hack because Vencord requires its settings right when it starts
|
||||||
if (event === "VencordGetSettings") {
|
if (event === "VencordGetSettings") {
|
||||||
console.log("stub: IPC VencordGetSettings");
|
return window.discordScreenaudioVencordSettings || "{}";
|
||||||
return "{}";
|
|
||||||
} else throw new Error("Synchroneous IPC not implemented");
|
} else throw new Error("Synchroneous IPC not implemented");
|
||||||
},
|
},
|
||||||
on(event: string, listener: () => {}) {
|
on(event: string, listener: () => {}) {
|
||||||
|
@ -34,6 +34,9 @@ window.VencordNative = {
|
||||||
},
|
},
|
||||||
invoke: async (event: string, ...args: any[]) => {
|
invoke: async (event: string, ...args: any[]) => {
|
||||||
await prepareWebclass();
|
await prepareWebclass();
|
||||||
|
if (event === "VencordSetSettings") {
|
||||||
|
window.discordScreenaudioVencordSettings = args[0];
|
||||||
|
}
|
||||||
return webclass.vencordSend(event, args);
|
return webclass.vencordSend(event, args);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx
|
||||||
|
index 8ffe111..8f037bd 100644
|
||||||
|
--- a/src/components/Settings.tsx
|
||||||
|
+++ b/src/components/Settings.tsx
|
||||||
|
@@ -61,37 +61,22 @@ export default ErrorBoundary.wrap(function Settings() {
|
||||||
|
Settings Directory: <code style={{ userSelect: "text", cursor: "text" }}>{settingsDir}</code>
|
||||||
|
</Forms.FormText>
|
||||||
|
|
||||||
|
- {!IS_WEB && <Flex className={Margins.marginBottom20} style={{ marginTop: 8 }}>
|
||||||
|
+ <Flex className={Margins.marginBottom20} style={{ marginTop: 8 }}>
|
||||||
|
<Button
|
||||||
|
- onClick={() => window.DiscordNative.app.relaunch()}
|
||||||
|
- size={Button.Sizes.SMALL}
|
||||||
|
- color={Button.Colors.GREEN}
|
||||||
|
- >
|
||||||
|
- Reload
|
||||||
|
- </Button>
|
||||||
|
- <Button
|
||||||
|
- onClick={() => window.DiscordNative.fileManager.showItemInFolder(settingsDir)}
|
||||||
|
+ onClick={() => VencordNative.ipc.send(IpcEvents.OPEN_EXTERNAL, settingsDir)}
|
||||||
|
size={Button.Sizes.SMALL}
|
||||||
|
disabled={settingsDirPending}
|
||||||
|
>
|
||||||
|
Launch Directory
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
- onClick={() => VencordNative.ipc.invoke(IpcEvents.OPEN_MONACO_EDITOR)}
|
||||||
|
+ onClick={() => VencordNative.ipc.send(IpcEvents.OPEN_EXTERNAL, settingsDir + "/quickCss.css")}
|
||||||
|
size={Button.Sizes.SMALL}
|
||||||
|
disabled={settingsDir === "Loading..."}
|
||||||
|
>
|
||||||
|
Open QuickCSS File
|
||||||
|
</Button>
|
||||||
|
- </Flex>}
|
||||||
|
-
|
||||||
|
- {IS_WEB && <Button
|
||||||
|
- onClick={launchMonacoEditor}
|
||||||
|
- size={Button.Sizes.SMALL}
|
||||||
|
- disabled={settingsDir === "Loading..."}
|
||||||
|
- >
|
||||||
|
- Open QuickCSS File
|
||||||
|
- </Button>}
|
||||||
|
+ </Flex>
|
||||||
|
|
||||||
|
<Forms.FormDivider />
|
||||||
|
<Switch
|
File diff suppressed because one or more lines are too long
|
@ -22,7 +22,7 @@ fi
|
||||||
echo_status "Checking out latest commit"
|
echo_status "Checking out latest commit"
|
||||||
git reset --hard HEAD
|
git reset --hard HEAD
|
||||||
git checkout main
|
git checkout main
|
||||||
git reset --hard origin/main
|
git reset --hard devbuild
|
||||||
|
|
||||||
echo_status "Installing dependencies"
|
echo_status "Installing dependencies"
|
||||||
pnpm i
|
pnpm i
|
||||||
|
@ -30,6 +30,7 @@ pnpm i
|
||||||
echo_status "Patching Vencord"
|
echo_status "Patching Vencord"
|
||||||
cp -v ../../assets/vencord/plugin.js ./src/plugins/discord-screenaudio.js
|
cp -v ../../assets/vencord/plugin.js ./src/plugins/discord-screenaudio.js
|
||||||
cp -v ../../assets/vencord/VencordNativeStub.ts ./browser/VencordNativeStub.ts
|
cp -v ../../assets/vencord/VencordNativeStub.ts ./browser/VencordNativeStub.ts
|
||||||
|
patch -p1 -i ../../assets/vencord/settings.patch
|
||||||
|
|
||||||
echo_status "Building Vencord"
|
echo_status "Building Vencord"
|
||||||
pnpm run buildWeb
|
pnpm run buildWeb
|
||||||
|
|
|
@ -59,7 +59,16 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
|
||||||
webChannel()->registerObject("webclass", &m_webClass);
|
webChannel()->registerObject("webclass", &m_webClass);
|
||||||
|
|
||||||
injectScriptFile("userscript.js", ":/assets/userscript.js");
|
injectScriptFile("userscript.js", ":/assets/userscript.js");
|
||||||
injectScriptFile("vencord.js", ":/assets/vencord/vencord.js");
|
QFile vencord(":/assets/vencord/vencord.js");
|
||||||
|
if (!vencord.open(QIODevice::ReadOnly))
|
||||||
|
qFatal("Failed to load vencord source with error: %s",
|
||||||
|
vencord.errorString().toLatin1().constData());
|
||||||
|
injectScriptText(
|
||||||
|
"vencord.js",
|
||||||
|
QString("window.discordScreenaudioVencordSettings = `%1`; %2")
|
||||||
|
.arg(m_webClass.vencordSend("VencordGetSettings", {}).toString(),
|
||||||
|
vencord.readAll()));
|
||||||
|
vencord.close();
|
||||||
|
|
||||||
injectScriptText("version.js",
|
injectScriptText("version.js",
|
||||||
QString("window.discordScreenaudioVersion = '%1';")
|
QString("window.discordScreenaudioVersion = '%1';")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "webclass.h"
|
#include "webclass.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -7,19 +8,28 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
QVariant WebClass::vencordSend(QString event, QVariantList args) {
|
QVariant WebClass::vencordSend(QString event, QVariantList args) {
|
||||||
|
QString configFolder =
|
||||||
|
QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) +
|
||||||
|
"/vencord";
|
||||||
|
QString quickCssFile = configFolder + "/quickCss.css";
|
||||||
|
QString settingsFile = configFolder + "/settings.json";
|
||||||
|
|
||||||
|
if (!QDir().exists(configFolder))
|
||||||
|
QDir().mkpath(configFolder);
|
||||||
|
|
||||||
if (event == "VencordGetRepo") {
|
if (event == "VencordGetRepo") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (event == "VencordGetSettingsDir") {
|
if (event == "VencordGetSettingsDir") {
|
||||||
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
return configFolder;
|
||||||
}
|
}
|
||||||
if (event == "VencordGetQuickCss") {
|
if (event == "VencordGetQuickCss") {
|
||||||
QString filename =
|
if (QFile::exists(quickCssFile)) {
|
||||||
QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) +
|
QFile file(quickCssFile);
|
||||||
"/vencord/quickCss.css";
|
if (!file.open(QIODevice::WriteOnly))
|
||||||
if (QFile::exists(filename)) {
|
qFatal("Failed to load %s with error: %s",
|
||||||
QFile file(filename);
|
quickCssFile.toLatin1().constData(),
|
||||||
file.open(QIODevice::ReadOnly);
|
file.errorString().toLatin1().constData());
|
||||||
auto content = file.readAll();
|
auto content = file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
return QString(content);
|
return QString(content);
|
||||||
|
@ -27,10 +37,26 @@ QVariant WebClass::vencordSend(QString event, QVariantList args) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if (event == "VencordGetSettings") {
|
if (event == "VencordGetSettings") {
|
||||||
return m_vencordSettings;
|
if (QFile::exists(settingsFile)) {
|
||||||
|
QFile file(settingsFile);
|
||||||
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
|
qFatal("Failed to load %s with error: %s",
|
||||||
|
settingsFile.toLatin1().constData(),
|
||||||
|
file.errorString().toLatin1().constData());
|
||||||
|
auto content = file.readAll();
|
||||||
|
file.close();
|
||||||
|
return QString(content);
|
||||||
|
} else
|
||||||
|
return "{}";
|
||||||
}
|
}
|
||||||
if (event == "VencordSetSettings") {
|
if (event == "VencordSetSettings") {
|
||||||
m_vencordSettings = args[0].toString();
|
QFile file(settingsFile);
|
||||||
|
if (!file.open(QIODevice::WriteOnly))
|
||||||
|
qFatal("Failed to load %s with error: %s",
|
||||||
|
settingsFile.toLatin1().constData(),
|
||||||
|
file.errorString().toLatin1().constData());
|
||||||
|
file.write(args[0].toString().toUtf8());
|
||||||
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (event == "VencordGetUpdates") {
|
if (event == "VencordGetUpdates") {
|
||||||
|
|
Loading…
Reference in New Issue