Skip to content

Commit

Permalink
chore(capslockx): setup
Browse files Browse the repository at this point in the history
setup
  • Loading branch information
snomiao committed Nov 20, 2024
1 parent 333e48c commit 324d81d
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: bun install
- run: npm publish --provenance --access public
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 6 additions & 6 deletions CapsLockX.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ global 显示加载提示 := 1
global loadingTips := ""

; 对 核心模块 进行 编码清洗
清洗为_UTF8_WITH_BOM_型编码(CLX_CoreDir "/CapsLockX-Config.ahk")
清洗为_UTF8_WITH_BOM_型编码(CLX_CoreDir "/CapsLockX-Core.ahk")
清洗为_UTF8_WITH_BOM_型编码(CLX_CoreDir "/CapsLockX-RunSilent.ahk")
清洗为_UTF8_WITH_BOM_型编码(CLX_CoreDir "/CapsLockX-Update.ahk")
清洗为_UTF8_WITH_BOM_型编码(CLX_CoreDir "/CapsLockX-i18n.ahk")
CONVERT_FILE_TO_UTF8_WITH_BOM_ENCODING(CLX_CoreDir "/CapsLockX-Config.ahk")
CONVERT_FILE_TO_UTF8_WITH_BOM_ENCODING(CLX_CoreDir "/CapsLockX-Core.ahk")
CONVERT_FILE_TO_UTF8_WITH_BOM_ENCODING(CLX_CoreDir "/CapsLockX-RunSilent.ahk")
CONVERT_FILE_TO_UTF8_WITH_BOM_ENCODING(CLX_CoreDir "/CapsLockX-Update.ahk")
CONVERT_FILE_TO_UTF8_WITH_BOM_ENCODING(CLX_CoreDir "/CapsLockX-i18n.ahk")

; 复制用户模块
; TODO FIX:如果CLX已经开了的话,这一步会触发重启,这可能会导致一些文件冲突的BUG……
Expand Down Expand Up @@ -210,7 +210,7 @@ Return
加载提示追加(t("跳过模块:") . i . " " . 模块名称)
} else {
; 这里引入模块代码
清洗为_UTF8_WITH_BOM_型编码(CLX_ModuleDir "/" 模块文件)
CONVERT_FILE_TO_UTF8_WITH_BOM_ENCODING(CLX_ModuleDir "/" 模块文件)
; 导入模块
模块初始化代码 .= "GoSub CLX_ModuleSetup_" i "`n"
模块导入代码 .= "`n" "#If" "`n" "`n"
Expand Down
18 changes: 11 additions & 7 deletions Core/CapsLockX-i18n.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
global CLX_i18nConfigPath := "Core/lang.ini"
global CLX_i18n_newTranslated := "Core/lang.ini"

清洗为_UTF16_WITH_BOM_型编码(CLX_i18nConfigPath)
CONVERT_FILE_TO_UTF16_WITH_BOM_ENCODING(CLX_i18nConfigPath)

; - [Language Codes \| AutoHotkey v1]( https://www.autohotkey.com/docs/v1/misc/Languages.htm )
LCID_7804 := "Chinese" ; zh
Expand Down Expand Up @@ -82,21 +82,25 @@ i18n_translated(lang, key)
return translated
}

question := "TASK: translate to " . lang . ",dont explain, just translate`n" . "ORIGIN TEXT: " . key
question := ">>> ROLE: Act as translator, input text is between '>>> TEXT BEGIN' and '>>> TEXT END', output transcript, no explain" . "`n"
question .= ">>> TASK: translate to " . lang . "`n"
question .= ">>> TEXT BEGIN" . "`n"
question .= key . "`n"
question .= ">>> TEXT END" . "`n"

global brainstorm_origin
if (!brainstorm_origin) {
brainstorm_origin := CLX_Config("BrainStorm", "Website", "https://brainstorm.snomiao.com")
}
endpoint := brainstorm_origin . "/ai/chat?ret=text"
endpoint := brainstorm_origin . "/ai/translator?ret=text"
xhr := ComObjCreate("Msxml2.XMLHTTP")
xhr.Open("POST", endpoint)
xhr.setRequestHeader("Authorization", "Bearer " . brainstormApiKey)
xhr.onreadystatechange := Func("brainstorm_translatePostResult").Bind(lang, key, xhr)
xhr.onreadystatechange := Func("i18n_brainstorm_translatePostResult").Bind(lang, key, xhr)
xhr.Send(question)
return "…[" . key . "]"
}
brainstorm_translatePostResult(lang, key, xhr)
i18n_brainstorm_translatePostResult(lang, key, xhr)
{
if (xhr.readyState != 4)
return
Expand All @@ -107,7 +111,7 @@ brainstorm_translatePostResult(lang, key, xhr)
; ignore 500 error
return
}
MsgBox, % xhr.status . " " xhr.responseText . " " . ("未知错误 / Unknown Error")
MsgBox, % xhr.status . " " . xhr.responseText . " " . ("未知错误 / Unknown Error")
return
}
global transcript := xhr.responseText
Expand Down Expand Up @@ -160,7 +164,7 @@ CLX_i18n_ConfigSet(field, varName, value)
global CLX_ConfigDir
IniSave(encodedValue, CLX_ConfigDir . "/" . field . ".ini", field, encodedKey)

; 清洗为_UTF16_WITH_BOM_型编码(CLX_ConfigDir)
; CONVERT_FILE_TO_UTF16_WITH_BOM_ENCODING(CLX_ConfigDir)
}
CLX_i18n_ConfigEnocde(str){
str := RegExReplace(str, "\\", "\\")
Expand Down
19 changes: 10 additions & 9 deletions Core/CapslockX-Config.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ if (!CLX_ConfigPath) {
; 配置文件编码清洗
global CLX_ConfigChangedTickCount
CLX_ConfigChangedTickCount := A_TickCount
; msgbox 清洗为_UTF16_WITH_BOM_型编码1
清洗为_UTF16_WITH_BOM_型编码(CLX_ConfigPath)
; msgbox 清洗为_UTF16_WITH_BOM_型编码2
; msgbox CONVERT_FILE_TO_UTF16_WITH_BOM_ENCODING1
CONVERT_FILE_TO_UTF16_WITH_BOM_ENCODING(CLX_ConfigPath)
; msgbox CONVERT_FILE_TO_UTF16_WITH_BOM_ENCODING2

CLX_Config("_NOTICE_", "ENCODING_USING", "UTF16_LE", "")

Expand Down Expand Up @@ -110,7 +110,8 @@ CLX_Config(field, varName, defaultValue, comment := "")
return content
}

清洗为_UTF16_WITH_BOM_型编码(path){
; convert file to UTF16 (which is required by ReadINI in ahk)
CONVERT_FILE_TO_UTF16_WITH_BOM_ENCODING(path){
ConfigLock("UTF16_WITH_BOM 文件编码清洗:" path)
if (FileGetFormat(path) === "UTF-16 LE") {
ConfigUnlock()
Expand Down Expand Up @@ -150,7 +151,7 @@ FileGetFormat(file)
Return StrLen(f) = size ? "ANSI" : "UTF-8 no BOM"
}

清洗为_UTF8_WITH_BOM_型编码(path){
CONVERT_FILE_TO_UTF8_WITH_BOM_ENCODING(path){
ConfigLock("UTF8_WITH_BOM 文件编码清洗:" path)
if (FileGetFormat(path) === "UTF-8") {
ConfigUnlock()
Expand All @@ -164,14 +165,14 @@ FileGetFormat(file)
ConfigUnlock()
}

ConfigLock(名义:="")
ConfigLock(reason:="")
{
k:= 0
while (FileExist(CLX_ConfigPath ".lock")) {
k := k + 1
if ( k > 10 ) {
FileRead 上次名义, % CLX_ConfigPath ".lock"
; MsgBox, 程序退出, %名义% 配置写入失败,配置文件被意外锁定,上次锁定名义为 %上次名义%
FileRead lastReason, % CLX_ConfigPath ".lock"
; MsgBox, 程序退出, %reason% 配置写入失败,配置文件被意外锁定,上次锁定名义为 %lastReason%
ConfigUnlock()
Reload
ExitApp
Expand All @@ -181,7 +182,7 @@ ConfigLock(名义:="")
}
CLX_DontReload := 1

FileAppend %名义%, % CLX_ConfigPath ".lock"
FileAppend %reason%, % CLX_ConfigPath ".lock"
return True
}
ConfigUnlock()
Expand Down
Binary file modified Core/lang.ini
Binary file not shown.
28 changes: 28 additions & 0 deletions DevTools/setup.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; -- setup.iss --
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING .ISS SCRIPT FILES!

[Setup]
AppName=CapsLockX
AppVersion=1.34.6
WizardStyle=modern
; DefaultDirName={autopf}\CapsLockX
DefaultDirName={userappdata}\CapsLockX
DefaultGroupName=CapsLockX
UninstallDisplayIcon={app}\CapsLockX.exe
Compression=lzma2
SolidCompression=yes
OutputDir=userdocs:Inno Setup CapsLockX Output

[Files]
Source: "README.md"; DestDir: "{app}"; Flags: isreadme
Source: "CapsLockX.exe"; DestDir: "{app}"
Source: "CapsLockX.ahk"; DestDir: "{app}"
Source: "Core\*"; DestDir: "{app}"
Source: "Data\*"; DestDir: "{app}"
Source: "docs\*"; DestDir: "{app}"
Source: "Lib\*"; DestDir: "{app}"
Source: "Modules\*"; DestDir: "{app}"
Source: "Tools\*"; DestDir: "{app}"

[Icons]
Name: "{group}\CapsLockX"; Filename: "{app}\CapsLockX.exe"
195 changes: 0 additions & 195 deletions Modules/App-ScreenRotate.ahk

This file was deleted.

8 changes: 0 additions & 8 deletions Modules/App-ScreenRotate.md

This file was deleted.

2 changes: 2 additions & 0 deletions Modules/CLX-Brainstorm.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ return
#if brainstorming

esc:: stop_brainstorm()
`:: stop_brainstorm()


#if

Expand Down
Loading

0 comments on commit 324d81d

Please sign in to comment.