Files
memberApp/backend/utils/utils.go
Adrian Zürcher 690b7f4034
All checks were successful
Build Quasar SPA and Go Backend for memberApp / build-spa (push) Successful in 2m12s
Build Quasar SPA and Go Backend for memberApp / build-backend (amd64, , linux) (push) Successful in 5m8s
Build Quasar SPA and Go Backend for memberApp / build-backend (amd64, .exe, windows) (push) Successful in 5m8s
Build Quasar SPA and Go Backend for memberApp / build-backend (arm, 6, , linux) (push) Successful in 4m57s
Build Quasar SPA and Go Backend for memberApp / build-backend (arm64, , linux) (push) Successful in 5m7s
add new user and role table in app (in progress)
2025-10-14 16:41:20 +02:00

72 lines
1.7 KiB
Go

package utils
import (
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
"regexp"
"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
}
func IsValidEmail(email string) bool {
re := regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)
return re.MatchString(email)
}