Skip to content

Commit 28ac1e6

Browse files
committed
Multiple Fixes/updates
Changed all instances of worker.exec() to worker.exec[A]Func(), which allows the GUI to not freeze when executing code on a thread Added pause checking for threadMan.execAFunc() Added error catch for trying to edit a script without having AHK installed/edit association with AHK Changed fileList.reload() to use ahkReload Fixed bug where removing scripts wouldn't close them
1 parent e917939 commit 28ac1e6

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

data/guiSubs.ahk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ addScriptFinal:
1717
gui,addScript:submit
1818
iniWrite,% newScript . "?" . dllType,% sini,scripts,% getFilename(newScript)
1919
gosub,genList
20-
worker.exec("global threadList`nthreadList.genList()`nthreadList.run(""" . getFilename(newScript) . """)")
20+
worker.execFunc("do","genList","","")
21+
worker.execAFunc("do","run",getFilename(newScript),"")
2122
return
2223

2324
genList:
@@ -51,7 +52,7 @@ gosub setDllFinal
5152
return
5253

5354
setDllFinal:
54-
worker.exec("threadList.setDll(""" . nDllType . """,""" . nDllPath . """)")
55+
worker.execAFunc("do","setDll",nDllType,nDllPath)
5556
return
5657

5758
lvCallback:

data/menuSubs.ahk

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
reloadScript:
22
lv_getText(scr,selectedRow)
3-
worker.exec("threadList.reload(""" . scr . """)")
3+
worker.execAFunc("do","reload",scr,"")
44
return
55

66
pauseScript:
77
lv_getText(scr,selectedRow)
8-
worker.exec("threadList.pause(""" . scr . """)")
8+
worker.execAFunc("do","pause",scr,"")
99
return
1010

1111
suspendScript:
1212
lv_getText(scr,selectedRow)
13-
worker.exec("threadList.suspend(""" . scr . """)")
13+
worker.execAFunc("do","suspend",scr,"")
1414
return
1515

1616
listlinesScript:
1717
lv_getText(scr,selectedRow)
18-
worker.exec("threadList.listlines(""" . scr . """)")
18+
worker.execAFunc("do","listlines",scr,"")
1919
return
2020

2121
editScript:
2222
lv_getText(scr,selectedRow)
23-
worker.exec("threadList.edit(""" . scr . """)")
23+
worker.execAFunc("do","edit",scr,"")
2424
return
2525

2626
removeScript:
@@ -40,7 +40,8 @@ return
4040

4141
removeScriptFinal:
4242
iniDelete,% sini,scripts,% scr
43-
worker.exec("threadList.remove(""" . scr . """)`nthreadList.genList()")
43+
worker.execFunc("do","remove",scr,"")
44+
worker.execAFunc("do","genList","","")
4445
gosub genList
4546
return
4647

@@ -52,5 +53,5 @@ return
5253

5354
execScriptFinal:
5455
gui,execCode:submit,nohide
55-
worker.exec("threadList.exec(""" . scrx . """,""" . execScriptCode . """)")
56+
worker.execAFunc("do","exec",scrx,execScriptCode)
5657
return

data/threadMan.ahk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class threadMan {
145145
}
146146

147147
execAFunc(func,params*){
148+
if(this.pauseState()){
149+
msgbox,,Error,Code can not be executed while thread is paused.
150+
return
151+
}
148152
if(!params.length())
149153
return dllCall(this.dllObj.getProcAddress("ahkPostFunction"),"Str",func,"Cdecl UInt")
150154
if(params.length()=1)

data/workerH.ahk

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ threadList.runAll()
1212
setTimer,updateStatus,100
1313
return
1414

15+
do(funct,p1,p2){ ; execAFunc does not support varadic functions or optional params
16+
global threadList
17+
params:=[]
18+
loop 2
19+
if(p%a_index%)
20+
params.push(p%a_index%)
21+
threadList[funct](params*)
22+
}
23+
1524
updateStatus:
1625
stateList:=threadList.returnStates()
1726
return
@@ -93,7 +102,8 @@ class fileList {
93102
toolTip
94103
}
95104
edit(scriptName){
96-
run,% "edit """ . this.scripts[scriptName].path . """"
105+
try
106+
run,% "edit """ . this.scripts[scriptName].path . """"
97107
}
98108
exec(scriptName,code){
99109
if(this.pauseState(scriptName))
@@ -102,8 +112,7 @@ class fileList {
102112
return this.scripts[scriptName].thread.ahkExec(code)
103113
}
104114
reload(scriptName){
105-
this.close(scriptName)
106-
return this.run(scriptName)
115+
this.scripts[scriptName].thread.ahkReload()
107116
}
108117
listlines(scriptName){
109118
if(this.scripts[scriptName].dll="Mini")
@@ -167,7 +176,10 @@ class fileList {
167176
}
168177
close(scriptName){
169178
try{
170-
this.scripts[scriptName].thread.timeout:=this.quitTimeout
179+
try{
180+
this.scripts[scriptName].thread.ahkTerminate()
181+
MemoryFreeLibrary(this.scripts[scriptName].thread[""])
182+
}
171183
this.scripts[scriptName].thread:=""
172184
}
173185
}
@@ -203,9 +215,6 @@ ahkthread_free(obj:=""){
203215
else If objects.HasKey(obj)
204216
objects.Remove(obj)
205217
}
206-
ahkthread_release(o){
207-
o.ahkterminate(o.timeout?o.timeout:0),MemoryFreeLibrary(o[""])
208-
}
209218
ahkthread(s:="",p:="",IsFile:=0,dll:=""){
210219
static ahkdll,ahkmini,base,functions
211220
if !base
@@ -219,4 +228,4 @@ ahkthread(s:="",p:="",IsFile:=0,dll:=""){
219228
obj.hThread:=obj[IsFile?"ahkdll":"ahktextdll"](s,"",p)
220229
ahkthread_free(true)[obj]:=1 ; keep dll loaded even if returned object is freed
221230
return obj
222-
}
231+
}

0 commit comments

Comments
 (0)