mirror of
				https://github.com/smartfrigde/armcord.git
				synced 2024-08-14 23:56:58 +00:00 
			
		
		
		
	Add disable autogain
This commit is contained in:
		
							parent
							
								
									dd79ad624c
								
							
						
					
					
						commit
						1f369dae11
					
				
					 7 changed files with 114 additions and 1 deletions
				
			
		|  | @ -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-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-performance": "Performance", | ||||||
|     "settings-prfmMode-battery": "Battery", |     "settings-prfmMode-battery": "Battery", | ||||||
|  |     "settings-disableAutogain": "Disable autogain", | ||||||
|  |     "settings-disableAutogain-desc": "Disables autogain.", | ||||||
|     "settings-trayIcon": "Tray icon", |     "settings-trayIcon": "Tray icon", | ||||||
|     "settings-trayIcon-desc": "Set the icon which will appear in tray menu.", |     "settings-trayIcon-desc": "Set the icon which will appear in tray menu.", | ||||||
|     "settings-trayIcon-dynamic": "Dynamic", |     "settings-trayIcon-dynamic": "Dynamic", | ||||||
|  |  | ||||||
							
								
								
									
										94
									
								
								src/content/js/disableAutogain.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/content/js/disableAutogain.js
									
										
									
									
									
										Normal 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); | ||||||
|  | @ -156,6 +156,7 @@ | ||||||
|                             automaticPatches: false, |                             automaticPatches: false, | ||||||
|                             performanceMode: "none", |                             performanceMode: "none", | ||||||
|                             alternativePaste: false, |                             alternativePaste: false, | ||||||
|  |                             disableAutogain: false, | ||||||
|                             startMinimized: false, |                             startMinimized: false, | ||||||
|                             trayIcon: "default", |                             trayIcon: "default", | ||||||
|                             mods: options.mod, |                             mods: options.mod, | ||||||
|  | @ -171,6 +172,7 @@ | ||||||
|                         minimizeToTray: true, |                         minimizeToTray: true, | ||||||
|                         automaticPatches: false, |                         automaticPatches: false, | ||||||
|                         mobileMode: false, |                         mobileMode: false, | ||||||
|  |                         disableAutogain: false, | ||||||
|                         mods: "none", |                         mods: "none", | ||||||
|                         startMinimized: false, |                         startMinimized: false, | ||||||
|                         alternativePaste: false, |                         alternativePaste: false, | ||||||
|  |  | ||||||
|  | @ -121,6 +121,9 @@ export function registerIpc() { | ||||||
|     ipcMain.on("trayIcon", async (event, arg) => { |     ipcMain.on("trayIcon", async (event, arg) => { | ||||||
|         event.returnValue = await getConfig("trayIcon"); |         event.returnValue = await getConfig("trayIcon"); | ||||||
|     }); |     }); | ||||||
|  |     ipcMain.on("disableAutogain", async (event, arg) => { | ||||||
|  |         event.returnValue = await getConfig("disableAutogain"); | ||||||
|  |     }); | ||||||
|     ipcMain.on("titlebar", (event, arg) => { |     ipcMain.on("titlebar", (event, arg) => { | ||||||
|         event.returnValue = customTitlebar; |         event.returnValue = customTitlebar; | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  | @ -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")); |         addScript(fs.readFileSync(path.join(__dirname, "../", "/content/js/rpc.js"), "utf8")); | ||||||
|         const cssPath = path.join(__dirname, "../", "/content/css/discord.css"); |         const cssPath = path.join(__dirname, "../", "/content/css/discord.css"); | ||||||
|         addStyle(fs.readFileSync(cssPath, "utf8")); |         addStyle(fs.readFileSync(cssPath, "utf8")); | ||||||
|  |  | ||||||
|  | @ -96,6 +96,14 @@ | ||||||
|         </div> |         </div> | ||||||
|         <br /> |         <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"> |         <div class="switch acChannel"> | ||||||
|             <select name="channel" data-setting="channel" class="left dropdown"> |             <select name="channel" data-setting="channel" class="left dropdown"> | ||||||
|                 <option value="stable" selected>Stable</option> |                 <option value="stable" selected>Stable</option> | ||||||
|  |  | ||||||
|  | @ -50,6 +50,7 @@ export function setup() { | ||||||
|         skipSplash: false, |         skipSplash: false, | ||||||
|         inviteWebsocket: true, |         inviteWebsocket: true, | ||||||
|         startMinimized: false, |         startMinimized: false, | ||||||
|  |         disableAutogain: false, | ||||||
|         mobileMode: false, |         mobileMode: false, | ||||||
|         trayIcon: "default", |         trayIcon: "default", | ||||||
|         doneSetup: false |         doneSetup: false | ||||||
|  | @ -247,6 +248,7 @@ export interface Settings { | ||||||
|     performanceMode: string; |     performanceMode: string; | ||||||
|     startMinimized: boolean; |     startMinimized: boolean; | ||||||
|     inviteWebsocket: boolean; |     inviteWebsocket: boolean; | ||||||
|  |     disableAutogain: boolean; | ||||||
|     trayIcon: string; |     trayIcon: string; | ||||||
|     doneSetup: boolean; |     doneSetup: boolean; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue