Skip to content

Instantly share code, notes, and snippets.

@CzBiX
Created December 5, 2020 08:35
Show Gist options
  • Save CzBiX/0a3da80387ed6aac740492defa3a6a4f to your computer and use it in GitHub Desktop.
Save CzBiX/0a3da80387ed6aac740492defa3a6a4f to your computer and use it in GitHub Desktop.
Clash in AHK
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
#Persistent
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Menu, Tray, NoStandard
Menu, Tray, Tip, Clash
Menu, Tray, Icon, SHELL32.dll, 136, 1
;Menu, Tray, Icon, clash.exe, 1, 1
Menu, Tray, Add, Open, Web
Menu, Tray, Add, Edit, Edit
Menu, Tray, Add, Reload, Reload
Menu, Tray, Add, Test, Test
Menu, Tray, Add, Exit, Exit
Menu, Tray, Default, Open
OnExit("ExitFunc")
StartApp()
Return
StartApp()
{
global ClashPid
Run, clash-windows-amd64.exe -d . , , Hide UseErrorLevel, ClashPid
Sleep, 1000
Process, Exist, %ClashPid%
if (!ErrorLevel)
{
MsgBox, 0x30, Clash, Start failed.
Exit()
}
}
ExitFunc()
{
global ClashPid
if (ClashPid)
{
Process, Close, %ClashPid%
}
}
Edit()
{
RunWait, notepad.exe config.yaml
Reload()
}
Reload()
{
RunWait, clash-windows-amd64.exe -d . -t , , Hide UseErrorLevel
if (ErrorLevel)
{
MsgBox, 0x30, Clash, Config test failed.
Return
}
ExitFunc()
StartApp()
}
Test()
{
RunWait, %ComSpec% /C ""clash-windows-amd64.exe" "-d" "." "-t" & pause"
}
Web()
{
Run, https://yacd.haishan.me/
}
Exit()
{
ExitApp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment