first commit

This commit is contained in:
Adrian Zürcher
2025-10-12 14:56:18 +02:00
parent a9f2e11fe6
commit a908db4f38
92 changed files with 13273 additions and 0 deletions

65
backend/utils/utils.go Normal file
View File

@@ -0,0 +1,65 @@
package utils
import (
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
"runtime"
"gitea.tecamino.com/paadi/tecamino-logger/logging"
)
func OpenBrowser(url string, logger *logging.Logger) error {
var commands [][]string
switch runtime.GOOS {
case "windows":
// Try with Chrome in kiosk mode
commands = [][]string{
{`C:\Program Files\Google\Chrome\Application\chrome.exe`, "--kiosk", url},
{"rundll32", "url.dll,FileProtocolHandler", url}, // fallback
}
case "darwin":
// macOS: open with Chrome in kiosk
commands = [][]string{
{"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--kiosk", url},
{"open", url}, // fallback
}
default: // Linux
if os.Getenv("DISPLAY") == "" && os.Getenv("WAYLAND_DISPLAY") == "" && os.Getenv("XDG_SESSION_TYPE") != "wayland" {
return fmt.Errorf("os is running i headless mode do not start browser")
}
commands = [][]string{
{"chromium-browser", "--kiosk", url},
{"google-chrome", "--kiosk", url},
{"firefox", "--kiosk", url},
{"xdg-open", url}, // fallback
}
}
for _, cmd := range commands {
execCmd := exec.Command(cmd[0], cmd[1:]...)
if err := execCmd.Start(); err == nil {
return nil
} else {
logger.Error("utils.OpenBrowser", err)
}
}
return fmt.Errorf("could not open browser")
}
func FindAllFiles(rootDir, fileExtention string) (files []string, err error) {
err = filepath.WalkDir(rootDir, func(path string, d fs.DirEntry, err error) error {
if d.IsDir() {
return nil
} else if filepath.Ext(d.Name()) == fileExtention {
files = append(files, path)
}
return err
})
return
}