2019-09-06 11:43:14 -04:00
|
|
|
//+build darwin
|
2019-09-06 10:45:18 -04:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/user"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"golang.org/x/image/font/gofont/goregular"
|
|
|
|
"golang.org/x/image/font/sfnt"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
regular *sfnt.Font
|
|
|
|
confDir string
|
|
|
|
)
|
|
|
|
|
|
|
|
func setFont() error {
|
|
|
|
f, err := os.Open("/System/Library/Fonts/AppleSDGothicNeo.ttc")
|
|
|
|
if err != nil {
|
2019-09-06 10:46:23 -04:00
|
|
|
log(Info, "Cannot open system font.")
|
2019-09-06 10:45:18 -04:00
|
|
|
return err
|
2019-09-06 10:46:23 -04:00
|
|
|
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
|
|
|
collection, err := sfnt.ParseCollectionReaderAt(f)
|
|
|
|
if err != nil {
|
2019-09-06 10:46:23 -04:00
|
|
|
log(Info, "Cannot parse system font.")
|
2019-09-06 10:45:18 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
regular, err = collection.Font(0)
|
|
|
|
if err != nil {
|
2019-09-06 10:46:23 -04:00
|
|
|
log(Info, "Cannot access first font in collection.")
|
2019-09-06 10:45:18 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
err := setFont()
|
|
|
|
if err != nil {
|
|
|
|
regular, err = sfnt.Parse(goregular.TTF)
|
|
|
|
if err != nil {
|
2019-09-06 10:46:23 -04:00
|
|
|
log(Fatal, "Cannot parse default font: ", err)
|
2019-09-06 10:45:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
usr, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
log(Fatal, "Cannot get current user: ", err)
|
|
|
|
}
|
|
|
|
confDir = path.Join(usr.HomeDir, ".config/passgo")
|
|
|
|
if _, err := os.Stat(confDir); os.IsNotExist(err) {
|
|
|
|
err = os.MkdirAll(confDir, 0700)
|
|
|
|
if err != nil {
|
2019-09-06 10:46:23 -04:00
|
|
|
log(Info, "Cannot create configuration directory ", confDir)
|
2019-09-06 10:45:18 -04:00
|
|
|
log(Fatal, err)
|
|
|
|
} else {
|
|
|
|
log(Info, "Configuration directory created")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|