fix(fonts): register user fonts correctly on Windows

Previously on Windows, fonts installed with `oh-my-posh font install --user` would not show up in the Control Panel nor as an option in program font menus.

Now, fonts are correctly registered.
This commit is contained in:
Dan Rose 2023-08-18 12:52:50 -05:00 committed by Jan De Dobbeleer
parent 2d2af929a9
commit a711f9b7f7

View file

@ -42,9 +42,11 @@ func install(font *Font, admin bool) error {
}
// Add registry entry
reg := registry.LOCAL_MACHINE
var reg = registry.LOCAL_MACHINE
var regValue = font.FileName
if !admin {
reg = registry.CURRENT_USER
regValue = fullPath
}
k, err := registry.OpenKey(reg, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts`, registry.WRITE)
@ -59,7 +61,7 @@ func install(font *Font, admin bool) error {
defer k.Close()
name := fmt.Sprintf("%v (TrueType)", font.Name)
if err = k.SetStringValue(name, font.FileName); err != nil {
if err = k.SetStringValue(name, regValue); err != nil {
// If this fails, remove the font file as well.
if nexterr := os.Remove(fullPath); nexterr != nil {
return errors.New("Unable to delete font file after registry key set error")