Refactor: Moved Go app to the root and fixed links.

This commit is contained in:
Jesse Malotaux 2025-05-03 20:56:15 +02:00
parent d1de67910d
commit 7157d43168
28 changed files with 100 additions and 164 deletions

17
.air.toml Normal file
View file

@ -0,0 +1,17 @@
# Working directory
root = "."
# The main Go file
main = "main.go"
bin = "tmp/main.exe"
# Watching all Go files, excluding certain directories
[build]
cmd = "go build -o ./tmp/main.exe main.go"
include_ext = ["go"]
exclude_dir = ["fe", "panels", "builds"]
# Restart on file changes
[log]
time = true

8
.gitignore vendored
View file

@ -1,9 +1,11 @@
.env .env
config.js config.js
be/devices/* devices/*
be/tmp/ tmp/
be/log.txt log.txt
Macrame.exe
public public
macros/* macros/*

View file

@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package app package app
import ( import (
"be/app/helper" "macrame/app/helper"
"mime" "mime"
"net/http" "net/http"
"path/filepath" "path/filepath"
@ -45,7 +45,7 @@ func ApiCORS(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http
} }
func ApiGet(w http.ResponseWriter, r *http.Request) { func ApiGet(w http.ResponseWriter, r *http.Request) {
root, err := filepath.Abs("../public") root, err := filepath.Abs("public")
if err != nil { if err != nil {
MCRMLog("ApiGet Abs Error: ", err) MCRMLog("ApiGet Abs Error: ", err)
return return

View file

@ -22,10 +22,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package app package app
import ( import (
"be/app/helper"
"be/app/structs"
"encoding/json" "encoding/json"
"fmt" "fmt"
"macrame/app/helper"
"macrame/app/structs"
"math/rand" "math/rand"
"net" "net"
"net/http" "net/http"

View file

@ -28,8 +28,8 @@ import (
"net/http" "net/http"
"strings" "strings"
"be/app/structs" "macrame/app/structs"
. "be/app/structs" . "macrame/app/structs"
) )
func EndpointAccess(w http.ResponseWriter, r *http.Request) (bool, string, error) { func EndpointAccess(w http.ResponseWriter, r *http.Request) (bool, string, error) {

View file

@ -30,9 +30,10 @@ import (
"strings" "strings"
) )
var configPath = "../public/config.js" var configPath = "public/config.js"
func EnvGet(key string) string { func EnvGet(key string) string {
if !configFileExists() { if !configFileExists() {
CreateConfigFile(configPath) CreateConfigFile(configPath)
CheckFeDevDir() CheckFeDevDir()
@ -64,9 +65,10 @@ func configFileExists() bool {
func CheckFeDevDir() { func CheckFeDevDir() {
log.Println("Checking FE dev directory...") log.Println("Checking FE dev directory...")
_, err := os.Stat("../fe") _, err := os.Stat("fe")
if err != nil { if err != nil {
log.Println("Error checking FE dev directory:", err)
return return
} }
@ -74,14 +76,14 @@ func CheckFeDevDir() {
} }
func copyConfigToFe() { func copyConfigToFe() {
data, err := os.ReadFile("../public/config.js") data, err := os.ReadFile(configPath)
if err != nil { if err != nil {
log.Println("Error reading config.js:", err) log.Println("Error reading config.js:", err)
return return
} }
if err := os.WriteFile("../fe/config.js", data, 0644); err != nil { if err := os.WriteFile("fe/config.js", data, 0644); err != nil {
log.Println("Error writing config.js:", err) log.Println("Error writing config.js:", err)
} }
} }

View file

@ -31,8 +31,8 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"be/app/helper" "macrame/app/helper"
"be/app/structs" "macrame/app/structs"
) )
func CheckMacro(w http.ResponseWriter, r *http.Request) { func CheckMacro(w http.ResponseWriter, r *http.Request) {
@ -47,7 +47,7 @@ func CheckMacro(w http.ResponseWriter, r *http.Request) {
var filename = helper.FormatMacroFileName(req.Macro) var filename = helper.FormatMacroFileName(req.Macro)
macroFile, err := helper.ReadMacroFile(fmt.Sprintf("../macros/%s.json", filename)) macroFile, err := helper.ReadMacroFile(fmt.Sprintf("macros/%s.json", filename))
if macroFile != nil && err == nil { if macroFile != nil && err == nil {
json.NewEncoder(w).Encode(true) json.NewEncoder(w).Encode(true)
@ -85,7 +85,7 @@ func SaveMacro(w http.ResponseWriter, r *http.Request) {
return return
} }
err = os.WriteFile("../macros/"+helper.FormatMacroFileName(newMacro.Name)+".json", stepsJSON, 0644) err = os.WriteFile("macros/"+helper.FormatMacroFileName(newMacro.Name)+".json", stepsJSON, 0644)
if err != nil { if err != nil {
MCRMLog("SaveMacro WriteFile Error: ", err) MCRMLog("SaveMacro WriteFile Error: ", err)
return return
@ -117,7 +117,7 @@ func simplifyMacro(step structs.Step) map[string]interface{} {
} }
func ListMacros(w http.ResponseWriter, r *http.Request) { func ListMacros(w http.ResponseWriter, r *http.Request) {
dir := "../macros" dir := "macros"
files, err := os.ReadDir(dir) files, err := os.ReadDir(dir)
if err != nil { if err != nil {
MCRMLog("ListMacros ReadDir Error: ", err) MCRMLog("ListMacros ReadDir Error: ", err)
@ -154,7 +154,7 @@ func DeleteMacro(w http.ResponseWriter, r *http.Request) {
var filename = helper.FormatMacroFileName(req.Macro) var filename = helper.FormatMacroFileName(req.Macro)
err = os.Remove("../macros/" + filename + ".json") err = os.Remove("macros/" + filename + ".json")
if err != nil { if err != nil {
MCRMLog("DeleteMacro Remove Error: ", err) MCRMLog("DeleteMacro Remove Error: ", err)
@ -180,7 +180,7 @@ func PlayMacro(data string, w http.ResponseWriter, r *http.Request) {
MCRMLog("Playing Macro: ", macro) MCRMLog("Playing Macro: ", macro)
var filename = helper.FormatMacroFileName(macro) var filename = helper.FormatMacroFileName(macro)
var filepath = fmt.Sprintf("../macros/%s.json", filename) var filepath = fmt.Sprintf("macros/%s.json", filename)
macroFile, err := helper.ReadMacroFile(filepath) macroFile, err := helper.ReadMacroFile(filepath)
if err != nil { if err != nil {
@ -208,7 +208,7 @@ func OpenMacro(w http.ResponseWriter, r *http.Request) {
return return
} }
macroFile, err := helper.ReadMacroFile(fmt.Sprintf("../macros/%s.json", req.Macro)) macroFile, err := helper.ReadMacroFile(fmt.Sprintf("macros/%s.json", req.Macro))
if err != nil { if err != nil {
MCRMLog("OpenMacro ReadMacroFile Error: ", err) MCRMLog("OpenMacro ReadMacroFile Error: ", err)

View file

@ -22,17 +22,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package app package app
import ( import (
"be/app/helper"
"be/app/structs"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"macrame/app/helper"
"macrame/app/structs"
"net/http" "net/http"
"os" "os"
"strings" "strings"
) )
func PanelList(w http.ResponseWriter, r *http.Request) { func PanelList(w http.ResponseWriter, r *http.Request) {
panelDirs, err := os.ReadDir("../panels") panelDirs, err := os.ReadDir("panels")
if err != nil { if err != nil {
MCRMLog("PanelList ReadDir Error: ", err) MCRMLog("PanelList ReadDir Error: ", err)
json.NewEncoder(w).Encode(false) json.NewEncoder(w).Encode(false)
@ -59,7 +59,7 @@ func PanelList(w http.ResponseWriter, r *http.Request) {
func getPanelInfo(dirname string) structs.PanelInfo { func getPanelInfo(dirname string) structs.PanelInfo {
var panelInfo structs.PanelInfo var panelInfo structs.PanelInfo
jsonFile, err := os.ReadFile("../panels/" + dirname + "/panel.json") jsonFile, err := os.ReadFile("panels/" + dirname + "/panel.json")
if err != nil { if err != nil {
panelInfo.Name = strings.Replace(dirname, "_", " ", -1) panelInfo.Name = strings.Replace(dirname, "_", " ", -1)
@ -86,7 +86,7 @@ func getPanelThumb(dirname string) string {
for _, ext := range extensions { for _, ext := range extensions {
filename := "thumbnail" + ext filename := "thumbnail" + ext
file, err := os.Open("../panels/" + dirname + "/" + filename) file, err := os.Open("panels/" + dirname + "/" + filename)
if err != nil { if err != nil {
MCRMLog("getPanelThumb Open Error: ", err) MCRMLog("getPanelThumb Open Error: ", err)
continue continue
@ -100,8 +100,8 @@ func getPanelThumb(dirname string) string {
} }
func getPanelCode(dirname string) (html string, css string) { func getPanelCode(dirname string) (html string, css string) {
htmlBytes, _ := os.ReadFile("../panels/" + dirname + "/index.html") htmlBytes, _ := os.ReadFile("panels/" + dirname + "/index.html")
cssBytes, _ := os.ReadFile("../panels/" + dirname + "/output.css") cssBytes, _ := os.ReadFile("panels/" + dirname + "/output.css")
return string(htmlBytes), string(cssBytes) return string(htmlBytes), string(cssBytes)
} }
@ -153,7 +153,7 @@ func SavePanelJSON(w http.ResponseWriter, r *http.Request) {
return return
} }
filePath := "../panels/" + req.Dir + "/panel.json" filePath := "panels/" + req.Dir + "/panel.json"
req.Dir = "" req.Dir = ""

View file

@ -1,7 +1,7 @@
package app package app
import ( import (
"be/app/helper" "macrame/app/helper"
"os" "os"
"github.com/getlantern/systray" "github.com/getlantern/systray"

View file

@ -1,52 +0,0 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "tmp\\main.exe"
cmd = "go build -o ./tmp/main.exe ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
silent = false
time = false
[misc]
clean_on_exit = false
[proxy]
app_port = 0
enabled = false
proxy_port = 0
[screen]
clear_on_rebuild = false
keep_scroll = true

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,31 +0,0 @@
/*
Macrame is a program that enables the user to create keyboard macros and button panels.
The macros are saved as simple JSON files and can be linked to the button panels. The panels can
be created with HTML and CSS.
Copyright (C) 2025 Jesse Malotaux
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package main
import "be/app/helper"
func main() {
helper.CreateConfigFile("../public/config.js")
helper.CheckFeDevDir()
return
}

View file

Before

Width:  |  Height:  |  Size: 191 KiB

After

Width:  |  Height:  |  Size: 191 KiB

Before After
Before After

View file

@ -1,8 +1,11 @@
module be module macrame
go 1.24.0 go 1.24.1
require github.com/go-vgo/robotgo v0.110.7 require (
github.com/getlantern/systray v1.2.2
github.com/go-vgo/robotgo v0.110.7
)
require ( require (
github.com/dblohm7/wingoes v0.0.0-20240820181039-f2b84150679e // indirect github.com/dblohm7/wingoes v0.0.0-20240820181039-f2b84150679e // indirect
@ -14,7 +17,6 @@ require (
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
github.com/getlantern/systray v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect github.com/go-stack/stack v1.8.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect

View file

View file

@ -25,16 +25,15 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"strings"
"be/app" "macrame/app"
"be/app/helper" "macrame/app/helper"
) )
func main() { func main() {
app.MCRMLogInit() app.MCRMLogInit()
switchToBeDir() switchDir()
if helper.EnvGet("MCRM__PORT") == "" { if helper.EnvGet("MCRM__PORT") == "" {
app.MCRMLog("Error: MCRM__PORT is not set") app.MCRMLog("Error: MCRM__PORT is not set")
@ -53,17 +52,14 @@ func main() {
app.MCRMLog(http.ListenAndServe(":"+helper.EnvGet("MCRM__PORT"), nil)) app.MCRMLog(http.ListenAndServe(":"+helper.EnvGet("MCRM__PORT"), nil))
} }
func switchToBeDir() { func switchDir() {
cwd, err := os.Getwd() cwd, err := os.Getwd()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
if !strings.HasSuffix(cwd, "be") {
err := os.Chdir("be") log.Println(cwd)
if err != nil {
log.Fatal(err)
}
}
} }
func apiInit(w http.ResponseWriter, r *http.Request) { func apiInit(w http.ResponseWriter, r *http.Request) {