Compare commits
	
		
			9 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | e3d87e8202 | ||
|  | 700d576ff8 | ||
|  | 906deee580 | ||
|  | 9d9e57df1e | ||
|  | 9eae8bbe4f | ||
|  | 0493a76117 | ||
|  | 100f9bf58e | ||
|  | 1eda9d75b0 | ||
|  | f750b76068 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +1,3 @@ | ||||
| /build | ||||
| .vscode | ||||
| /submodules/Vencord | ||||
|   | ||||
							
								
								
									
										43
									
								
								assets/vencord/VencordNativeStub.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								assets/vencord/VencordNativeStub.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| let webclass; | ||||
|  | ||||
| const promise = new Promise((resolve) => { | ||||
|   setTimeout(() => { | ||||
|     new QWebChannel(qt.webChannelTransport, function (channel) { | ||||
|       webclass = channel.objects.webclass; | ||||
|       resolve(); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| async function prepareWebclass() { | ||||
|   if (!webclass) await promise; | ||||
| } | ||||
|  | ||||
| window.VencordNative = { | ||||
|   getVersions: () => ({}), | ||||
|   ipc: { | ||||
|     send: async (event: string, ...args: any[]) => { | ||||
|       await prepareWebclass(); | ||||
|       webclass.vencordSend(event, args); | ||||
|     }, | ||||
|     sendSync: (event: string, ...args: any[]) => { | ||||
|       // We need this hack because Vencord requires its settings right when it starts | ||||
|       if (event === "VencordGetSettings") { | ||||
|         return window.discordScreenaudioVencordSettings || "{}"; | ||||
|       } else throw new Error("Synchroneous IPC not implemented"); | ||||
|     }, | ||||
|     on(event: string, listener: () => {}) { | ||||
|       // TODO quickCss | ||||
|     }, | ||||
|     off(event: string, listener: () => {}) { | ||||
|       // not used for now | ||||
|     }, | ||||
|     invoke: async (event: string, ...args: any[]) => { | ||||
|       await prepareWebclass(); | ||||
|       if (event === "VencordSetSettings") { | ||||
|         window.discordScreenaudioVencordSettings = args[0]; | ||||
|       } | ||||
|       return webclass.vencordSend(event, args); | ||||
|     }, | ||||
|   }, | ||||
| }; | ||||
							
								
								
									
										14
									
								
								assets/vencord/plugin.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								assets/vencord/plugin.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| import definePlugin from "../utils/types"; | ||||
|  | ||||
| export default definePlugin({ | ||||
|   name: "discord-screenaudio", | ||||
|   authors: [ | ||||
|     { | ||||
|       name: "maltejur", | ||||
|       id: 205966226709676032n, | ||||
|     }, | ||||
|   ], | ||||
|   required: true, | ||||
|   description: "UI patches for discord-screenaudio.", | ||||
|   patches: [], | ||||
| }); | ||||
							
								
								
									
										15
									
								
								assets/vencord/settings.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								assets/vencord/settings.patch
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| --- a/src/components/VencordSettings/VencordTab.tsx | ||||
| +++ b/src/components/VencordSettings/VencordTab.tsx | ||||
| @@ -87,10 +87,10 @@ function VencordSettings() { | ||||
|                  <Card className={cl("quick-actions-card")}> | ||||
|                      {IS_WEB ? ( | ||||
|                          <Button | ||||
| -                            onClick={() => require("../Monaco").launchMonacoEditor()} | ||||
| +                            onClick={() => VencordNative.ipc.send(IpcEvents.OPEN_EXTERNAL, settingsDir)} | ||||
|                              size={Button.Sizes.SMALL} | ||||
|                              disabled={settingsDir === "Loading..."}> | ||||
| -                            Open QuickCSS File | ||||
| +                            Launch Directory | ||||
|                          </Button> | ||||
|                      ) : ( | ||||
|                          <React.Fragment> | ||||
							
								
								
									
										410
									
								
								assets/vencord/vencord.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										410
									
								
								assets/vencord/vencord.js
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @@ -2,6 +2,7 @@ | ||||
| <RCC> | ||||
|   <qresource> | ||||
|     <file>assets/userscript.js</file> | ||||
|     <file>assets/vencord/vencord.js</file> | ||||
|     <file>assets/de.shorsh.discord-screenaudio.png</file> | ||||
|   </qresource> | ||||
| </RCC> | ||||
							
								
								
									
										39
									
								
								scripts/build_vencord.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										39
									
								
								scripts/build_vencord.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| #!/usr/bin/bash | ||||
| set -e | ||||
|  | ||||
| cd "$(dirname "$0")/../submodules" | ||||
|  | ||||
| echo_status() { | ||||
|   echo | ||||
|   echo | ||||
|   echo "-> $1..." | ||||
| } | ||||
|  | ||||
| if [ ! -d "Vencord" ]; then | ||||
|   echo_status "Cloning Vencord" | ||||
|   git clone https://github.com/Vendicated/Vencord.git | ||||
|   cd Vencord | ||||
| else | ||||
|   echo_status "Fetching Vencord changes" | ||||
|   cd Vencord | ||||
|   git fetch | ||||
| fi | ||||
|  | ||||
| echo_status "Checking out latest commit" | ||||
| git reset --hard HEAD | ||||
| git checkout main | ||||
| git reset --hard devbuild | ||||
|  | ||||
| echo_status "Installing dependencies" | ||||
| pnpm i | ||||
|  | ||||
| echo_status "Patching Vencord" | ||||
| cp -v ../../assets/vencord/plugin.js ./src/plugins/discord-screenaudio.js | ||||
| cp -v ../../assets/vencord/VencordNativeStub.ts ./browser/VencordNativeStub.ts | ||||
| patch -p1 -i ../../assets/vencord/settings.patch | ||||
|  | ||||
| echo_status "Building Vencord" | ||||
| pnpm run buildWeb | ||||
|  | ||||
| echo_status "Copying built file" | ||||
| cp -v ./dist/browser.js ../../assets/vencord/vencord.js | ||||
| @@ -34,6 +34,19 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) { | ||||
|   injectFile(&DiscordPage::injectScript, "userscript.js", | ||||
|              ":/assets/userscript.js"); | ||||
|  | ||||
|   injectFile(&DiscordPage::injectScript, "userscript.js", | ||||
|              ":/assets/userscript.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()); | ||||
|   injectScript( | ||||
|       "vencord.js", | ||||
|       QString("window.discordScreenaudioVencordSettings = `%1`; %2") | ||||
|           .arg(m_userScript.vencordSend("VencordGetSettings", {}).toString(), | ||||
|                vencord.readAll())); | ||||
|   vencord.close(); | ||||
|  | ||||
|   setupUserStyles(); | ||||
| } | ||||
|  | ||||
| @@ -210,7 +223,9 @@ void DiscordPage::javaScriptConsoleMessage( | ||||
|       } | ||||
|     } | ||||
|     qDebug(discordLog) << (ansi + lines[0].trimmed() + "\033[0m " + | ||||
|                            lines[endOfStyles].trimmed()) | ||||
|                            ((lines.length() > endOfStyles) | ||||
|                                 ? lines[endOfStyles].trimmed() | ||||
|                                 : "")) | ||||
|                               .toUtf8() | ||||
|                               .constData(); | ||||
|     for (auto line : lines.mid(endOfStyles + 1)) { | ||||
|   | ||||
| @@ -1,6 +1,8 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "streamdialog.h" | ||||
| #include "userscript.h" | ||||
| #include "virtmic.h" | ||||
|  | ||||
| #include <QWebEngineFullScreenRequest> | ||||
| #include <QWebEnginePage> | ||||
|   | ||||
| @@ -4,6 +4,10 @@ | ||||
|  | ||||
| #include <QApplication> | ||||
| #include <QDebug> | ||||
| #include <QDesktopServices> | ||||
| #include <QDir> | ||||
| #include <QFile> | ||||
| #include <QStandardPaths> | ||||
| #include <QTimer> | ||||
|  | ||||
| #ifdef KXMLGUI | ||||
| @@ -162,4 +166,69 @@ void UserScript::showStreamDialog() { | ||||
|   else | ||||
|     m_streamDialog->activateWindow(); | ||||
|   m_streamDialog->updateTargets(); | ||||
| } | ||||
| } | ||||
|  | ||||
| QVariant UserScript::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") { | ||||
|     return true; | ||||
|   } | ||||
|   if (event == "VencordGetSettingsDir") { | ||||
|     return configFolder; | ||||
|   } | ||||
|   if (event == "VencordGetQuickCss") { | ||||
|     if (QFile::exists(quickCssFile)) { | ||||
|       QFile file(quickCssFile); | ||||
|       if (!file.open(QIODevice::ReadOnly)) | ||||
|         qFatal("Failed to load %s with error: %s", | ||||
|                quickCssFile.toLatin1().constData(), | ||||
|                file.errorString().toLatin1().constData()); | ||||
|       auto content = file.readAll(); | ||||
|       file.close(); | ||||
|       return QString(content); | ||||
|     } else | ||||
|       return ""; | ||||
|   } | ||||
|   if (event == "VencordGetSettings") { | ||||
|     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") { | ||||
|     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; | ||||
|   } | ||||
|   if (event == "VencordGetUpdates") { | ||||
|     return QVariantMap{{"ok", true}, {"value", QVariantList()}}; | ||||
|   } | ||||
|   if (event == "VencordOpenExternal") { | ||||
|     QDesktopServices::openUrl(QUrl(args[0].toString())); | ||||
|     return true; | ||||
|   } | ||||
|   if (event == "VencordOpenQuickCss") { | ||||
|     return true; | ||||
|   } | ||||
|   assert(false); | ||||
| } | ||||
|   | ||||
| @@ -40,6 +40,7 @@ private: | ||||
|   KShortcutsDialog *m_shortcutsDialog; | ||||
| #endif | ||||
| #endif | ||||
|   QString m_vencordSettings; | ||||
|   void setupHelpMenu(); | ||||
|   void setupShortcutsDialog(); | ||||
|   void setupStreamDialog(); | ||||
| @@ -62,6 +63,7 @@ public Q_SLOTS: | ||||
|   void showStreamDialog(); | ||||
|   void stopVirtmic(); | ||||
|   void startVirtmic(QString target); | ||||
|   QVariant vencordSend(QString event, QVariantList args); | ||||
|  | ||||
| private Q_SLOTS: | ||||
|   void startStream(bool video, bool audio, int width, int height, int frameRate, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user