fixed path resolution

This commit is contained in:
Luxferre
2024-09-19 15:51:46 +03:00
parent e545d2c1a8
commit 51f28a6397
5 changed files with 22 additions and 8 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ func init() {
bro := webview.New(debug) /* create a browser instance */ bro := webview.New(debug) /* create a browser instance */
bro.SetSize(320, 720, webview.HintNone) bro.SetSize(320, 720, webview.HintNone)
defer bro.Destroy() defer bro.Destroy()
bro.SetTitle("StreamGoose v0.0.1") bro.SetTitle("StreamGoose")
bro.Navigate("http://" + target_addr) bro.Navigate("http://" + target_addr)
bro.Run() bro.Run()
} }
+3 -2
View File
@@ -15,6 +15,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"io/ioutil" "io/ioutil"
"path/filepath"
) )
/* global API root URL placeholder */ /* global API root URL placeholder */
@@ -124,11 +125,11 @@ func oc_process_message(rawmsg map[string]interface{}) {
/* entry point */ /* entry point */
func owncast_run(config map[string]interface{}) { func owncast_run(config map[string]interface{}) {
token_path := "auth/oc-token.txt" token_path := filepath.Join(APP_ROOT_DIR, "auth", "oc-token.txt")
token, err := ioutil.ReadFile(token_path) token, err := ioutil.ReadFile(token_path)
token_err_msg := "[owncast] No Owncast token file provided or it is empty. " token_err_msg := "[owncast] No Owncast token file provided or it is empty. "
token_err_msg += "Please generate a token in your Owncast admin panel " token_err_msg += "Please generate a token in your Owncast admin panel "
token_err_msg += "and paste it into the auth/oc-token.txt file!" token_err_msg += "and paste it into the " + token_path + " file!"
if err != nil { if err != nil {
log.Fatal(token_err_msg + "\nDetailed error: ", err) log.Fatal(token_err_msg + "\nDetailed error: ", err)
} }
+14 -2
View File
@@ -15,6 +15,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"io/ioutil" "io/ioutil"
"path/filepath"
) )
/* main chat message structure */ /* main chat message structure */
@@ -30,6 +31,7 @@ type ChatMessage struct {
var global_msg_id uint64 = 0 /* track global message ID */ var global_msg_id uint64 = 0 /* track global message ID */
var message_transport chan ChatMessage /* global message channel */ var message_transport chan ChatMessage /* global message channel */
var sse_transports []chan string /* SSE output channels */ var sse_transports []chan string /* SSE output channels */
var APP_ROOT_DIR string /* global application root directory */
/* headless behaviour by default */ /* headless behaviour by default */
var goose_start_gui = func(config map[string]interface{}) { var goose_start_gui = func(config map[string]interface{}) {
@@ -130,7 +132,17 @@ func sseHandler(w http.ResponseWriter, r *http.Request) {
/* entry point */ /* entry point */
func main() { func main() {
config_path := "config.json" /* detect current executable directory and load the config from there */
ex, err := os.Executable()
if err != nil {
panic(err)
}
ex, err = filepath.EvalSymlinks(ex)
if err != nil {
panic(err)
}
APP_ROOT_DIR = filepath.Dir(ex)
config_path := filepath.Join(APP_ROOT_DIR, "config.json")
if len(os.Args) > 1 { if len(os.Args) > 1 {
config_path = os.Args[1] config_path = os.Args[1]
} }
@@ -158,7 +170,7 @@ func main() {
/* serve the GET /sse */ /* serve the GET /sse */
http.HandleFunc("/sse", sseHandler) http.HandleFunc("/sse", sseHandler)
/* serve the webroot directory */ /* serve the webroot directory */
fs := http.FileServer(http.Dir("./webroot")) fs := http.FileServer(http.Dir(filepath.Join(APP_ROOT_DIR, "webroot")))
http.Handle("/", fs) http.Handle("/", fs)
log.Println(fmt.Sprintf("Listening on %s\n", target_addr)) log.Println(fmt.Sprintf("Listening on %s\n", target_addr))
err = http.ListenAndServe(target_addr, nil) err = http.ListenAndServe(target_addr, nil)
+3 -2
View File
@@ -14,6 +14,7 @@ import (
"time" "time"
"net" "net"
"io/ioutil" "io/ioutil"
"path/filepath"
"unicode/utf8" "unicode/utf8"
) )
@@ -143,11 +144,11 @@ func tw_process_message(rawmsg string) {
/* entry point */ /* entry point */
func twitch_run(config map[string]interface{}) { func twitch_run(config map[string]interface{}) {
token_path := "auth/twitch-token.txt" token_path := filepath.Join(APP_ROOT_DIR, "auth", "twitch-token.txt")
token, err := ioutil.ReadFile(token_path) token, err := ioutil.ReadFile(token_path)
token_err_msg := "[twitch] No Twitch token file provided or it is empty. " token_err_msg := "[twitch] No Twitch token file provided or it is empty. "
token_err_msg += "Please visit https://twitchapps.com/tmi/, generate a token there " token_err_msg += "Please visit https://twitchapps.com/tmi/, generate a token there "
token_err_msg += "and paste it into the auth/twitch-token.txt file!" token_err_msg += "and paste it into the " + token_path +" file!"
if err != nil { if err != nil {
log.Fatal(token_err_msg + "\nDetailed error: ", err) log.Fatal(token_err_msg + "\nDetailed error: ", err)
} }
+1 -1
View File
@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset=utf-8> <meta charset=utf-8>
<title>StreamGoose v0.0.1</title> <title>StreamGoose</title>
<link rel=stylesheet href="style.css"> <link rel=stylesheet href="style.css">
</head> </head>
<body> <body>