Added headless build support
This commit is contained in:
+11
-2
@@ -2,15 +2,24 @@ LDFLAGS = -s -w
|
||||
LDFLAGS_WIN = -H windowsgui -s -w
|
||||
GOFLAGS = -trimpath
|
||||
SOURCES = server.go twitch.go youtube.go owncast.go kick.go
|
||||
SOURCES_GUI = $(SOURCES) gui.go
|
||||
BIN = streamgoose
|
||||
|
||||
unix:
|
||||
go mod tidy
|
||||
go build -o $(BIN) $(GOFLAGS) -ldflags "$(LDFLAGS)" $(SOURCES)
|
||||
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN) $(SOURCES_GUI)
|
||||
|
||||
unix-headless:
|
||||
go mod tidy
|
||||
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN) $(SOURCES)
|
||||
|
||||
win64:
|
||||
go mod tidy
|
||||
GOOS=windows GOARCH=amd64 go build -o $(BIN).exe $(GOFLAGS) -ldflags "$(LDFLAGS_WIN)" $(SOURCES)
|
||||
GOOS=windows GOARCH=amd64 go build $(GOFLAGS) -ldflags "$(LDFLAGS_WIN)" -o $(BIN).exe $(SOURCES_GUI)
|
||||
|
||||
win64-headless:
|
||||
go mod tidy
|
||||
GOOS=windows GOARCH=amd64 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN).exe $(SOURCES)
|
||||
|
||||
clean:
|
||||
rm $(BIN)
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
StreamGoose UI — Go reference implementation
|
||||
|
||||
Created by Luxferre in 2024, released into public domain
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"centrifuge.hectabit.org/HectaBit/webview_go" /* for UI launch */
|
||||
)
|
||||
|
||||
/* override GUI entry point */
|
||||
func init() {
|
||||
goose_start_gui = func(config map[string]interface{}) {
|
||||
/* target server listening address */
|
||||
target_addr := fmt.Sprintf("%s:%d", config["server_listen_ip"].(string), int(config["server_port"].(float64)))
|
||||
|
||||
/* start the GUI */
|
||||
debug := false
|
||||
if _, ok := config["debug"]; ok && config["debug"].(bool) == true {
|
||||
debug = true
|
||||
}
|
||||
bro := webview.New(debug) /* create a browser instance */
|
||||
bro.SetSize(320, 720, webview.HintNone)
|
||||
defer bro.Destroy()
|
||||
bro.SetTitle("StreamGoose v0.0.1")
|
||||
bro.Navigate("http://" + target_addr)
|
||||
bro.Run()
|
||||
}
|
||||
}
|
||||
+14
-15
@@ -9,13 +9,12 @@ import (
|
||||
"os"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"strings"
|
||||
"slices"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
/* external */
|
||||
"centrifuge.hectabit.org/HectaBit/webview_go" /* for UI launch */
|
||||
)
|
||||
|
||||
/* main chat message structure */
|
||||
@@ -31,7 +30,17 @@ type ChatMessage struct {
|
||||
var global_msg_id uint64 = 0 /* track global message ID */
|
||||
var message_transport chan ChatMessage /* global message channel */
|
||||
var sse_transports []chan string /* SSE output channels */
|
||||
var bro webview.WebView /* global browser instance handle */
|
||||
|
||||
/* headless behaviour by default */
|
||||
var goose_start_gui = func(config map[string]interface{}) {
|
||||
/* target server listening address */
|
||||
const fmt_str = "[headless] Connect to http://%s:%d in any browser to see the chat window"
|
||||
log.Printf(fmt_str, config["server_listen_ip"].(string), int(config["server_port"].(float64)))
|
||||
/* just do nothing except sleep in the main thread */
|
||||
for {
|
||||
time.Sleep(time.Duration(3600) * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
/* escape HTML entities in JS parameters */
|
||||
func esc(s string) string {
|
||||
@@ -157,7 +166,6 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
if _, ok := config["tw_backend_enabled"]; ok && config["tw_backend_enabled"].(bool) == true {
|
||||
go twitch_run(config) /* start the Twitch backend */
|
||||
@@ -175,16 +183,7 @@ func main() {
|
||||
go kick_run(config) /* start the Kick backend */
|
||||
}
|
||||
|
||||
/* start the GUI */
|
||||
debug := false
|
||||
if _, ok := config["debug"]; ok && config["debug"].(bool) == true {
|
||||
debug = true
|
||||
}
|
||||
bro = webview.New(debug) /* create a browser instance */
|
||||
bro.SetSize(320, 720, webview.HintNone)
|
||||
defer bro.Destroy()
|
||||
bro.SetTitle("StreamGoose v0.0.1")
|
||||
bro.Navigate("http://" + target_addr)
|
||||
bro.Run()
|
||||
/* start the GUI from gui.go file */
|
||||
goose_start_gui(config)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user