10 Commits

Author SHA1 Message Date
Adrian Zürcher
3241429e98 add logger
All checks were successful
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 2m7s
Build Slideshow App / build (amd64, , linux) (push) Successful in 2m25s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 2m2s
Build Slideshow App / build (arm64, , linux) (push) Successful in 2m1s
2026-01-18 21:00:53 +01:00
Adrian Zürcher
8165b2d843 fix workflow take 3
All checks were successful
Build Slideshow App / build (amd64, , linux) (push) Successful in 1m24s
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 1m20s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 1m23s
Build Slideshow App / build (arm64, , linux) (push) Successful in 1m26s
2026-01-18 17:06:59 +01:00
Adrian Zürcher
e480141e89 fix workflow take 2 only linux
All checks were successful
Build Slideshow App / build (arm64, , linux) (push) Successful in 1m23s
2026-01-18 17:04:52 +01:00
Adrian Zürcher
e1ae34a336 update workflow
Some checks failed
Build Slideshow App / build (amd64, , linux) (push) Has been cancelled
Build Slideshow App / build (amd64, .exe, windows) (push) Has been cancelled
Build Slideshow App / build (arm, 7, , linux) (push) Has been cancelled
Build Slideshow App / build (arm64, , linux) (push) Has been cancelled
2026-01-18 15:27:39 +01:00
Adrian Zürcher
3aac950b9c add new debian install workflow for linux
All checks were successful
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 1m49s
Build Slideshow App / build (amd64, , linux) (push) Successful in 2m8s
Build Slideshow App / build (arm, 7, , linux) (push) Successful in 1m53s
Build Slideshow App / build (arm64, , linux) (push) Successful in 1m51s
2026-01-17 22:42:16 +01:00
Adrian Zürcher
96bfcb7d0e add new set function 2026-01-17 22:41:54 +01:00
Adrian Zürcher
64744e218a add feature check if ip is active 2026-01-17 22:41:42 +01:00
Adrian Zürcher
7d3db6b485 remove schedule.json file 2026-01-17 22:41:21 +01:00
Adrian Zürcher
9cde384a36 add browser open function 2026-01-17 22:39:50 +01:00
f9a92e4e4a Fix appname artifact
All checks were successful
Build Slideshow App / build (amd64, .exe, windows) (push) Successful in 1m56s
Build Slideshow App / build (amd64, , linux) (push) Successful in 2m2s
Build Slideshow App / build (arm, 6, , linux) (push) Successful in 1m42s
Build Slideshow App / build (arm64, , linux) (push) Successful in 1m48s
2026-01-17 18:12:49 +01:00
10 changed files with 274 additions and 29 deletions

3
.env
View File

@@ -1,5 +1,6 @@
ENV= #empty|development ENV= #empty|development|debug
PHOTO_DIR=images PHOTO_DIR=images
HOST=0.0.0.0 HOST=0.0.0.0
PORT=8080 PORT=8080
INTERVAL_DEFAULT=10 INTERVAL_DEFAULT=10
LOG_PATH= #path for logger files default .

View File

@@ -26,7 +26,7 @@ jobs:
ext: "" ext: ""
- os: linux - os: linux
arch: arm arch: arm
arm_version: 6 arm_version: 7
ext: "" ext: ""
steps: steps:
@@ -76,18 +76,114 @@ jobs:
OUTPUT="${APP_NAME}" OUTPUT="${APP_NAME}"
if [ -n "${{ matrix.arm_version }}" ]; then if [ -n "${{ matrix.arm_version }}" ]; then
OUTPUT="${OUTPUT}v${{ matrix.arm_version }}"
export GOARM=${{ matrix.arm_version }} export GOARM=${{ matrix.arm_version }}
fi fi
OUTPUT="${OUTPUT}${{ matrix.ext }}" OUTPUT="${OUTPUT}${{ matrix.ext }}"
echo "Building $OUTPUT" echo "Building $OUTPUT"
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT" GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT"
shell: bash shell: bash
- name: Upload artifact - 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/etc/systemd/system
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. Handle .env (Copy as a .template so it doesn't overwrite existing ones)
if [ -f ".env" ]; then
cp .env $BUILD_DIR/usr/share/$PKG_NAME/.env.template
else
echo "PORT=8080" > $BUILD_DIR/usr/share/$PKG_NAME/.env.template
fi
# 5. Create the systemd Service File
cat <<EOF > $BUILD_DIR/etc/systemd/system/$PKG_NAME.service
[Unit]
Description=Slideshow Application Service
After=graphical.target
[Service]
Type=simple
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/youruser/.Xauthority
ExecStart=/usr/bin/$PKG_NAME
WorkingDirectory=/usr/share/$PKG_NAME
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
# 6. 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
# 7. Optional: Add post-install script to enable service automatically
echo "create service"
cat <<EOF > $BUILD_DIR/DEBIAN/postinst
#!/bin/sh
# Check if .env exists in the target share folder
if [ ! -f "/usr/share/$PKG_NAME/.env" ]; then
echo "Creating new .env from template..."
cp /usr/share/$PKG_NAME/.env.template /usr/share/$PKG_NAME/.env
else
echo ".env already exists, skipping template copy to preserve settings."
fi
echo "reload"
systemctl daemon-reload
echo "enable service"
systemctl enable $PKG_NAME.service
echo "start service"
systemctl start $PKG_NAME.service
EOF
chmod 555 $BUILD_DIR/DEBIAN/postinst
# 8. 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 uses: actions/upload-artifact@v3
with: with:
name: ${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }} name: ${{ env.APP_NAME }}-windows
path: | path: |
${{ env.APP_NAME }}.exe
./web ./web
${APP_NAME}${{ matrix.ext }}
# 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
View File

@@ -1,2 +1,3 @@
images/ images/
slideshowApp slideshowApp
schedule.json

5
env/enviroment.go vendored
View File

@@ -13,6 +13,7 @@ const (
Host EnvKey = "HOST" Host EnvKey = "HOST"
Port EnvKey = "PORT" Port EnvKey = "PORT"
IntervalDefault EnvKey = "INTERVAL_DEFAULT" IntervalDefault EnvKey = "INTERVAL_DEFAULT"
LogPath EnvKey = "LOG_PATH"
) )
type EnvKey string type EnvKey string
@@ -28,6 +29,10 @@ func (key EnvKey) GetValue() string {
return os.Getenv(string(key)) return os.Getenv(string(key))
} }
func (key EnvKey) SetValue(value string) {
os.Setenv(string(key), value)
}
func (key EnvKey) GetBoolValue() bool { func (key EnvKey) GetBoolValue() bool {
value := strings.ToLower(os.Getenv(string(key))) value := strings.ToLower(os.Getenv(string(key)))
return value == "true" || value == "1" return value == "true" || value == "1"

7
go.mod
View File

@@ -3,7 +3,14 @@ module slideshowApp
go 1.25.4 go 1.25.4
require ( require (
gitea.tecamino.com/paadi/tecamino-logger v1.0.0
github.com/gorilla/mux v1.8.1 github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3 github.com/gorilla/websocket v1.5.3
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
) )
require (
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)

18
go.sum
View File

@@ -1,6 +1,24 @@
gitea.tecamino.com/paadi/tecamino-logger v1.0.0 h1:Quk0UJerOCy7xbHWYOuBXk0FQIgx4arjVDMt2ahvaO0=
gitea.tecamino.com/paadi/tecamino-logger v1.0.0/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -5,30 +5,32 @@ import (
"net" "net"
"net/http" "net/http"
"slideshowApp/env" "slideshowApp/env"
"strings"
) )
// Helper to get the local network IP address // 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" { if env.Host.GetValue() != "0.0.0.0" && env.Host.GetValue() != "localhost" {
return env.Host.GetValue() return env.Host.GetValue()
} }
addrs, err := net.InterfaceAddrs() if ip := getActiveIP(); ip != "" {
return ip
}
return "localhost"
}
func getActiveIP() string {
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil { if err != nil {
return "localhost" return ""
} }
for _, address := range addrs { defer conn.Close()
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil { addr := conn.LocalAddr()
if env.Env.GetValue() == "development" && !strings.Contains(ipnet.IP.String(), "192.168") { if udpAddr, ok := addr.(*net.UDPAddr); ok {
continue return udpAddr.IP.String()
} }
return ipnet.IP.String() return ""
}
}
}
return "localhost"
} }
func InfoHandler(w http.ResponseWriter, r *http.Request) { func InfoHandler(w http.ResponseWriter, r *http.Request) {
@@ -43,7 +45,7 @@ func InfoHandler(w http.ResponseWriter, r *http.Request) {
} }
data := map[string]string{ data := map[string]string{
"ip": getLocalIP(), "ip": GetLocalIP(),
"port": port, "port": port,
"speed": speed, "speed": speed,
} }

32
main.go
View File

@@ -7,7 +7,10 @@ import (
"os" "os"
"slideshowApp/env" "slideshowApp/env"
"slideshowApp/handlers" "slideshowApp/handlers"
"slideshowApp/utils"
"time"
"gitea.tecamino.com/paadi/tecamino-logger/logging"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@@ -15,19 +18,34 @@ var staticFolder = "./web/static/"
func main() { func main() {
logConfig := logging.DefaultConfig()
logConfig.Debug = env.Env.GetValue() == "debug"
logger, err := logging.NewLogger(env.LogPath.GetValue(), logConfig)
if err != nil {
log.Fatal(err)
}
logger.Debug("main", "load enviroment variable")
env.Load(".env") env.Load(".env")
r := mux.NewRouter() r := mux.NewRouter()
uploadFolder := env.PhotoDir.GetValue() uploadFolder := env.PhotoDir.GetValue()
logger.Debug("main", "uploadfolder: "+uploadFolder)
if _, err := os.Stat(uploadFolder); err != nil { if _, err := os.Stat(uploadFolder); err != nil {
fmt.Println("upload folder for images not found: ", uploadFolder) fmt.Println("upload folder for images not found: ", uploadFolder)
fmt.Println("use fallback") logger.Error("main", "upload folder for images not found: "+uploadFolder)
fmt.Println("use fallback folder")
uploadFolder = "./images" uploadFolder = "./images"
logger.Info("main", "use fallback uploadfolder: "+uploadFolder)
env.PhotoDir.SetValue(uploadFolder)
} }
fmt.Println("upload folder for images: ", uploadFolder) fmt.Println("upload folder for images: ", uploadFolder)
r.PathPrefix("/uploads/").Handler(http.StripPrefix("/uploads/", http.FileServer(http.Dir(uploadFolder)))) r.PathPrefix("/uploads/").Handler(http.StripPrefix("/uploads/", http.FileServer(http.Dir(uploadFolder))))
r.HandleFunc("/api/images", handlers.ListFilesHandler).Methods("GET") r.HandleFunc("/api/images", handlers.ListFilesHandler).Methods("GET")
r.HandleFunc("/ws", handlers.Websocket) r.HandleFunc("/ws", handlers.Websocket)
@@ -54,6 +72,16 @@ func main() {
host := env.Host.GetValue() host := env.Host.GetValue()
port := env.Port.GetValue() port := env.Port.GetValue()
url := fmt.Sprintf("%s:%s", host, port) url := fmt.Sprintf("%s:%s", host, port)
go func() {
logger.Debug("main", "start go routine with a 3 second wait")
time.Sleep(3 * time.Second)
if err := utils.OpenBrowser(logger, fmt.Sprintf("%s:%s/slideshow", handlers.GetLocalIP(), port)); err != nil {
logger.Error("main", err)
}
}()
fmt.Println("Server running at", url) fmt.Println("Server running at", url)
log.Fatal(http.ListenAndServe(url, r)) logger.Info("main", "Server running at: "+url)
if err := http.ListenAndServe(url, r); err != nil {
logger.Error("main", err)
}
} }

View File

@@ -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"}

88
utils/utils.go Normal file
View File

@@ -0,0 +1,88 @@
package utils
import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"gitea.tecamino.com/paadi/tecamino-logger/logging"
)
func OpenBrowser(logger *logging.Logger, url string) error {
var commands [][]string
switch runtime.GOOS {
case "windows":
logger.Debug("OpenBrowser", "os: 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":
logger.Debug("OpenBrowser", "os: windows")
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
logger.Debug("OpenBrowser", "os: 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 {
logger.Debug("OpenBrowser", "browser started with command: "+strings.Join(cmd, ", "))
return nil
} else {
return err
}
}
return fmt.Errorf("could not open browser")
}