Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions fontscan/fontmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package fontscan
import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"sync"

"github.com/go-text/typesetting/font"
Expand Down Expand Up @@ -165,17 +163,7 @@ func cacheDir(userProvided string) (string, error) {
return userProvided, nil
}
// load an existing index
if runtime.GOOS == "android" {
// There is no stable way to infer the proper place to store the cache
// with access to the Java runtime for the application. Rather than
// clutter our API with that, require the caller to provide a path.
return "", fmt.Errorf("user must provide cache directory on android")
}
configDir, err := os.UserCacheDir()
if err != nil {
return "", fmt.Errorf("resolving index cache path: %s", err)
}
return configDir, nil
return platformCacheDir()
}

// initSystemFonts scan the system fonts and update `SystemFonts`.
Expand Down
10 changes: 10 additions & 0 deletions fontscan/fontmap_cache_android.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build android
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this comment as the file name already includes _android suffix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true it is not needed... just a habit of mine sorry


package fontscan

func platformCacheDir() (string, error) {
// There is no stable way to infer the proper place to store the cache
// with access to the Java runtime for the application. Rather than
// clutter our API with that, require the caller to provide a path.
return "", fmt.Errorf("user must provide cache directory on android")
}
16 changes: 16 additions & 0 deletions fontscan/fontmap_cache_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !android && !tinygo

package fontscan

import (
"fmt"
"os"
)

func platformCacheDir() (string, error) {
configDir, err := os.UserCacheDir()
if err != nil {
return "", fmt.Errorf("resolving index cache path: %s", err)
}
return configDir, nil
}
18 changes: 18 additions & 0 deletions fontscan/fontmap_cache_tinygo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build tinygo

package fontscan

import (
"fmt"
"os"
"path/filepath"
)

func platformCacheDir() (string, error) {
// if no path is provided we cannot get cache dir with tinygo, so just make one up.
homeDir, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("resolving index cache path: %s", err)
}
return filepath.Join(homeDir, ".cache"), nil
}