Backend update: macro/open endpoint works as intended.

This commit is contained in:
Jesse Malotaux 2025-04-28 13:44:45 +02:00
parent 4789e5d1a9
commit 97af604cb6
2 changed files with 141 additions and 61 deletions

View file

@ -4,69 +4,140 @@ import (
"strings" "strings"
) )
func Translate(code string) string { var translations = map[string]string{
translations := map[string]string{ "ArrowUp": "up",
"ArrowUp": "up", "ArrowDown": "down",
"ArrowDown": "down", "ArrowRight": "right",
"ArrowRight": "right", "ArrowLeft": "left",
"ArrowLeft": "left", "Meta": "cmd",
"Meta": "cmd", "MetaLeft": "lcmd",
"MetaLeft": "lcmd", "MetaRight": "rcmd",
"MetaRight": "rcmd", "Alt": "alt",
"Alt": "alt", "AltLeft": "lalt",
"AltLeft": "lalt", "AltRight": "ralt",
"AltRight": "ralt", "Control": "ctrl",
"Control": "ctrl", "ControlLeft": "lctrl",
"ControlLeft": "lctrl", "ControlRight": "rctrl",
"ControlRight": "rctrl", "Shift": "shift",
"Shift": "shift", "ShiftLeft": "lshift",
"ShiftLeft": "lshift", "ShiftRight": "rshift",
"ShiftRight": "rshift", "AudioVolumeMute": "audio_mute",
"AudioVolumeMute": "audio_mute", "AudioVolumeDown": "audio_vol_down",
"AudioVolumeDown": "audio_vol_down", "AudioVolumeUp": "audio_vol_up",
"AudioVolumeUp": "audio_vol_up", "MediaTrackPrevious": "audio_prev",
"MediaTrackPrevious": "audio_prev", "MediaTrackNext": "audio_next",
"MediaTrackNext": "audio_next", "MediaPlayPause": "audio_play|audio_pause",
"MediaPlayPause": "audio_play|audio_pause", "Numpad0": "num0",
"Numpad0": "num0", "Numpad1": "num1",
"Numpad1": "num1", "Numpad2": "num2",
"Numpad2": "num2", "Numpad3": "num3",
"Numpad3": "num3", "Numpad4": "num4",
"Numpad4": "num4", "Numpad5": "num5",
"Numpad5": "num5", "Numpad6": "num6",
"Numpad6": "num6", "Numpad7": "num7",
"Numpad7": "num7", "Numpad8": "num8",
"Numpad8": "num8", "Numpad9": "num9",
"Numpad9": "num9", "NumLock": "num_lock",
"NumLock": "num_lock", "NumpadDecimal": "num.",
"NumpadDecimal": "num.", "NumpadAdd": "num+",
"NumpadAdd": "num+", "NumpadSubtract": "num-",
"NumpadSubtract": "num-", "NumpadMultiply": "num*",
"NumpadMultiply": "num*", "NumpadDivide": "num/",
"NumpadDivide": "num/", "NumpadEnter": "num_enter",
"NumpadEnter": "num_enter", "Clear": "num_clear",
"Clear": "num_clear", "BracketLeft": "[",
"BracketLeft": "[", "BracketRight": "]",
"BracketRight": "]", "Quote": "'",
"Quote": "'", "Semicolon": ";",
"Semicolon": ";", "Backquote": "`",
"Backquote": "`", "Backslash": "\\",
"Backslash": "\\", "IntlBackslash": "\\",
"IntlBackslash": "\\", "Slash": "/",
"Slash": "/", "Comma": ",",
"Comma": ",", "Period": ".",
"Period": ".", "Equal": "=",
"Equal": "=", "Minus": "-",
"Minus": "-",
}
if translations[code] == "" {
return strings.ToLower(code)
}
return translations[code]
} }
func Translate(code string) string {
if val, ok := translations[code]; ok {
return val
}
return strings.ToLower(code)
}
func ReverseTranslate(name string) string {
for key, value := range translations {
if value == name {
return key
}
}
return name
}
// func Translate(code string) string {
// translations := map[string]string{
// "ArrowUp": "up",
// "ArrowDown": "down",
// "ArrowRight": "right",
// "ArrowLeft": "left",
// "Meta": "cmd",
// "MetaLeft": "lcmd",
// "MetaRight": "rcmd",
// "Alt": "alt",
// "AltLeft": "lalt",
// "AltRight": "ralt",
// "Control": "ctrl",
// "ControlLeft": "lctrl",
// "ControlRight": "rctrl",
// "Shift": "shift",
// "ShiftLeft": "lshift",
// "ShiftRight": "rshift",
// "AudioVolumeMute": "audio_mute",
// "AudioVolumeDown": "audio_vol_down",
// "AudioVolumeUp": "audio_vol_up",
// "MediaTrackPrevious": "audio_prev",
// "MediaTrackNext": "audio_next",
// "MediaPlayPause": "audio_play|audio_pause",
// "Numpad0": "num0",
// "Numpad1": "num1",
// "Numpad2": "num2",
// "Numpad3": "num3",
// "Numpad4": "num4",
// "Numpad5": "num5",
// "Numpad6": "num6",
// "Numpad7": "num7",
// "Numpad8": "num8",
// "Numpad9": "num9",
// "NumLock": "num_lock",
// "NumpadDecimal": "num.",
// "NumpadAdd": "num+",
// "NumpadSubtract": "num-",
// "NumpadMultiply": "num*",
// "NumpadDivide": "num/",
// "NumpadEnter": "num_enter",
// "Clear": "num_clear",
// "BracketLeft": "[",
// "BracketRight": "]",
// "Quote": "'",
// "Semicolon": ";",
// "Backquote": "`",
// "Backslash": "\\",
// "IntlBackslash": "\\",
// "Slash": "/",
// "Comma": ",",
// "Period": ".",
// "Equal": "=",
// "Minus": "-",
// }
// if translations[code] == "" {
// return strings.ToLower(code)
// }
// return translations[code]
// }
// Redundant translation because tolower can be used // Redundant translation because tolower can be used
// "Backspace": "backspace", // "Backspace": "backspace",
// "Delete": "delete", // "Delete": "delete",

View file

@ -150,5 +150,14 @@ func OpenMacro(w http.ResponseWriter, r *http.Request) {
return return
} }
// Walk through the macro file and reverse translate codes
for i, action := range macroFile {
if actionType, ok := action["type"].(string); ok && actionType == "key" {
if code, ok := action["code"].(string); ok {
macroFile[i]["code"] = helper.ReverseTranslate(code)
}
}
}
json.NewEncoder(w).Encode(macroFile) json.NewEncoder(w).Encode(macroFile)
} }