passgo/cmd/passgo-gui/impl_darwin.go

62 lines
1.2 KiB
Go

//+build darwin
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 {
log(Info, "Cannot open system font.")
return err
}
collection, err := sfnt.ParseCollectionReaderAt(f)
if err != nil {
log(Info, "Cannot parse system font.")
return err
}
regular, err = collection.Font(0)
if err != nil {
log(Info, "Cannot access first font in collection.")
return err
}
return nil
}
func init() {
err := setFont()
if err != nil {
regular, err = sfnt.Parse(goregular.TTF)
if err != nil {
log(Fatal, "Cannot parse default font: ", err)
}
}
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 {
log(Info, "Cannot create configuration directory ", confDir)
log(Fatal, err)
} else {
log(Info, "Configuration directory created")
}
}
}