Add disable autogain

This commit is contained in:
smartfridge 2022-12-13 15:11:28 +01:00
parent dd79ad624c
commit 1f369dae11
7 changed files with 114 additions and 1 deletions

View file

@ -47,6 +47,8 @@
"settings-prfmMode-desc": "Performance mode is an experimental function that may either increase responsiveness and performance of\n ArmCord or... decrease it. Please try every option and see which fits you the best.",
"settings-prfmMode-performance": "Performance",
"settings-prfmMode-battery": "Battery",
"settings-disableAutogain": "Disable autogain",
"settings-disableAutogain-desc": "Disables autogain.",
"settings-trayIcon": "Tray icon",
"settings-trayIcon-desc": "Set the icon which will appear in tray menu.",
"settings-trayIcon-dynamic": "Dynamic",

View file

@ -0,0 +1,94 @@
// MIT License
// Copyright (c) 2021 Joseph Watts
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
function setLegacyChromeConstraint(constraint, name, value) {
if (constraint.mandatory && name in constraint.mandatory) {
constraint.mandatory[name] = value;
return;
}
if (constraint.optional) {
const element = constraint.optional.find((opt) => name in opt);
if (element) {
element[name] = value;
return;
}
}
// `mandatory` options throw errors for unknown keys, so avoid that by
// setting it under optional.
if (!constraint.optional) {
constraint.optional = [];
}
constraint.optional.push({[name]: value});
}
function setConstraint(constraint, name, value) {
if (constraint.advanced) {
const element = constraint.advanced.find((opt) => name in opt);
if (element) {
element[name] = value;
return;
}
}
constraint[name] = value;
}
function disableAutogain(constraints) {
console.log("Automatically unsetting gain!", constraints);
if (constraints && constraints.audio) {
if (typeof constraints.audio !== "object") {
constraints.audio = {};
}
if (constraints.audio.optional || constraints.audio.mandatory) {
setLegacyChromeConstraint(constraints.audio, "googAutoGainControl", false);
setLegacyChromeConstraint(constraints.audio, "googAutoGainControl2", false);
} else {
setConstraint(constraints.audio, "autoGainControl", false);
}
}
}
function patchFunction(object, name, createNewFunction) {
if (name in object) {
var original = object[name];
object[name] = createNewFunction(original);
}
}
patchFunction(navigator.mediaDevices, "getUserMedia", function (original) {
return function getUserMedia(constraints) {
disableAutogain(constraints);
return original.call(this, constraints);
};
});
function patchDeprecatedGetUserMedia(original) {
return function getUserMedia(constraints, success, error) {
disableAutogain(constraints);
return original.call(this, constraints, success, error);
};
}
patchFunction(navigator, "getUserMedia", patchDeprecatedGetUserMedia);
patchFunction(navigator, "mozGetUserMedia", patchDeprecatedGetUserMedia);
patchFunction(navigator, "webkitGetUserMedia", patchDeprecatedGetUserMedia);
patchFunction(MediaStreamTrack.prototype, "applyConstraints", function (original) {
return function applyConstraints(constraints) {
disableAutogain(constraints);
return original.call(this, constraints);
};
});
console.log("Disable Autogain by Joey Watts!", navigator.mediaDevices.getUserMedia);

View file

@ -156,6 +156,7 @@
automaticPatches: false,
performanceMode: "none",
alternativePaste: false,
disableAutogain: false,
startMinimized: false,
trayIcon: "default",
mods: options.mod,
@ -171,6 +172,7 @@
minimizeToTray: true,
automaticPatches: false,
mobileMode: false,
disableAutogain: false,
mods: "none",
startMinimized: false,
alternativePaste: false,

View file

@ -121,6 +121,9 @@ export function registerIpc() {
ipcMain.on("trayIcon", async (event, arg) => {
event.returnValue = await getConfig("trayIcon");
});
ipcMain.on("disableAutogain", async (event, arg) => {
event.returnValue = await getConfig("disableAutogain");
});
ipcMain.on("titlebar", (event, arg) => {
event.returnValue = customTitlebar;
});

View file

@ -57,7 +57,9 @@ if (window.location.href.indexOf("splash.html") > -1) {
});
})();
`);
if (ipcRenderer.sendSync("disableAutogain")) {
addScript(fs.readFileSync(path.join(__dirname, "../", "/content/js/disableAutogain.js"), "utf8"));
}
addScript(fs.readFileSync(path.join(__dirname, "../", "/content/js/rpc.js"), "utf8"));
const cssPath = path.join(__dirname, "../", "/content/css/discord.css");
addStyle(fs.readFileSync(cssPath, "utf8"));

View file

@ -96,6 +96,14 @@
</div>
<br />
<div class="switch acAutogain">
<label class="header" data-string="settings-disableAutogain"></label>
<input id="disableAutogain" class="tgl tgl-light left" data-setting="disableAutogain" type="checkbox" />
<label class="tgl-btn left" for="disableAutogain"></label>
<p class="description" data-string="settings-disableAutogain-desc"></p>
</div>
<br />
<div class="switch acChannel">
<select name="channel" data-setting="channel" class="left dropdown">
<option value="stable" selected>Stable</option>

View file

@ -50,6 +50,7 @@ export function setup() {
skipSplash: false,
inviteWebsocket: true,
startMinimized: false,
disableAutogain: false,
mobileMode: false,
trayIcon: "default",
doneSetup: false
@ -247,6 +248,7 @@ export interface Settings {
performanceMode: string;
startMinimized: boolean;
inviteWebsocket: boolean;
disableAutogain: boolean;
trayIcon: string;
doneSetup: boolean;
}