Files
gio/app/datadir_android.go
T
Elias Naur 2395659be3 app: [Android] set XDG_CACHE_HOME to make os.UserCacheDir work
os.UserCacheDir can't work on Android because it doesn't have
access to the Java app context. Gio programs do have access, so set
up UserCacheDir's fallback, the XDG_CACHE_HOME environment variable.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-06 16:39:21 +02:00

31 lines
481 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
// +build android
package app
import "C"
import (
"os"
"path/filepath"
"sync"
"gioui.org/app/internal/window"
)
var (
dataDirOnce sync.Once
dataPath string
)
func dataDir() (string, error) {
dataDirOnce.Do(func() {
dataPath = window.GetDataDir()
// Set XDG_CACHE_HOME to make os.UserCacheDir work.
cachePath := filepath.Join(dataPath, "cache")
os.Setenv("XDG_CACHE_HOME", cachePath)
})
return dataPath, nil
}