mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Backend update: macro/open endpoint works as intended.
This commit is contained in:
parent
4789e5d1a9
commit
97af604cb6
2 changed files with 141 additions and 61 deletions
|
|
@ -4,8 +4,7 @@ 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",
|
||||||
|
|
@ -60,12 +59,84 @@ func Translate(code string) string {
|
||||||
"Minus": "-",
|
"Minus": "-",
|
||||||
}
|
}
|
||||||
|
|
||||||
if translations[code] == "" {
|
func Translate(code string) string {
|
||||||
|
if val, ok := translations[code]; ok {
|
||||||
|
return val
|
||||||
|
}
|
||||||
return strings.ToLower(code)
|
return strings.ToLower(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
return translations[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",
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue