matthewjberger / scoop-nerd-fonts

A scoop bucket for installing nerd fonts
The Unlicense
364 stars 34 forks source link

Font installation for non-admin users #10

Closed chawyehsu closed 2 years ago

chawyehsu commented 5 years ago

From Windows 10 17704 onward, Users have the ability to install fonts without admin rights.

As reference: https://blogs.windows.com/windowsexperience/2018/06/27/announcing-windows-10-insider-preview-build-17704/

linyinfeng commented 5 years ago

Updated again... I retest the installer and uninstaller following on 1903 and find it is not working now. Last time I use these script is several months ago because my switching to other system(now I am back on win). Some Windows mechanism may be changed and it is no longer working. I am sorry for this wrong script. The work can be done by replacing installer and uninstaller like this:

"installer": {
    "script": [
        "New-Item -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\Scoop.%name' -Force | Out-Null",
        "Get-ChildItem `$dir -filter '*Windows Compatible.*' | ForEach-Object {",
        "    New-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\Scoop.%name' -Name `$_.Name -Value `$_.FullName -Force | Out-Null",
        "}"
    ]
},
"uninstaller": {
    "script": [
        "Remove-Item -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\Scoop.%name'",
        "Write-Host \"The '`$(`$app.Replace('-NF', ''))' Font family has been uninstalled and will not be present after restarting your computer.\" -Foreground Magenta"
    ]
}

Changes made to registry will looks like this: 2019-05-21 Also, changes to fonts can be immediately viewed in Settings - Personalization - Fonts.

A problem is, the Windows Font Cache Service(FontCache) does not automatically detect changes of this registry key and the service does not update font cache at boot time by default to reduce boot time of Windows. A restart of FontCache service can fix missing of installed fonts, but this requires admin rights and a restart may not be a reliable way to accomplish this task. I don't find approaches to build font cache for newly added fonts without admin rights. This might cause problem.

My fork of the repository for my personal use installs fonts without admin rights: linyinfeng/scoop-nerd-fonts. I am not actively maintaining the fork and it may be buggy. But it can serves as a simple working example for the issue.

chawyehsu commented 5 years ago

@linyinfeng Thanks for your information, this is really helpful! @matthewjberger Would you like to adopt this to support non-admin installation? Maybe we should add conditions to check if the user's machine is under Windows 10 17704 or later, for backward compatibility.

linyinfeng commented 5 years ago

@h404bi I don't known whether or not fonts installed by the new method can be used by any application. In my test some application can not use these fonts. I believe that compatibility of the new installation method needs more inspection. Maybe both installation methods should be kept.

linyinfeng commented 5 years ago

Tried to copy fonts to AppData\Local\Microsoft\Windows\Fonts and modified registry keys. Installed fonts in this directory seem work well. Font files not in the directory seems take effect when fonts cache was rebuilt and disappear after system reboot. So maybe we can't just leave font files in the app directory of scoop and only create registry keys for them like the script described above in my comment, which I thought is a nice and clean way.

Update: I ignored permission problem. Fonts can not be accessed by service like FontCache because some services have no read permission to scoop apps directory. By properly set read rights for them in ACL, we can install fonts just in the default location of scoop. A problem is to find out what ACL rules should be added to which files or directories to make font cache services and all applications including Font settings work.