diff --git a/src/Lib/DisplayDevices.ahk b/src/Lib/DisplayDevices.ahk index 08f9072..bb870ec 100644 --- a/src/Lib/DisplayDevices.ahk +++ b/src/Lib/DisplayDevices.ahk @@ -185,7 +185,7 @@ class DisplayDevices { DisplayDevices_UpdateDisplays() { static method := ObjBindMethod(DisplayDevices, "updateCachedDisplays") - SetTimer, %method%, -10 + SetTimer, %method%, -100 } DisplayDevices.updateCachedDisplays() diff --git a/src/Lib/WinUtils.ahk b/src/Lib/WinUtils.ahk index b7c0140..0916986 100644 --- a/src/Lib/WinUtils.ahk +++ b/src/Lib/WinUtils.ahk @@ -228,7 +228,10 @@ util_log(msg){ static logNum:=0 msg:= Format("#{:i} {}: {}`n", ++logNum, A_TickCount, IsObject(msg)? "Error: " . msg.Message : msg) A_log.= msg - Try FileOpen(arg_logFile, "a").Write(msg) + if (arg_isDebug || A_DebuggerName) + OutputDebug, % msg + else + Try FileOpen(arg_logFile, "a").Write(msg) } util_toString(obj){ diff --git a/src/MicMute.ahk b/src/MicMute.ahk index 7c63749..1cf0b1d 100644 --- a/src/MicMute.ahk +++ b/src/MicMute.ahk @@ -1,4 +1,4 @@ -#Requires AutoHotkey v1.1.36+ +#Requires AutoHotkey v1.1.36+ ;compiler directives ;@Ahk2Exe-Let Res = %A_ScriptDir%\resources @@ -87,7 +87,7 @@ Global A_startupTime:= A_TickCount , watched_profile , mic_actions , last_modif_time - , arg_isDebug:=0 + , arg_isDebug:= A_DebuggerName ? 1 : 0 , arg_profile:="" , arg_noUI:=0 , arg_reload:= 0 @@ -97,7 +97,8 @@ Global A_startupTime:= A_TickCount , args_str:="" , resources_obj:= new ResourcesManager() , isFirstLaunch:=0 - , isAfterUpdate:=0 + , A_AfterUpdate:=0 + , A_PreviousVersion:="" , A_Version:= A_IsCompiled? util_getFileSemVer(A_ScriptFullPath) : U_Version , sound_player , osd_wnd @@ -109,14 +110,13 @@ Global A_startupTime:= A_TickCount , WM_SETTINGCHANGE:= 0x001A , WM_DEVICECHANGE := 0x0219 -; parse cli args +util_log("MicMute v" A_Version) parseArgs() tray_defaults() -util_log("MicMute v" . A_Version) -util_log(Format("[Main] Running as user {}, A_IsAdmin = {}", A_UserName, A_IsAdmin)) +util_log(Format("[Main] {} as user {}, A_IsAdmin = {}, A_Args = {}", arg_reload ? "Reloading" : "Running", A_UserName, A_IsAdmin, args_str)) OnError(Func("util_log")) if(arg_isUpdater){ - util_log("[Main] Updater mode") + util_log("[Main] Starting updater mode") tray_init_updater() updater_UI:= new UpdaterUI() return @@ -416,7 +416,7 @@ checkIsIdle(){ } if (!wasIdle){ - util_log("[Main] Detected idling for " current_profile.afkTimeout " ms") + util_log("[Main] Detected idling for " A_TimeIdlePhysical " ms") wasIdle := true } @@ -441,7 +441,7 @@ checkConfigDiff(){ checkLinkedApps(){ if(watched_profile){ if(!isAppActive(watched_profile.LinkedApp, watched_profile.ForegroundAppsOnly)){ - util_log("[Main] Linked app closed: " . watched_profile.LinkedApp) + util_log("[Main] Linked app closed: " watched_profile.LinkedApp) watched_profile:="" switchProfile(config_obj.DefaultProfile) } @@ -450,7 +450,7 @@ checkLinkedApps(){ for _i, p in watched_profiles { if(isAppActive(p.LinkedApp, p.ForegroundAppsOnly)){ - util_log("[Main] Detected linked app: " . p.LinkedApp) + util_log("[Main] Detected linked app: " p.LinkedApp) watched_profile:= p switchProfile(p.ProfileName) break @@ -460,7 +460,7 @@ checkLinkedApps(){ isAppActive(appFile, foregroundOnly){ if (foregroundOnly) { - windowExists := WinExist("ahk_exe " . appFile) + windowExists := WinExist("ahk_exe " appFile) WinGet, minState, MinMax, ahk_exe %appFile% ; An app is active in the foreground if it has a window that's not hidden @@ -581,7 +581,7 @@ showElevatedWarning(){ configMsg(err){ Thread, NoTimers, 1 - MsgBox, 65, MicMute, % (IsObject(err)? err.Message : err) . "`nClick OK to edit configuration" + MsgBox, 65, MicMute, % (IsObject(err)? err.Message : err) "`nClick OK to edit configuration" IfMsgBox, OK editConfig() IfMsgBox, Cancel diff --git a/src/UI/Overlay.ahk b/src/UI/Overlay.ahk index f2eaedd..5a2e7d4 100644 --- a/src/UI/Overlay.ahk +++ b/src/UI/Overlay.ahk @@ -62,7 +62,7 @@ if (!this._setPosConfig(positionConfig)) Continue - this.options.pos[i] := this.currentPos + this.options.pos[i] := this.relativePosition isPositionSet := 1 Break } @@ -71,13 +71,13 @@ if (!isPositionSet) { display := DisplayDevices.getPrimary() - this.windowPosition := display.getAbsolutePosition(this.options.pos[1].X, this.options.pos[1].Y) + this.absolutePosition := display.getAbsolutePosition(this.options.pos[1].X, this.options.pos[1].Y) ; position is not set -> use default position - if (!this.windowPosition) + if (!this.absolutePosition) this._setDefaultPos(display) else - this.currentPos := this.options.pos[1] := display.getRelativePosition(this.windowPosition.X, this.windowPosition.Y) + this.relativePosition := this.options.pos[1] := display.getRelativePosition(this.absolutePosition.X, this.absolutePosition.Y) } } else { positionConfig := this.options.pos[1] @@ -97,18 +97,18 @@ if (!display) display := DisplayDevices.getPrimary() - this.windowPosition := display.getAbsolutePosition(positionConfig.X, positionConfig.Y) + this.absolutePosition := display.getAbsolutePosition(positionConfig.X, positionConfig.Y) ; position is not set -> use default position - if (!this.windowPosition) + if (!this.absolutePosition) this._setDefaultPos(display) else - this.currentPos := this.options.pos[1] := display.getRelativePosition(this.windowPosition.X, this.windowPosition.Y) + this.relativePosition := this.options.pos[1] := display.getRelativePosition(this.absolutePosition.X, this.absolutePosition.Y) } } - if (this.hwnd && this.shown && this.windowPosition.x && this.windowPosition.y) - WinMove, % "ahk_id " this.hwnd, , % this.windowPosition.x, % this.windowPosition.y + if (this.hwnd && this.shown && this.absolutePosition.x && this.absolutePosition.y) + WinMove, % "ahk_id " this.hwnd, , % this.absolutePosition.x, % this.absolutePosition.y } _setPosConfig(positionConfig){ @@ -122,11 +122,11 @@ if (!display) return false - this.windowPosition := display.getAbsolutePosition(positionConfig.X, positionConfig.Y) - if (!this.windowPosition) + this.absolutePosition := display.getAbsolutePosition(positionConfig.X, positionConfig.Y) + if (!this.absolutePosition) return false - this.currentPos := display.getRelativePosition(this.windowPosition.X, this.windowPosition.Y) + this.relativePosition := display.getRelativePosition(this.absolutePosition.X, this.absolutePosition.Y) return true } @@ -134,10 +134,10 @@ if (!display) display := DisplayDevices.getPrimary() - this.currentPos := this.options.pos[1] := Overlay.DEFAULT_POSITION.Clone() + this.relativePosition := this.options.pos[1] := Overlay.DEFAULT_POSITION.Clone() this.options.pos[1].DisplayId := display.id - this.windowPosition := display.getAbsolutePosition(this.options.pos[1].X, this.options.pos[1].Y) + this.absolutePosition := display.getAbsolutePosition(this.options.pos[1].X, this.options.pos[1].Y) } _createWindow() { @@ -206,11 +206,7 @@ } _updateLayeredWindow() { - pos := this.windowPosition - if (this.changedPos) - pos := this.changedPos - - UpdateLayeredWindow(this.hwnd, this.deviceContext, pos.x, pos.y, this.options.size, this.options.size) + UpdateLayeredWindow(this.hwnd, this.deviceContext, this.absolutePosition.x, this.absolutePosition.y, this.options.size, this.options.size) } _clear() { @@ -249,20 +245,20 @@ if (!this.changedPos) return - this.windowPosition.X := xPos := this.changedPos.x - this.windowPosition.Y := yPos := this.changedPos.y + this.absolutePosition.X := xPos := this.changedPos.x + this.absolutePosition.Y := yPos := this.changedPos.y util_log("[Overlay] Overlay position changed to: " xPos ", " yPos) this.changedPos := "" - display := DisplayDevices.getByPosition(xPos, yPos) + newPosDisplay := DisplayDevices.getByPosition(xPos, yPos) ; Check if we're on the same display - if (display.Id == this.windowPosition.DisplayId){ - relativePos := display.getRelativePosition(xPos, yPos) + if (newPosDisplay.Id == this.absolutePosition.DisplayId){ + relativePos := newPosDisplay.getRelativePosition(xPos, yPos) - this.currentPos.X := relativePos.X - this.currentPos.Y := relativePos.Y + this.relativePosition.X := relativePos.X + this.relativePosition.Y := relativePos.Y config_obj.exportConfig() return @@ -271,32 +267,32 @@ ; Check if there's a config for the new display existingConfigIndex := 0 for i, positionConfig in this.options.pos { - if (positionConfig.displayId = display.Id) { + if (positionConfig.displayId = newPosDisplay.Id) { existingConfigIndex := i break } } if (existingConfigIndex) { - this.currentPos := existingConfig := this.options.pos[existingConfigIndex] + this.relativePosition := existingConfig := this.options.pos[existingConfigIndex] this.options.pos.Delete(existingConfigIndex) this.options.pos.InsertAt(1, existingConfig) - relativePos := display.getRelativePosition(xPos, yPos) + relativePos := newPosDisplay.getRelativePosition(xPos, yPos) existingConfig.X := relativePos.X existingConfig.Y := relativePos.Y - this.windowPosition.DisplayId := display.Id + this.absolutePosition.DisplayId := newPosDisplay.Id config_obj.exportConfig() return } ; No config for the new display, add a new one - this.currentPos := display.getRelativePosition(xPos, yPos) - this.options.pos.InsertAt(1, this.currentPos) - this.windowPosition.DisplayId := display.Id + this.relativePosition := newPosDisplay.getRelativePosition(xPos, yPos) + this.options.pos.InsertAt(1, this.relativePosition) + this.absolutePosition.DisplayId := newPosDisplay.Id config_obj.exportConfig() } @@ -315,7 +311,7 @@ Gui, % this.hwnd ":Default" Gui, Show, % Format("w{} h{} x{} y{} NA" , this.options.size, this.options.size - , this.windowPosition.x, this.windowPosition.y) + , this.absolutePosition.x, this.absolutePosition.y) this._updateLayeredWindow() this.shown := 1 }