diff --git a/Makefile b/Makefile index d1f5dde..b8bb0b8 100644 --- a/Makefile +++ b/Makefile @@ -19,4 +19,4 @@ build: deps CGO_ENABLED=$(CGO_ENABLED) GOARCH=amd64 GOOS=linux $(CC) $(CFLAGS) -o $(BUILD_DIR)/$(LINUX_BIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" watch: - gowatch -o build/app-live-linux-amd64 + gowatch -o build/app-live-linux-amd64 -args='./config.yaml' diff --git a/build/app-live-linux-amd64 b/build/app-live-linux-amd64 deleted file mode 100755 index 51ed60f..0000000 Binary files a/build/app-live-linux-amd64 and /dev/null differ diff --git a/config.go b/config.go new file mode 100644 index 0000000..0e3c593 --- /dev/null +++ b/config.go @@ -0,0 +1,44 @@ +package main + +import ( + "gopkg.in/yaml.v3" + "os" +) + +type ServerAuthConfig struct { + Username string `yaml:"username"` + Password string `yaml:"password"` +} + +type ServerConfig struct { + Listen string `yaml:"listen"` + Auth ServerAuthConfig `yaml:"auth"` +} + +type RemoteConfigItem struct { + Type string `yaml:"type"` + Label string `yaml:"label"` + Items []map[string]string `yaml:"items"` +} + +type Config struct { + Server ServerConfig `yaml:"server"` + Remote map[string][]RemoteConfigItem `yaml:"remote"` +} + +func createConfigFromFile(file string) (Config, error) { + data, err := os.ReadFile(file) + value := Config{} + + if err != nil { + return value, err + } + + err = yaml.Unmarshal(data, &value) + + if err != nil { + return value, err + } + + return value, nil +} diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..c00a5b5 --- /dev/null +++ b/config.yaml @@ -0,0 +1,48 @@ +server: + listen: 0.0.0.0:4000 + auth: + username: admin + password: admin + +remote: + Keyboard: + - type: live_text + label: Live text + - type: text + label: Text + - type: keys + label: Keys + - type: shortcuts + label: Shortcuts + i3: + - type: messages + label: Workspaces + items: + - '1. DBL': '{"type":"workspace","value":"1. DBL"}' + - '2. WWW': '{"type":"workspace","value":"2. WWW"}' + - '3. MAIL': '{"type":"workspace","value":"3. MAIL"}' + - '4. IM': '{"type":"workspace","value":"4. IM"}' + - '5': '{"type":"workspace","value":"5"}' + - '6. MEDIA': '{"type":"workspace","value":"6. MEDIA"}' + - '7. DEV': '{"type":"workspace","value":"7. DEV"}' + - '8. DEV': '{"type":"workspace","value":"8. DEV"}' + - '9. DEV': '{"type":"workspace","value":"9. DEV"}' + - '10': '{"type":"workspace","value":"10"}' + - '11': '{"type":"workspace","value":"11"}' + - '12': '{"type":"workspace","value":"12"}' + + - type: messages + label: Software + items: [] + Mouse: + - type: mouse + Media: + - type: spotify + label: Spotify + - type: volume + label: Volume + Desktop: + - type: screenshot + label: Screenshot + - type: live_video + label: Live video diff --git a/go.mod b/go.mod index 9525760..5d978de 100644 --- a/go.mod +++ b/go.mod @@ -21,4 +21,5 @@ require ( golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.12.0 // indirect golang.org/x/time v0.3.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 45ae588..6b231eb 100644 --- a/go.sum +++ b/go.sum @@ -65,3 +65,5 @@ golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/home_controller.go b/home_controller.go index 04eb3b2..fe141fd 100644 --- a/home_controller.go +++ b/home_controller.go @@ -5,6 +5,12 @@ import ( "net/http" ) -func homeController(c echo.Context) error { - return c.HTML(http.StatusOK, view("views/page/home.html", nil)) +type HomeViewParams struct { + Config Config +} + +func homeController(c echo.Context) error { + return c.HTML(http.StatusOK, view("views/page/home.html", HomeViewParams{ + Config: config, + })) } diff --git a/main.go b/main.go index a3460a6..6ee5235 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "crypto/subtle" "embed" + "fmt" rice "github.com/GeertJohan/go.rice" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -16,7 +17,8 @@ var ( //go:embed static staticFiles embed.FS //go:embed views/layout views/page - views embed.FS + views embed.FS + config Config ) func main() { @@ -31,6 +33,23 @@ func main() { RI3_BIND = "0.0.0.0:4000" } + if len(os.Args) != 2 { + fmt.Errorf("Configuration requried") + os.Exit(1) + } + + value, err := createConfigFromFile(os.Args[1]) + + if err != nil { + fmt.Printf("%+v\n", err) + fmt.Errorf("Configuration error") + os.Exit(1) + } + + config = value + + fmt.Printf("%+v\n", config) + assetHandler := http.FileServer(rice.MustFindBox("static").HTTPBox()) e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) { diff --git a/rice-box.go b/rice-box.go index 44de7f7..97f59a2 100644 --- a/rice-box.go +++ b/rice-box.go @@ -36,9 +36,9 @@ func init() { } file6 := &embedded.EmbeddedFile{ Filename: "main.css", - FileModTime: time.Unix(1692909231, 0), + FileModTime: time.Unix(1692955090, 0), - Content: string("a {\n color: #1e3650;\n}\n\n.btn-primary {\n background: #1e3650;\n border-color: #0e2640;\n}\n\n.nav-pills .nav-link.active {\n background: #1e3650;\n}\n\n.nav-pills .nav-link {\n padding-left: 3px;\n padding-right: 3px;\n}\n\n.nav-link {\n font-size: 10px;\n}\n\n.legend {\n color: #777;\n margin: 3px 0;\n padding: 3px 0;\n border-bottom: 1px solid #eee;\n font-size: 11px;\n text-transform: uppercase;\n}\n\n.btn-sm {\n font-size: 9px;\n}\n\n.select2 {\n min-width: 100%;\n}\n\n.line {\n height: 3px;\n}\n\n.pane {\n display: none;\n}\n\n.no-margin {\n margin: 0;\n}\n\n.no-padding {\n padding: 0;\n}\n\n.no-radius {\n border-radius: 0 !important;\n}\n\n#pointer {\n height: calc(100vh - 80px);\n margin: auto;\n background: #ccc;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n -khtml-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n#scrollbar {\n height: calc(100vh - 80px);\n width: 50px;\n background: #333;\n position: absolute;\n z-index: 100;\n right: 0;\n}\n\n.fullscreen #scrollbar {\n height: calc(100vh - 150px);\n}\n\n.fullscreen #pointer {\n height: calc(100vh - 150px);\n}\n\n#pane-pointer .form-group {\n padding: 0;\n margin: 0;\n}\n\n#pointer-buttons {\n position: absolute;\n margin-top: -42px;\n width: 100%;\n z-index: 110;\n}\n\n#pointer-buttons .btn {\n height: 50px;\n}\n\n#disconneced {\n position: absolute;\n top: 0;\n width: 100%;\n background: #ff6161;\n color: #fff;\n padding: 5px;\n}\n\n#disconneced a {\n color: #fff;\n font-weight: bold;\n}\n\n#nav {\n border-bottom: 2px solid #1e3650;\n}\n\n#shortcuts_special_keys input {\n display: none;\n}\n\n#response {\n position: absolute;\n bottom: 0;\n width: 100%;\n color: #fff;\n background: #748c26;\n padding: 5px;\n display: none;\n}\n\n#screenshot img {\n max-width: 100%;\n margin-top: 10px;\n cursor: pointer;\n}\n"), + Content: string("a {\n color: #1e3650;\n}\n\n.btn-primary {\n background: #1e3650;\n border-color: #0e2640;\n}\n\n.nav-pills .nav-link.active {\n background: #1e3650;\n}\n\n.nav-pills .nav-link {\n padding-left: 3px;\n padding-right: 3px;\n}\n\n.nav-link {\n font-size: 10px;\n}\n\n.legend {\n color: #777;\n margin: 3px 0;\n padding: 3px 0;\n border-bottom: 1px solid #eee;\n font-size: 11px;\n text-transform: uppercase;\n}\n\n.btn-sm {\n font-size: 9px;\n}\n\n.select2 {\n min-width: 100%;\n}\n\n.line {\n height: 3px;\n}\n\n.pane {\n display: none;\n}\n\n.no-margin {\n margin: 0;\n}\n\n.no-padding {\n padding: 0;\n}\n\n.no-radius {\n border-radius: 0 !important;\n}\n\n#pointer {\n height: calc(100vh - 80px);\n margin: auto;\n background: #ccc;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n -khtml-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n#scrollbar {\n height: calc(100vh - 80px);\n width: 50px;\n background: #333;\n position: absolute;\n z-index: 100;\n right: 0;\n}\n\n.fullscreen #scrollbar {\n height: calc(100vh - 150px);\n}\n\n.fullscreen #pointer {\n height: calc(100vh - 150px);\n}\n\n#pane-pointer .form-group {\n padding: 0;\n margin: 0;\n}\n\n#pointer-buttons {\n margin-top: -42px;\n width: 100%;\n z-index: 110;\n}\n\n#pointer-buttons .btn {\n height: 50px;\n}\n\n#disconneced {\n position: absolute;\n top: 0;\n width: 100%;\n background: #ff6161;\n color: #fff;\n padding: 5px;\n}\n\n#disconneced a {\n color: #fff;\n font-weight: bold;\n}\n\n#nav {\n border-bottom: 2px solid #1e3650;\n}\n\n#shortcuts_special_keys input {\n display: none;\n}\n\n#response {\n position: absolute;\n bottom: 0;\n width: 100%;\n color: #fff;\n background: #748c26;\n padding: 5px;\n display: none;\n}\n\n#screenshot img {\n max-width: 100%;\n margin-top: 10px;\n cursor: pointer;\n}\n"), } file7 := &embedded.EmbeddedFile{ Filename: "main.js", @@ -50,7 +50,7 @@ func init() { // define dirs dir1 := &embedded.EmbeddedDir{ Filename: "", - DirModTime: time.Unix(1692909534, 0), + DirModTime: time.Unix(1692955097, 0), ChildFiles: []*embedded.EmbeddedFile{ file2, // "bootstrap.bundle.min.js" file3, // "bootstrap.min.css" @@ -68,7 +68,7 @@ func init() { // register embeddedBox embedded.RegisterEmbeddedBox(`static`, &embedded.EmbeddedBox{ Name: `static`, - Time: time.Unix(1692909534, 0), + Time: time.Unix(1692955097, 0), Dirs: map[string]*embedded.EmbeddedDir{ "": dir1, }, diff --git a/static/main.css b/static/main.css index 05dc9a7..3d53be6 100644 --- a/static/main.css +++ b/static/main.css @@ -92,7 +92,6 @@ a { } #pointer-buttons { - position: absolute; margin-top: -42px; width: 100%; z-index: 110; diff --git a/views/page/home.html b/views/page/home.html index ed15cec..eb39add 100644 --- a/views/page/home.html +++ b/views/page/home.html @@ -4,21 +4,11 @@
-
-
-
-

Live text

-
-
- -
+ {{range $key, $values := .Config.Remote}} +
+ {{range $key2, $value := $values}} +
+ {{if ne $value.Label ""}} +
+

{{$value.Label}}

+
+ {{end}} + + {{if eq $value.Type "live_text"}} +
+ +
+ {{end}} + + {{if eq $value.Type "text"}} +
+ +
+
+ + +
+ {{end}} + + {{if eq $value.Type "keys"}} +
+ + + + +
+
+
+ + + + +
+ {{end}} + + {{if eq $value.Type "shortcuts"}} +
+ + + + +
+
+ +
+
+ + +
+ {{end}} + + {{if eq $value.Type "spotify"}} +
+ + + +
+ {{end}} + + {{if eq $value.Type "volume"}} +
+ + + + + +
+
+
+ + +
+ {{end}} + + {{if eq $value.Type "mouse"}} +
+ +
+
+
+
+ +
+ {{end}} +
+ {{end}}
-
-
-

TEXT

-
-
- -
-
- - -
-
-
-
-

Keys

-
-
- - - - -
-
-
- - - - -
-
-
-
-

Shortcuts

-
-
- - - - -
-
- -
-
- - -
-
-
+ {{end}} +
@@ -121,84 +149,8 @@
-
-
-

Software

-
-
- - -
- -
-

UI

-
-
- - - - - -
-
-
- - -
- -
-

Movie

-
-
- - -
-
-
- - - - -
-
-
-
- -
-
-
-
- -
-
- -
-
-

Spotify

-
-
- - - -
-
-

Volume

-
-
- - - - - -
-
-
- - -
-

Desktop