github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/pkg/utils/env.go (about) 1 package utils 2 3 import ( 4 "os" 5 "path/filepath" 6 "runtime" 7 ) 8 9 const ( 10 EnvBackendLaddr = "HYDRAPP_BACKEND_LADDR" 11 EnvFrontendLaddr = "HYDRAPP_FRONTEND_LADDR" 12 EnvBrowser = "HYDRAPP_BROWSER" 13 EnvType = "HYDRAPP_TYPE" 14 EnvSelfupdate = "HYDRAPP_SELFUPDATE" 15 ) 16 17 func PolyfillEnvironment(userHomeDir string) error { 18 switch runtime.GOOS { 19 case "android": 20 if _, exists := os.LookupEnv("XDG_CACHE_HOME"); !exists { 21 if err := os.Setenv("XDG_CACHE_HOME", filepath.Join(userHomeDir, ".cache")); err != nil { 22 return err 23 } 24 } 25 26 if _, exists := os.LookupEnv("XDG_CONFIG_HOME"); !exists { 27 if err := os.Setenv("XDG_CONFIG_HOME", filepath.Join(userHomeDir, ".config")); err != nil { 28 return err 29 } 30 } 31 32 if _, exists := os.LookupEnv("HOME"); !exists { 33 if err := os.Setenv("HOME", userHomeDir); err != nil { 34 return err 35 } 36 } 37 } 38 39 return nil 40 }