Skip to content

Commit

Permalink
Add option to disable admin app notification #106
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed Jun 29, 2024
1 parent 7ccffad commit 63d71ef
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 46 deletions.
31 changes: 18 additions & 13 deletions src/MicMute.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -555,27 +555,32 @@ parseArgs(){
}

registerWindowHook(){
DllCall( "RegisterShellHookWindow", UInt,A_ScriptHwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "onWindowChange" )
DllCall("RegisterShellHookWindow", "UInt", A_ScriptHwnd)
msgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK")
OnMessage(msgNum, "onWindowChange")
}

onWindowChange(wParam, _lParam){
if(wParam=1)
showElevatedWarning()
if (wParam = 1 && IsActiveAppAdmin()) {
TrayTip, MicMute, Detected an application running with administrator privileges. You need to run MicMute as administrator for the hotkeys to work with it.
onUpdateState(mic_controllers[1])
}
}

showElevatedWarning(){
static lastP:=""
IsActiveAppAdmin(){
static lastProcess:=""
if (A_IsAdmin || !config_obj.NotifyForAdminApps)
return false

WinGet, pid, pid, A
WinGet, pName, ProcessName, A
if(A_IsAdmin || !pName || pName == lastP)
return
if(util_isProcessElevated(pid)){
if (!pName || pName == lastProcess)
return false

if (util_isProcessElevated(pid)){
util_log("[Main] Detected elevated app: " pName " (" pid ")")
TrayTip, MicMute, Detected an application running with administrator privileges. You need to run MicMute as administrator for the hotkeys to work with it.
lastP:= pName
onUpdateState(mic_controllers[1])
lastProcess:= pName
return true
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/UI/config/UI.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ UI_reset(){
ui_obj.doc.getElementById("VoicemeeterIntegration").setAttribute("checked", 1)
else
ui_obj.doc.getElementById("VoicemeeterIntegration").removeAttribute("checked")
if(config_obj.NotifyForAdminApps)
ui_obj.doc.getElementById("NotifyForAdminApps").setAttribute("checked", 1)
else
ui_obj.doc.getElementById("NotifyForAdminApps").removeAttribute("checked")
ui_obj.doc.getElementById("PreferTheme").value:= config_obj.PreferTheme
}

Expand Down
4 changes: 3 additions & 1 deletion src/UI/config/UITemplates.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,6 @@ global template_link:= "<link rel='stylesheet' id='css_{1:}' href='{2:}'>"
,{ selector: ".volume-lock-label"
, string: "Lock the microphone's volume to a specific value"}
,{ selector: ".ForegroundAppsOnly-label"
, string: "Require apps to be in the foreground to trigger a profile change"}]
, string: "Require apps to be in the foreground to trigger a profile change"}
,{ selector: ".NotifyForAdminApps-label"
, string: "Show a notification when an admin app is detected"}]
8 changes: 8 additions & 0 deletions src/UI/config/html/UI.html
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,14 @@
<span>Voicemeeter integration</span>
</label>
</div>
<!-- Notify For Admin Apps -->
<div class="tag is-small option has-tooltip" onclick="ahk.UI_onGlobalOption('NotifyForAdminApps',1);this.blur()" tabindex=0
onkeydown="switch(event.keyCode){case 32:case 13:this.click()}" role="button" aria-pressed="false">
<label class="checkbox">
<input type="checkbox" name="NotifyForAdminApps" id="NotifyForAdminApps" disabled>
<span class="NotifyForAdminApps-label">Notify For Admin Apps</span>
</label>
</div>
</div>
<div class="column is-4">
<!-- default profile -->
Expand Down
10 changes: 1 addition & 9 deletions src/config/Config.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ForceMicrophoneState := 0
VoicemeeterPath := ""
VoicemeeterIntegration := 0

NotifyForAdminApps := 1
Version := ""

__New(p_DefaultProfile := "") {
Expand Down Expand Up @@ -61,14 +61,6 @@

; Update the config version
this.Version := A_Version

; Ensure compatibility with old versions
if (this.UseCustomSounds) {
for i, profile in this.profiles {
profile.SoundFeedbackUseCustomSounds := this.UseCustomSounds
}
}
this.Delete("UseCustomSounds")
}

exportConfig() {
Expand Down
23 changes: 0 additions & 23 deletions src/config/ProfileTemplate.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@
, UseCustomIcons: 0 }

if (IsObject(p_name_Obj)) {
; Ensure compatibility with old versions
onMuteOnly := p_name_Obj.Delete("OverlayOnMuteOnly")
if (onMuteOnly)
this.OnscreenOverlay.ShowOnState := onMuteOnly

; Ensure compatibility with old versions
if (!IsObject(p_name_Obj.OnscreenOverlay)){
this.OnscreenOverlay.Enabled := p_name_Obj.Delete("OnscreenOverlay")
this.OnscreenOverlay.Position[1] := p_name_Obj.Delete("OverlayPos")
this.OnscreenOverlay.ShowOnState := p_name_Obj.Delete("OverlayShow")
this.OnscreenOverlay.Theme := p_name_Obj.Delete("OverlayTheme")
this.OnscreenOverlay.Size := p_name_Obj.Delete("OverlaySize")
this.OnscreenOverlay.UseCustomIcons := p_name_Obj.Delete("OverlayUseCustomIcons")
}

for prop, val in p_name_Obj {
this[prop] := val
}
Expand All @@ -51,14 +36,6 @@
; if it's less than 1000, it's most likely an old value
if (A_AfterUpdate && p_name_Obj.afkTimeout < 1000)
this.afkTimeout := p_name_Obj.afkTimeout * 60000

; Ensure compatibility with old versions
if (!IsObject(this.Microphone)) {
this.Microphone := Array(new MicrophoneTemplate(this.Delete("Microphone")
, this.Delete("MuteHotkey")
, this.Delete("UnmuteHotkey")
, this.Delete("PushToTalk")))
}
}
}
}

0 comments on commit 63d71ef

Please sign in to comment.