From 1fdec29b911fdcee59c52b269a645e5853bcdcb5 Mon Sep 17 00:00:00 2001 From: Jacques Yip <12838628+Jvcon@users.noreply.github.com> Date: Fri, 9 Jun 2023 15:55:06 +0800 Subject: [PATCH] Chore: Add npm build support --- .github/workflows/build.yml | 2 +- EhAria2.ahk | 43 ++++++++++++++++++++++++++------- EhAria2Torrent.ahk | 4 ++-- build.ps1 | 48 +++++++++++++++++++++++++++++++++++++ lang/en_us.ini | 4 +++- lang/zh_cn.ini | 4 +++- package.json | 40 ++++++++++++++++++------------- 7 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 build.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82f7dd7..41c6d53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: branches: - main tags: - - 'v[0-9]+.[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+' jobs: build: diff --git a/EhAria2.ahk b/EhAria2.ahk index 5e3a1be..41c81bb 100644 --- a/EhAria2.ahk +++ b/EhAria2.ahk @@ -1,7 +1,7 @@ ; --------------------- COMPILER DIRECTIVES -------------------------- ;@Ahk2Exe-SetDescription Enhanced Aria2AHK -;@Ahk2Exe-SetVersion 0.0.0.5 +;@Ahk2Exe-SetVersion 0.0.6 ;@Ahk2Exe-SetCopyright Jacques Yip ;@Ahk2Exe-SetMainIcon EhAria2.ico ;@Ahk2Exe-SetOrigFilename EhAria2.exe @@ -121,11 +121,11 @@ global LangMenu := Menu() WindowsTheme.SetAppMode(!sysThemeMode) InitialLanguage() - CreateTrayMenu() CreateLangMenu() CreateProfileMenu() CreateSpeedMenu() +InitialProxy() ; --------------------- Intial -------------------------- If (CONF.Setting.BTTrackers = "") { @@ -134,7 +134,7 @@ If (CONF.Setting.BTTrackers = "") { StartAria2() -return +Return ; --------------------- Func -------------------------- CreateTrayMenu(*){ @@ -147,9 +147,6 @@ CreateTrayMenu(*){ EhAria2Tray.Add(lTraySpeedLimit, SubMenuSpeed) EhAria2Tray.Add(lTrayProfile, SubMenuProflie) EhAria2Tray.Add(lTrayEnableProxy, SwitchProxyStatus) - If (CONF.Setting.Aria2ProxyEnable = 1) { - EhAria2Tray.Check(lTrayEnableProxy) - } EhAria2Tray.Add(lTrayUpdateTrackerList, UpdateBTTracker) EhAria2Tray.Add EhAria2Tray.Add(lTrayExit, ExitTray) @@ -164,6 +161,7 @@ CreateTrayMenu(*){ EhAria2Tray.Add EhAria2Tray.Add(lTrayAddTorrent, AddTorrent) EhAria2Tray.Add(lTrayAddTask, AddTaskMenuHandler) + return } CreateLangMenu(*) { @@ -173,6 +171,7 @@ CreateLangMenu(*) { LangMenu.Add(FileNameNoExt, SwitchLanguage) } LangMenu.Check(CONF.Setting.Language) + return } CreateProfileMenu(recreate := 0) { @@ -375,6 +374,7 @@ SwitchSpeedLimit(ItemName := 0, ItemPos := 0, MyMenu := 0) { CONF.Speed.CurrentSpeed := ItemPos global CurrentSpeedName := IniRead(CONF_Path, "Speed", "SpeedName" . CONF.Speed.CurrentSpeed) SubMenuSpeed.ToggleCheck(CurrentSpeedName) + CONF.WriteFile() RestartAria2() return } @@ -384,6 +384,7 @@ SwitchProfile(ItemName := 0, ItemPos := 0, MyMenu := 0) { CONF.Profile.CurrentProfile := ItemPos global CurrentProfileName := IniRead(CONF_Path, "Profile", "ProfileName" . CONF.Profile.CurrentProfile) SubMenuProflie.ToggleCheck(CurrentProfileName) + CONF.WriteFile() RestartAria2() return } @@ -394,10 +395,27 @@ SwitchProxyStatus(*) { } else { CONF.Setting.Aria2ProxyEnable := 1 } - EhAria2Tray.ToggleCheck(lTrayEnableProxy) + CONF.WriteFile() + InitialProxy() + RestartAria2() return } +InitialProxy(*){ + If (CONF.Setting.Aria2ProxyEnable = 1) { + If (!(CONF.Setting.Aria2Proxy = "")){ + EhAria2Tray.Check(lTrayEnableProxy) + } + else{ + MsgBox lMsgProxyError + } + } + else{ + EhAria2Tray.Uncheck(lTrayEnableProxy) + + } +} + UpdateBTTracker(ItemName := 0, ItemPos := 0, MyMenu := 0) { Download CONF.Setting.BTTrackersList, A_ScriptDir . "\TrackersLists.list" @@ -445,6 +463,11 @@ StartAria2(*) { If (CONF.Setting.Aria2RpcSecret != "") { cmd .= " --rpc-secret=" CONF.Setting.Aria2RpcSecret } + If (CONF.Setting.Aria2ProxyEnable = 1){ + If (!(CONF.Setting.Aria2Proxy = "")){ + cmd .= " --all-proxy=`"" CONF.Setting.Aria2Proxy "`"" + } + } cmd .= " --max-overall-download-limit=" . CurrentSpeedLimit cmd .= " --max-download-limit=" . CurrentSpeedLimit cmd .= " --dir=" . CurrentProfilePath @@ -472,6 +495,7 @@ SwitchLanguage(ItemName, ItemPos, MyMenu) { InitialLanguage() CreateTrayMenu() CreateLangMenu() + return } InitialLanguage(*) { @@ -497,6 +521,9 @@ InitialLanguage(*) { global lGuiUriInputBtnOK := IniRead(LANG_PATH, "GuiUriInput", "btnok") global lGuiUriInputBtnCancel := IniRead(LANG_PATH, "GuiUriInput", "btncancel") global lGuiUriInputTitle := IniRead(LANG_PATH, "GuiUriInput", "title") + + global lMsgProxyError := IniRead(LANG_PATH, "Msg", "proxyerror") + return } ExitTray(*) { @@ -504,4 +531,4 @@ ExitTray(*) { CONF.WriteFile() ExitApp Return -} \ No newline at end of file +} diff --git a/EhAria2Torrent.ahk b/EhAria2Torrent.ahk index ef1a882..d96fcab 100644 --- a/EhAria2Torrent.ahk +++ b/EhAria2Torrent.ahk @@ -1,7 +1,7 @@ ; --------------------- COMPILER DIRECTIVES -------------------------- ;@Ahk2Exe-SetDescription Enhanced Aria2Torrent -;@Ahk2Exe-SetVersion 0.0.0.3 +;@Ahk2Exe-SetVersion 0.0.6 ;@Ahk2Exe-SetCopyright Jacques Yip ;@Ahk2Exe-SetMainIcon EhAria2Torrent.ico ;@Ahk2Exe-SetOrigFilename EhAria2Torrent.exe @@ -61,4 +61,4 @@ HttpPost(URL, PData) { WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") WebRequest.Send(PData) WebRequest.WaitForResponse(-1) -} \ No newline at end of file +} diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..ffce7e6 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,48 @@ +Import-Module Microsoft.PowerShell.Utility + +Write-Host "Version:" $args +$cwd = (Get-Location).Path +$ahkpath = "C:\Users\Jacques\scoop\apps\autohotkey\current" +$ahk2exe = $ahkpath + "\Compiler\Ahk2Exe.exe" +$ahk64base = $ahkpath + "\v2\AutoHotkey64.exe" +$command = $ahk2exe + " /silent verbose " + " /base " + $ahk64base + " /out $cwd\build\" + +$setversion = ";@Ahk2Exe-SetVersion " + $args + +Get-ChildItem “$cwd\*.ahk” | ForEach-Object { + (Get-Content $_) | ForEach-Object {$_ -Replace (";@Ahk2Exe-SetVersion " + '[0-9]+.[0-9]+.[0-9]+') , $setversion } | Set-Content $_ +} + +if (!(Test-Path -Path "$cwd\build")) { + mkdir $cwd\build +} + +foreach ($file in (Get-ChildItem -Path $cwd\*.ahk)) { + Invoke-Expression($command + " /in $file") +} + +while ( !(Test-Path -Path "$cwd\build\EhAria2.exe" )) { + Start-Sleep 1 +} + +while (!(Test-Path -Path "$cwd\build\EhAria2Torrent.exe")) { + Start-Sleep 1 +} + +if ((Test-Path -Path "$cwd\build\checksums_v$args.txt")) { + Remove-Item -Path $cwd\build\checksums_v$args.txt +} + +if ((Test-Path -Path "$cwd\build\EhAria2_v$args.zip")) { + Remove-Item -Force -Path $cwd\build\EhAria2_v$args.zip +} + +Compress-Archive -Path .\build\*.exe -DestinationPath .\build\EhAria2_v$args.zip + +$value = (Get-FileHash -Path .\build\EhAria2_v$args.zip -Algorithm SHA256).Hash + " EhAria2_v$args.zip" +Tee-Object -Append -InputObject $value -FilePath $cwd\build\checksums_v$args.txt + + +foreach ($file in (Get-ChildItem -Path $cwd\build\*.exe)) { + Invoke-Expression("Remove-Item -Force -Path $file") +} diff --git a/lang/en_us.ini b/lang/en_us.ini index 5434b5c..c7f8f00 100644 --- a/lang/en_us.ini +++ b/lang/en_us.ini @@ -19,4 +19,6 @@ addtorrentto=Add Torrent to... addtaskproxyto=Add Task with Proxy to ... addtaskto=Add Task to ... addtorrent=Add Torrent -addstask=Add Task \ No newline at end of file +addstask=Add Task +[Msg] +proxyerror=Can't found any proxy address! \ No newline at end of file diff --git a/lang/zh_cn.ini b/lang/zh_cn.ini index 7255795..b38fde0 100644 --- a/lang/zh_cn.ini +++ b/lang/zh_cn.ini @@ -19,4 +19,6 @@ addtorrentto=添加种子至... addtaskproxyto=添加任务(代理)至... addtaskto=添加任务至... addtorrent=添加种子 -addstask=添加任务 \ No newline at end of file +addstask=添加任务 +[Msg] +proxyerror=没有配置代理地址! \ No newline at end of file diff --git a/package.json b/package.json index 3592fcc..7cdb207 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,28 @@ { - "name": "EhAria2", - "version": "0.0.0.3", - "description": "", - "main": "EhAria2.ahk", - "scripts": { + "name": "EhAria2", + "version": "0.0.6", + "description": "", + "main": "EhAria2.ahk", + "scripts": { "start": "nodemon --exec EhAria2.ahk", - "test": "echo \"Error: no script specified\" && exit 1" - }, - "nodemonConfig": { - "ignore": ["node_modules", "dist"], + "build": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./build.ps1 %npm_package_version%" + }, + "nodemonConfig": { + "ignore": [ + "node_modules", + "dist" + ], "delay": "250", - "watch": ["*", "scripts/*"], + "watch": [ + "*", + "scripts/*" + ], "ext": "js, json, ahk, ini, conf" - }, - "keywords": [], - "author": "", - "license": "", - "dependencies": { + }, + "keywords": [], + "author": "", + "license": "", + "dependencies": { "nodemon": "^2.0.22" - } - } \ No newline at end of file + } +}