-
Notifications
You must be signed in to change notification settings - Fork 3
/
Config.ahk
195 lines (168 loc) · 6.07 KB
/
Config.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#Requires AutoHotkey v2.0
#SingleInstance Ignore
#NoTrayIcon
#Include lib\AppUtils.ahk
#Include lib\Json.ahk
#Include lib\ArrayExtensions.ahk
#Include lib\AhkScriptUtils.ahk
#Include lib\WinEvent.ahk
TraySetIcon("res\launcher.ico")
DetectHiddenWindows True
AppUtils.SetCurrentProcessExplicitAppUserModelID(AppUserModelID)
startUpLink := A_Startup "\launchMenu.lnk"
createStartUpLink()
configUi := Constructor()
configUi.Show("w620 h420")
Constructor()
{
cfgGui := Gui()
cfgGui.Title := "AhkLauncher配置"
cfgGui.AddText("x24 y16 w572 h59", "这是一个将文件夹显示为导航菜单的应用,因为trueLuanchBar不更新了,对win11支持不好,所以开发了这个应用.")
isStartUp := FileExist(startUpLink) ? 1 : 0
CheckBoxStartUp := cfgGui.AddCheckbox("x24 y56 w100 h23 Checked" isStartUp, "开机启动")
loadAhkScript := IniRead(configIni, "config", "loadAhkScript", 0)
CheckBoxLoadAhkScript := cfgGui.AddCheckbox("x124 y56 w200 h23 Checked" loadAhkScript, "加载 AHK 脚本菜单")
cfgGui.AddGroupBox("x24 y90 w572 h50", "导航文件夹")
launcherLnk := A_ScriptDir "\launchDir.lnk"
launcherPath := ""
if FileExist(launcherLnk) {
FileGetShortcut launcherLnk, &launcherPath
}
editLuncherDir := cfgGui.AddEdit("x32 y108 w460", launcherPath)
buttonLuncherDir := cfgGui.AddButton("x500 y106 w40 h24", "选择")
cfgGui.AddText("x24 y150", "AHK Script")
uxView := cfgGui.AddListView("x24 y170 w572 h230 +NoSort +Grid -LV0x10 Backgrounde9e9e9", ["name", "autoRun", "status"])
uxView.ModifyCol(1, 300)
uxView.ModifyCol(2, 80)
uxView.ModifyCol(3, "AutoHdr")
autoRuns := StrSplit(IniRead(configIni, "config", "autoRuns", ""), ",")
uxFiles := Array()
loop files A_ScriptDir "\ux\*.ahk", "F"
{
uxFiles.Push({
name: A_LoopFileName,
autoRun: Autorun(A_LoopFileName),
status: Status(A_LoopFileName)
})
}
for item in uxFiles {
uxView.Add(, item.name, formatAutorun(item.autoRun), item.status)
}
uxView.OnEvent("ContextMenu", Ctrl_ContextMenu)
buttonLuncherDir.OnEvent("Click", SelectLaunchDirHandler)
CheckBoxStartUp.OnEvent("Click", StartUpEventHandler)
CheckBoxLoadAhkScript.OnEvent("Click", LoadAhkScriptEventHandler)
cfgGui.OnEvent('Close', (*) => ExitApp())
WinEvent.Close(UpUxView, ".ahk - AutoHotkey")
WinEvent.Create(UpUxView, ".ahk - AutoHotkey")
UpUxView(*) {
for item in uxFiles {
isAutorun := Autorun(item.name)
mStatus := Status(item.name)
if (item.autoRun != isAutorun || item.status != mStatus) {
item.autoRun := isAutorun
item.status := mStatus
uxView.Modify(A_Index, , item.name, formatAutorun(item.autoRun), item.status)
}
}
}
SelectLaunchDirHandler(*) {
configUi.Opt("+OwnDialogs")
launcherPath := AppUtils.SelectLaunchDir()
if (launcherPath) {
editLuncherDir.Text := launcherPath
}
}
StartUpEventHandler(*) {
if (CheckBoxStartUp.Value) {
createStartUpLink
} else {
FileDelete(startUpLink)
}
}
LoadAhkScriptEventHandler(*) {
if (CheckBoxLoadAhkScript.Value) {
IniWrite(1, configIni, "config", "loadAhkScript")
} else {
IniWrite(0, configIni, "config", "loadAhkScript")
}
}
cMenu := Menu()
cMenu.DefineProp("data", { Value: "" })
Ctrl_ContextMenu(GuiCtrlObj, Item, IsRightClick, X, Y) {
cMenu.Delete
cMenu.data := Item
ux := uxFiles[Item]
If (ux.status) {
cMenu.Add("结束", EndScript)
} else {
cMenu.Add("运行", RunScript)
}
if (ux.autoRun) {
cMenu.Add("禁用自动运行", DisableAutoRun)
} else {
cMenu.Add("启用自动运行", EnableAutoRun)
}
cMenu.Show()
}
EnableAutoRun(ItemName, ItemPos, MyMenu) {
filePos := MyMenu.data
fileName := uxFiles[filePos].name
if (autoRuns.IndexOf(fileName) = 0) {
autoRuns.Push(fileName)
IniWrite(autoRuns.Join(), configIni, "config", "autoRuns")
}
index := uxFiles.find((v) => v.name = fileName)
if (index > 0) {
uxFiles[index].autoRun := true
uxView.Modify(index, , fileName, formatAutorun(true), Status(fileName))
}
}
DisableAutoRun(ItemName, ItemPos, MyMenu) {
filePos := MyMenu.data
fileName := uxFiles[filePos].name
fileIndex := autoRuns.IndexOf(fileName)
if (fileIndex > 0) {
autoRuns.RemoveAt(fileIndex)
IniWrite(autoRuns.Join(), configIni, "config", "autoRuns")
}
index := uxFiles.find((v) => v.name = fileName)
if (index > 0) {
uxFiles[index].autoRun := false
uxView.Modify(index, , fileName, formatAutorun(false), Status(fileName))
}
}
RunScript(ItemName, ItemPos, MyMenu) {
filePos := MyMenu.data
fileName := uxFiles[filePos].name
uxPath := A_ScriptDir "\ux\" fileName
Run '"' A_AhkPath '" "' uxPath '"'
}
EndScript(ItemName, ItemPos, MyMenu) {
filePos := MyMenu.data
fileName := uxFiles[filePos].name
AhkScript.Exit(A_ScriptDir "\ux\" fileName)
}
Autorun(fileName) {
return autoRuns.IndexOf(fileName)
}
Status(fileName) {
path := A_ScriptDir "\ux\" fileName
return WinExist(path " - AutoHotkey") ? "运行中" : ""
}
formatAutorun(isAutoRun) {
return isAutoRun ? "✓" : "✕"
}
return cfgGui
}
createStartUpLink() {
shellLink := IShellLink()
shellLink.SetPath(A_ScriptDir "\AhkLauncher.exe")
shellLink.SetWorkingDirectory(A_ScriptDir)
shellLink.SetTitle("AhkLauncher")
shellLink.SetArguments(A_ScriptDir "\launchMenu.ahk")
shellLink.SetIconLocation(A_ScriptDir "\res\launcher.ico", 0)
shellLink.SetAppUserModelID(AppUserModelID)
shellLink.Commit()
shellLink.Save(startUpLink, true)
}