Null-DRM-Official/apps/pkg/modhost/root.go
404errordeveloper f9c28be3f1
All checks were successful
release / build-and-upload (push) Successful in 6m8s
modules-release / build-and-upload (push) Successful in 4m47s
v0.1.1: external modules, publish YAML, proxy reset, binary-first README
- Host discovers/builds modules under modules/ (bbc, rte, tg4)
- module-publish.yaml tracked; local module.yaml gitignored
- drm --modules-dir / DRM_MODULES_DIR
- drm proxy reset; Magisk reinject reliability
- modules-v* Forgejo release workflow + build scripts
- BBC full Explore channel map including S4C
- README quickstart based on release binaries
2026-10-08 23:16:14 +02:00

62 lines
1.3 KiB
Go

package modhost
import (
"os"
"path/filepath"
"sync"
"drmdecryption/repo"
)
var (
rootMu sync.RWMutex
modulesDirOV string // absolute path override for the modules directory
)
// SetModulesDir overrides where providers are discovered (drm --modules-dir).
// Empty clears the override. Relative paths are resolved against the process cwd.
func SetModulesDir(dir string) error {
rootMu.Lock()
defer rootMu.Unlock()
if dir == "" {
modulesDirOV = ""
return nil
}
abs, err := filepath.Abs(dir)
if err != nil {
return err
}
modulesDirOV = abs
return nil
}
// ModulesDirOverride returns the --modules-dir override, or "".
func ModulesDirOverride() string {
rootMu.RLock()
defer rootMu.RUnlock()
return modulesDirOV
}
// EffectiveModulesDir is the directory that Discover/Open scan.
// Prefer --modules-dir / DRM_MODULES_DIR; else <root>/modules.
func EffectiveModulesDir(root string) string {
if ov := ModulesDirOverride(); ov != "" {
return ov
}
if root == "" {
root = repo.Root()
}
return filepath.Join(root, "modules")
}
// ApplyEnvModulesDir sets the override from DRM_MODULES_DIR when no flag was set.
func ApplyEnvModulesDir() error {
if ModulesDirOverride() != "" {
return nil
}
v := os.Getenv("DRM_MODULES_DIR")
if v == "" {
return nil
}
return SetModulesDir(v)
}