Skip to content

Commit

Permalink
Improve startup time when using AuraSync action
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed Jul 1, 2023
1 parent 54c8283 commit a50b34b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
31 changes: 23 additions & 8 deletions src/AuraService.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,25 @@ global parentHwnd := util_getAhkMainWindowHwnd(parentPID)
if (!parentPID || parentPID == servicePID)
ExitService(-1)

OnError(Func("ExitService"))
OnError(Func("logMsg"), -1)
OnError(Func("ExitService"), 1)

logMsg("AuraService started")

; Register IPC handler
IPC_SetHandler(Func("AddTask"))

if (!AuraSync.isInstalled()){
logMsg("Aura Sync is not installed")
ExitService(-1)
}

; Initialize Aura Sync
global currentTicks := A_TickCount
global aura := new AuraSync()

IPC_Send(parentHwnd, "Aura Sync initialized successfully in " A_TickCount - currentTicks " ms", 50)
IPC_Send(parentHwnd, "auraReady", 50)
logMsg("Aura Sync initialized in " A_TickCount - currentTicks " ms")
logMsg("auraReady")

; Set tasks timer
SetTimer, RunTasks, 60
Expand Down Expand Up @@ -91,15 +99,22 @@ RunTasks(){
}
}

if(A_IsDebug)
IPC_Send(parentHwnd, "Task " util_toString(task) " took " A_TickCount - currentTicks " ms", 50)
logMsg("Task " util_toString(task) " took " A_TickCount - currentTicks " ms", true)
}

ExitService(errorCode:=0) {
if(IsObject(errorCode)){
IPC_Send(parentHwnd, "An error occured: " errorCode.Message, 50)
if (IsObject(errorCode))
errorCode := 1
}
logMsg("AuraService Exiting with errorCode " errorCode)

aura.releaseControl()
ExitApp, %errorCode%
}

logMsg(msg, debugOnly:=0) {
if (IsObject(msg))
msg := "Exception: " msg.Message

if(!debugOnly || A_IsDebug)
IPC_Send(parentHwnd, msg, 50)
}
3 changes: 1 addition & 2 deletions src/Lib/WinUtils.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ util_getWindowList(winTitle){
winHwnd:= winList%A_Index%
WinGetTitle, winTitle, % "ahk_id " winHwnd
WinGetClass, winClass, % "ahk_id " winHwnd
WinGetText, winText, % "ahk_id " winHwnd
list.Push({"hwnd": winHwnd, "title": winTitle, "class": winClass, "text": winText})
list.Push({"hwnd": winHwnd, "title": winTitle, "class": winClass})
}
DetectHiddenWindows, Off

Expand Down
19 changes: 17 additions & 2 deletions src/MicMute.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,16 @@ util_log("[Main] MicMute startup took " A_startupTime "ms")

initilizeMicMute(default_profile:="", exportConfig:=1){
util_log("[Main] Initilizing MicMute")

;make sure hotkeys are disabled before reinitilization
if(mic_controllers)
for _i,mic in mic_controllers
mic.disableController()

;destroy existing guis
overlay_wnd.destroy()
osd_wnd.destroy()

;initilize globals
config_obj:= new Config()
, osd_wnd:=""
Expand All @@ -172,19 +175,21 @@ initilizeMicMute(default_profile:="", exportConfig:=1){
; Check if AuraSyncAction is used in any profile and initilize AuraService
for _j, action in profile.MicrophoneActions {
if (action.Type = AuraSyncAction.TypeName && !AuraSyncAction.AuraServicePID) {
AuraSyncAction.initAuraService()
IPC_SetHandler(Func("OnAuraServiceMessage"))
auraServiceEnabled := true
break
}
}
}

; export the processed config object
if(exportConfig)
config_obj.exportConfig()

;enable linked apps timer
SetTimer, checkLinkedApps, % watched_profiles.Length()? 3000 : "Off"
;enable checkConfigDiff timer
setTimer, checkConfigDiff, 3000

;update theme variables
updateSysTheme()
if(config_obj.AllowUpdateChecker==-1){
Expand All @@ -194,14 +199,19 @@ initilizeMicMute(default_profile:="", exportConfig:=1){
IfMsgBox, No
config_obj.AllowUpdateChecker:= 0
}

;on first launch -> immediately call editConfig()
if(isFirstLaunch){
current_profile:= config_obj.Profiles[1]
editConfig()
return
}

;switch to the default profile
switchProfile(default_profile)

if(auraServiceEnabled)
SetTimer, initAuraService, -20
}

switchProfile(p_name:=""){
Expand Down Expand Up @@ -568,6 +578,11 @@ runUpdater(){
ExitApp, 1
}

initAuraService(){
IPC_SetHandler(Func("OnAuraServiceMessage"))
AuraSyncAction.initAuraService()
}

OnAuraServiceMessage(parentHwnd, msg){
if(msg == "auraReady"){
AuraSyncAction.AuraReady:= 1
Expand Down
2 changes: 1 addition & 1 deletion src/actions/AuraSyncAction.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AuraSyncAction extends MicrophoneAction {
AuraSyncAction.AuraServiceHwnd := util_getAhkMainWindowHwnd(AuraSyncAction.AuraServicePID)

util_log("[AuraSyncAction] Started AuraService with PID: " AuraSyncAction.AuraServicePID " and HWND: " AuraSyncAction.AuraServiceHwnd)
OnExit(ObjBindMethod(AuraSyncAction, "stopAuraService"))
OnExit(ObjBindMethod(AuraSyncAction, "stopAuraService"), -1)

OnMessage(536, ObjBindMethod(AuraSyncAction, "__OnPowerChange")) ; WM_POWERBROADCAST=536
} catch e {
Expand Down

0 comments on commit a50b34b

Please sign in to comment.