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>
This commit is contained in:
Elias Naur
2020-05-06 16:36:34 +02:00
parent e97adeedd9
commit 2395659be3
+5
View File
@@ -7,6 +7,8 @@ package app
import "C"
import (
"os"
"path/filepath"
"sync"
"gioui.org/app/internal/window"
@@ -20,6 +22,9 @@ var (
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
}