Compare commits
7 Commits
v0.0.5
...
3aac950b9c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3aac950b9c | ||
|
|
96bfcb7d0e | ||
|
|
64744e218a | ||
|
|
7d3db6b485 | ||
|
|
9cde384a36 | ||
| f9a92e4e4a | |||
| 40b13a0661 |
@@ -26,13 +26,13 @@ jobs:
|
||||
ext: ""
|
||||
- os: linux
|
||||
arch: arm
|
||||
arm_version: 6
|
||||
arm_version: 7
|
||||
ext: ""
|
||||
|
||||
steps:
|
||||
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Ensure latest Go is installed in /data/go
|
||||
run: |
|
||||
@@ -76,18 +76,66 @@ jobs:
|
||||
|
||||
OUTPUT="${APP_NAME}"
|
||||
if [ -n "${{ matrix.arm_version }}" ]; then
|
||||
OUTPUT="${OUTPUT}v${{ matrix.arm_version }}"
|
||||
export GOARM=${{ matrix.arm_version }}
|
||||
fi
|
||||
OUTPUT="${OUTPUT}${{ matrix.ext }}"
|
||||
|
||||
OUTPUT="${OUTPUT}"
|
||||
echo "Building $OUTPUT"
|
||||
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT"
|
||||
shell: bash
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
- name: Create Debian Package
|
||||
if: matrix.os == 'linux'
|
||||
run: |
|
||||
# 1. Setup Variables
|
||||
VERSION=${GITHUB_REF_NAME#v} # Extracts 1.0.0 from v1.0.0
|
||||
ARCH=${{ matrix.arch }}
|
||||
if [ "$ARCH" == "arm" ]; then ARCH="armhf"; fi
|
||||
|
||||
PKG_NAME="slideshowapp"
|
||||
BUILD_DIR="${PKG_NAME}_${VERSION}_${ARCH}"
|
||||
|
||||
# 2. Create Directory Structure
|
||||
mkdir -p $BUILD_DIR/usr/bin
|
||||
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME
|
||||
mkdir -p $BUILD_DIR/DEBIAN
|
||||
|
||||
# 3. Copy Files
|
||||
cp ${APP_NAME} $BUILD_DIR/usr/bin/$PKG_NAME
|
||||
cp -r ./web $BUILD_DIR/usr/share/$PKG_NAME/
|
||||
chmod +x $BUILD_DIR/usr/bin/$PKG_NAME
|
||||
|
||||
# 4. Create Control File
|
||||
cat <<EOF > $BUILD_DIR/DEBIAN/control
|
||||
Package: $PKG_NAME
|
||||
Version: $VERSION
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Architecture: $ARCH
|
||||
Maintainer: Your Name <you@example.com>
|
||||
Description: Slideshow Application
|
||||
EOF
|
||||
|
||||
# 5. Build .deb
|
||||
dpkg-deb --build $BUILD_DIR
|
||||
shell: bash
|
||||
|
||||
# Upload for Windows (Binary + Web folder)
|
||||
- name: Upload Windows Artifact
|
||||
if: matrix.os == 'windows'
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
|
||||
name: ${{ env.APP_NAME }}-windows
|
||||
path: |
|
||||
./web
|
||||
${APP_NAME}${{ matrix.ext }}
|
||||
${{ env.APP_NAME }}.exe
|
||||
./web
|
||||
|
||||
# Upload for Linux (Binary + .deb)
|
||||
- name: Upload Linux Artifact
|
||||
if: matrix.os == 'linux'
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ env.APP_NAME }}-linux-${{ matrix.arch }}
|
||||
path: |
|
||||
${{ env.APP_NAME }}
|
||||
*.deb
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
images/
|
||||
slideshowApp
|
||||
schedule.json
|
||||
4
env/enviroment.go
vendored
4
env/enviroment.go
vendored
@@ -28,6 +28,10 @@ func (key EnvKey) GetValue() string {
|
||||
return os.Getenv(string(key))
|
||||
}
|
||||
|
||||
func (key EnvKey) SetValue(value string) {
|
||||
os.Setenv(string(key), value)
|
||||
}
|
||||
|
||||
func (key EnvKey) GetBoolValue() bool {
|
||||
value := strings.ToLower(os.Getenv(string(key)))
|
||||
return value == "true" || value == "1"
|
||||
|
||||
@@ -5,32 +5,34 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"slideshowApp/env"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Helper to get the local network IP address
|
||||
func getLocalIP() string {
|
||||
func GetLocalIP() string {
|
||||
if env.Host.GetValue() != "0.0.0.0" && env.Host.GetValue() != "localhost" {
|
||||
return env.Host.GetValue()
|
||||
}
|
||||
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return "localhost"
|
||||
}
|
||||
for _, address := range addrs {
|
||||
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
if env.Env.GetValue() == "development" && !strings.Contains(ipnet.IP.String(), "192.168") {
|
||||
continue
|
||||
}
|
||||
return ipnet.IP.String()
|
||||
}
|
||||
}
|
||||
if ip := getActiveIP(); ip != "" {
|
||||
return ip
|
||||
}
|
||||
return "localhost"
|
||||
}
|
||||
|
||||
func getActiveIP() string {
|
||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
addr := conn.LocalAddr()
|
||||
if udpAddr, ok := addr.(*net.UDPAddr); ok {
|
||||
return udpAddr.IP.String()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func InfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
port := env.Port.GetValue()
|
||||
if port == "" {
|
||||
@@ -43,7 +45,7 @@ func InfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
data := map[string]string{
|
||||
"ip": getLocalIP(),
|
||||
"ip": GetLocalIP(),
|
||||
"port": port,
|
||||
"speed": speed,
|
||||
}
|
||||
|
||||
13
main.go
13
main.go
@@ -7,6 +7,8 @@ import (
|
||||
"os"
|
||||
"slideshowApp/env"
|
||||
"slideshowApp/handlers"
|
||||
"slideshowApp/utils"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
@@ -23,11 +25,14 @@ func main() {
|
||||
|
||||
if _, err := os.Stat(uploadFolder); err != nil {
|
||||
fmt.Println("upload folder for images not found: ", uploadFolder)
|
||||
fmt.Println("use fallback")
|
||||
fmt.Println("use fallback folder")
|
||||
uploadFolder = "./images"
|
||||
env.PhotoDir.SetValue(uploadFolder)
|
||||
|
||||
}
|
||||
|
||||
fmt.Println("upload folder for images: ", uploadFolder)
|
||||
|
||||
r.PathPrefix("/uploads/").Handler(http.StripPrefix("/uploads/", http.FileServer(http.Dir(uploadFolder))))
|
||||
r.HandleFunc("/api/images", handlers.ListFilesHandler).Methods("GET")
|
||||
r.HandleFunc("/ws", handlers.Websocket)
|
||||
@@ -54,6 +59,12 @@ func main() {
|
||||
host := env.Host.GetValue()
|
||||
port := env.Port.GetValue()
|
||||
url := fmt.Sprintf("%s:%s", host, port)
|
||||
go func() {
|
||||
time.Sleep(3 * time.Second)
|
||||
if err := utils.OpenBrowser(fmt.Sprintf("%s:%s/slideshow", handlers.GetLocalIP(), port)); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
fmt.Println("Server running at", url)
|
||||
log.Fatal(http.ListenAndServe(url, r))
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"Friday_active":false,"Friday_end":"07:38","Friday_start":"07:00","Monday_active":false,"Monday_end":"22:00","Monday_start":"08:00","Saturday_active":false,"Saturday_end":"22:00","Saturday_start":"08:00","Sunday_active":false,"Sunday_end":"22:00","Sunday_start":"08:00","Thursday_active":false,"Thursday_end":"22:00","Thursday_start":"08:00","Tuesday_active":false,"Tuesday_end":"22:00","Tuesday_start":"08:00","Wednesday_active":false,"Wednesday_end":"22:00","Wednesday_start":"08:00"}
|
||||
81
utils/utils.go
Normal file
81
utils/utils.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func OpenBrowser(url string) error {
|
||||
var commands [][]string
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
commands = [][]string{
|
||||
// Chrome (most common)
|
||||
{`C:\Program Files\Google\Chrome\Application\chrome.exe`, "--kiosk", url},
|
||||
{`C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`, "--kiosk", url},
|
||||
|
||||
// Edge (default on modern Windows)
|
||||
{`C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`, "--kiosk", url},
|
||||
{`C:\Program Files\Microsoft\Edge\Application\msedge.exe`, "--kiosk", url},
|
||||
|
||||
// Firefox (no true kiosk, but fullscreen)
|
||||
{`C:\Program Files\Mozilla Firefox\firefox.exe`, "--kiosk", url},
|
||||
{`C:\Program Files (x86)\Mozilla Firefox\firefox.exe`, "--kiosk", url},
|
||||
|
||||
// System default browser (always works)
|
||||
{"rundll32", "url.dll,FileProtocolHandler", url},
|
||||
}
|
||||
|
||||
case "darwin":
|
||||
commands = [][]string{
|
||||
// Chrome
|
||||
{"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--kiosk", url},
|
||||
|
||||
// Edge
|
||||
{"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge", "--kiosk", url},
|
||||
|
||||
// Firefox
|
||||
{"/Applications/Firefox.app/Contents/MacOS/firefox", "--kiosk", url},
|
||||
|
||||
// Safari (no kiosk flag, opens normally)
|
||||
{"open", "-a", "Safari", url},
|
||||
|
||||
// System default browser
|
||||
{"open", url},
|
||||
}
|
||||
|
||||
default: // Linux
|
||||
if os.Getenv("DISPLAY") == "" &&
|
||||
os.Getenv("WAYLAND_DISPLAY") == "" &&
|
||||
os.Getenv("XDG_SESSION_TYPE") != "wayland" {
|
||||
return fmt.Errorf("os is running in headless mode; do not start browser")
|
||||
}
|
||||
|
||||
commands = [][]string{
|
||||
// Chromium / Chrome
|
||||
{"chromium-browser", "--kiosk", url},
|
||||
{"chromium", "--kiosk", url},
|
||||
{"google-chrome", "--kiosk", url},
|
||||
|
||||
// Firefox
|
||||
{"firefox", "--kiosk", url},
|
||||
|
||||
// System default browser (best universal fallback)
|
||||
{"xdg-open", url},
|
||||
}
|
||||
}
|
||||
|
||||
for _, cmd := range commands {
|
||||
execCmd := exec.Command(cmd[0], cmd[1:]...)
|
||||
if err := execCmd.Start(); err == nil {
|
||||
return nil
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("could not open browser")
|
||||
}
|
||||
Reference in New Issue
Block a user