webinstall / webi-installers

Primary and community-submitted packages for webinstall.dev
https://webinstall.dev
Mozilla Public License 2.0
1.97k stars 210 forks source link

[Windows] NerdFont: install requires manual button click #228

Closed veritem closed 3 years ago

veritem commented 3 years ago

When I install nerd font on my windows machine it works but, when I try to restart the computer the font fails, I'm not sure what's the cause for this but this is serious issue with this installer.

veritem commented 3 years ago

The font fails booth on windows and wsl at the same time so fix it every time i boot up my laptop i run curl.exe -A "MS" https://webinstall.dev/nerdfont | powershell in powershell

coolaj86 commented 3 years ago

As a workaround see if you can manually right-click install or open and install the font:

It should be in

%UserProfile%\AppData\Local\Microsoft\Windows\Fonts

And installing it manually should add it to

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Fonts

Do you happen to be on a roaming profile or something else that might cause local machine settings to get reset at every login?

veritem commented 3 years ago

I fixed it by executing the installation of fonts in %UserProfile%\AppData\Local\Microsoft\Windows\Fonts Thanks for the quick response

coolaj86 commented 3 years ago

cc/ @jkunkee Could you lend your expertise?

This only loads a font for the current session: https://github.com/webinstall/webi-installers/blob/master/nerdfont/install.ps1

I also found a script that supposedly works for system-level fonts, but my attempts and adapting it to use HKCU instead of HKLM have floundered. https://github.com/PPOSHGROUP/PPoShTools/blob/master/PPoShTools/Public/FileSystem/Add-Font.ps1

coolaj86 commented 3 years ago

As a temporary workaround while waiting on more info from Kunkee, this now pops up the font installer dialog.

coolaj86 commented 3 years ago

Closing now that there's a workaround in place, but still hoping to hear back from @jkunkee.

jkunkee commented 3 years ago

TL;DR: I think p/invoke from PowerShell of AddFontResource (p/invoke page for AddFontResourceEx) combined with another p/invoke of SendMessage(HWND_BROADCAST,WM_FONTCHANGE, 0, 0); will get you the most reliable results.

Copying to %WINDIR%\Fonts and rebooting always works, but...requires a reboot.

The relevant system docs are here. There's a brief explanation in there about the various reboot and session visibility questions which boil down to 'don't land in a temporary cache, and the globallest of global caches is only rebuilt on reboot but don't worry about that last bit unless you have multiple concurrent users, as with Terminal Server. Oh, and uninstalling requires hunting down all open handles first--so just reboot.'

Reusing the shell components is a curious option--effectively mimicking right-click-install--but I consider that more complex and gnarly and I'm not seeing a useful tutorial for it.

I expect the reason HKCU is hard to sub in for HKLM is that HKLM is the system-wide settings location and HKCU is the per-user settings location. The structures are often divergent between them, though I don't know the font side of things well.

Happy to elaborate if I can, but there's a whole world down this here little rabbit hole.