github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/app/datadir_android.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  // +build android
     4  
     5  package app
     6  
     7  import "C"
     8  
     9  import (
    10  	"os"
    11  	"path/filepath"
    12  	"sync"
    13  
    14  	"github.com/cybriq/giocore/app/internal/wm"
    15  )
    16  
    17  var (
    18  	dataDirOnce sync.Once
    19  	dataPath    string
    20  )
    21  
    22  func dataDir() (string, error) {
    23  	dataDirOnce.Do(func() {
    24  		dataPath = wm.GetDataDir()
    25  		// Set XDG_CACHE_HOME to make os.UserCacheDir work.
    26  		if _, exists := os.LookupEnv("XDG_CACHE_HOME"); !exists {
    27  			cachePath := filepath.Join(dataPath, "cache")
    28  			os.Setenv("XDG_CACHE_HOME", cachePath)
    29  		}
    30  		// Set XDG_CONFIG_HOME to make os.UserConfigDir work.
    31  		if _, exists := os.LookupEnv("XDG_CONFIG_HOME"); !exists {
    32  			cfgPath := filepath.Join(dataPath, "config")
    33  			os.Setenv("XDG_CONFIG_HOME", cfgPath)
    34  		}
    35  		// Set HOME to make os.UserHomeDir work.
    36  		if _, exists := os.LookupEnv("HOME"); !exists {
    37  			os.Setenv("HOME", dataPath)
    38  		}
    39  	})
    40  	return dataPath, nil
    41  }