From 55c77395bb5a0ec0a9cc99852cd803b2cfe51bda Mon Sep 17 00:00:00 2001 From: aiek Date: Fri, 26 Jul 2024 19:14:58 +0300 Subject: [PATCH] Upload files to 'src/renderer/patches' --- src/renderer/patches/screenShareFixes.ts | 69 ++++++++++++++++++++ src/renderer/patches/shared.ts | 30 +++++++++ src/renderer/patches/spellCheck.tsx | 82 ++++++++++++++++++++++++ src/renderer/patches/windowsTitleBar.tsx | 30 +++++++++ 4 files changed, 211 insertions(+) create mode 100644 src/renderer/patches/screenShareFixes.ts create mode 100644 src/renderer/patches/shared.ts create mode 100644 src/renderer/patches/spellCheck.tsx create mode 100644 src/renderer/patches/windowsTitleBar.tsx diff --git a/src/renderer/patches/screenShareFixes.ts b/src/renderer/patches/screenShareFixes.ts new file mode 100644 index 0000000..caf11bb --- /dev/null +++ b/src/renderer/patches/screenShareFixes.ts @@ -0,0 +1,69 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Aerocord, a vesktop fork for older microsoft NT releases such as NT 6.0, 6.1, 6.2 and 6.3. + * Credits to vendicated and the rest of the vesktop contribuitors for making Vesktop! + */ + +import { Logger } from "@vencord/types/utils"; +import { currentSettings } from "renderer/components/ScreenSharePicker"; +import { isLinux } from "renderer/utils"; + +const logger = new Logger("VesktopStreamFixes"); + +if (isLinux) { + const original = navigator.mediaDevices.getDisplayMedia; + + async function getVirtmic() { + try { + const devices = await navigator.mediaDevices.enumerateDevices(); + const audioDevice = devices.find(({ label }) => label === "vencord-screen-share"); + return audioDevice?.deviceId; + } catch (error) { + return null; + } + } + + navigator.mediaDevices.getDisplayMedia = async function (opts) { + const stream = await original.call(this, opts); + const id = await getVirtmic(); + + const frameRate = Number(currentSettings?.fps); + const height = Number(currentSettings?.resolution); + const width = Math.round(height * (16 / 9)); + const track = stream.getVideoTracks()[0]; + + track.contentHint = String(currentSettings?.contentHint); + + const constraints = { + ...track.getConstraints(), + frameRate, + width: { min: 640, ideal: width, max: width }, + height: { min: 480, ideal: height, max: height }, + advanced: [{ width: width, height: height }], + resizeMode: "none" + }; + + track + .applyConstraints(constraints) + .then(() => { + logger.info("Applied constraints successfully. New constraints: ", track.getConstraints()); + }) + .catch(e => logger.error("Failed to apply constraints.", e)); + + if (id) { + const audio = await navigator.mediaDevices.getUserMedia({ + audio: { + deviceId: { + exact: id + }, + autoGainControl: false, + echoCancellation: false, + noiseSuppression: false + } + }); + audio.getAudioTracks().forEach(t => stream.addTrack(t)); + } + + return stream; + }; +} diff --git a/src/renderer/patches/shared.ts b/src/renderer/patches/shared.ts new file mode 100644 index 0000000..056e91d --- /dev/null +++ b/src/renderer/patches/shared.ts @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Aerocord, a vesktop fork for older microsoft NT releases such as NT 6.0, 6.1, 6.2 and 6.3. + * Credits to vendicated and the rest of the vesktop contribuitors for making Vesktop! + */ + +import { Patch } from "@vencord/types/utils/types"; + +window.VCDP = {}; + +interface PatchData { + patches: Omit[]; + [key: string]: any; +} + +export function addPatch

(p: P) { + const { patches, ...globals } = p; + + for (const patch of patches as Patch[]) { + if (!Array.isArray(patch.replacement)) patch.replacement = [patch.replacement]; + for (const r of patch.replacement) { + if (typeof r.replace === "string") r.replace = r.replace.replaceAll("$self", "VCDP"); + } + + patch.plugin = "Vesktop"; + Vencord.Plugins.patches.push(patch); + } + + Object.assign(VCDP, globals); +} diff --git a/src/renderer/patches/spellCheck.tsx b/src/renderer/patches/spellCheck.tsx new file mode 100644 index 0000000..6234359 --- /dev/null +++ b/src/renderer/patches/spellCheck.tsx @@ -0,0 +1,82 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Aerocord, a vesktop fork for older microsoft NT releases such as NT 6.0, 6.1, 6.2 and 6.3. + * Credits to vendicated and the rest of the vesktop contribuitors for making Vesktop! + */ + +import { addContextMenuPatch } from "@vencord/types/api/ContextMenu"; +import { findStoreLazy } from "@vencord/types/webpack"; +import { FluxDispatcher, Menu, useStateFromStores } from "@vencord/types/webpack/common"; + +import { addPatch } from "./shared"; + +let word: string; +let corrections: string[]; + +const SpellCheckStore = findStoreLazy("SpellcheckStore"); + +// Make spellcheck suggestions work +addPatch({ + patches: [ + { + find: ".enableSpellCheck)", + replacement: { + // if (isDesktop) { DiscordNative.onSpellcheck(openMenu(props)) } else { e.preventDefault(); openMenu(props) } + match: /else (.{1,3})\.preventDefault\(\),(.{1,3}\(.{1,3}\))(?<=:(.{1,3})\.enableSpellCheck\).+?)/, + // ... else { $self.onSlateContext(() => openMenu(props)) } + replace: "else {$self.onSlateContext($1, $3?.enableSpellCheck, () => $2)}" + } + } + ], + + onSlateContext(e: MouseEvent, hasSpellcheck: boolean | undefined, openMenu: () => void) { + if (!hasSpellcheck) { + e.preventDefault(); + openMenu(); + return; + } + + const cb = (w: string, c: string[]) => { + VesktopNative.spellcheck.offSpellcheckResult(cb); + word = w; + corrections = c; + openMenu(); + }; + VesktopNative.spellcheck.onSpellcheckResult(cb); + } +}); + +addContextMenuPatch("textarea-context", children => { + const spellCheckEnabled = useStateFromStores([SpellCheckStore], () => SpellCheckStore.isEnabled()); + const hasCorrections = Boolean(word && corrections?.length); + + children.push( + + {hasCorrections && ( + <> + {corrections.map(c => ( + VesktopNative.spellcheck.replaceMisspelling(c)} + /> + ))} + + VesktopNative.spellcheck.addToDictionary(word)} + /> + + )} + { + FluxDispatcher.dispatch({ type: "SPELLCHECK_TOGGLE" }); + }} + /> + + ); +}); diff --git a/src/renderer/patches/windowsTitleBar.tsx b/src/renderer/patches/windowsTitleBar.tsx new file mode 100644 index 0000000..25d8aff --- /dev/null +++ b/src/renderer/patches/windowsTitleBar.tsx @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Aerocord, a vesktop fork for older microsoft NT releases such as NT 6.0, 6.1, 6.2 and 6.3. + * Credits to vendicated and the rest of the vesktop contribuitors for making Vesktop! + */ + +import { Settings } from "renderer/settings"; + +import { addPatch } from "./shared"; + +if (Settings.store.customTitleBar) + addPatch({ + patches: [ + { + find: ".wordmarkWindows", + replacement: [ + { + // TODO: Fix eslint rule + // eslint-disable-next-line no-useless-escape + match: /case \i\.\i\.WINDOWS:/, + replace: 'case "WEB":' + }, + ...["close", "minimize", "maximize"].map(op => ({ + match: new RegExp(String.raw`\i\.\i\.${op}\b`), + replace: `VesktopNative.win.${op}` + })) + ] + } + ] + });