2

I am building my first UWP app (so still very newbie).

Detailed Context

I need any website (not just mine) to be able to open my app when the user clicks on a link and open my website when the app is not available. I can't use web-to-app-linking since it would not work on all browsers according to the documentation. So I need to use a custom scheme to open the app (I already have that feature).

Now I need to detect in JS if the app is installed to chose between the http link or the custom scheme link. The solution I found was to install a system-wide font with the application. A JS script can then compare the size of a caracter rendered with 'font-family: monospace;' with the size of the same caracter rendered with 'font-family: customAppFont, monospace;' and conclude about the app presence.

My problem

I don't know how to embed my ttf custom font file in my UWP app so that it is available to all browsers.

What I have tried so far

I have tried to use uap4:SharedFonts App extension following this documentation. I uninstalled the app, built it again, and restarted my computer but my custom font is never made available to browsers (tested with Chrome and Edge).

My package.appxmanifest

<?xml version="1.0" encoding="utf-8"?>

<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
  IgnorableNamespaces="uap mp uap4">

  ...
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
  </Dependencies>

  <Applications>
    <Application ...>
      <Extensions>
        <uap:Extension Category="windows.protocol">
          <uap:Protocol Name="myprotocol" DesiredView="useMinimum">
            <uap:DisplayName>MyApp</uap:DisplayName>
          </uap:Protocol>
        </uap:Extension>
        <uap4:Extension Category="windows.sharedFonts">
          <uap4:SharedFonts>
            <uap4:Font File="Assets\myCustomFont.ttf"/>
          </uap4:SharedFonts>
        </uap4:Extension>
      </Extensions>
    </Application>
  </Applications>
</Package>

and I have added the file Assets\myCustomFont.ttf to the solution with Visual Studio 2019.

What I would like to have

Make my custom font available in all browsers after the app has been installed. I also want the font to be automatically removed when the app is uninstalled.

Bonus : can I prevent the user from manually deleting the font ? (or better totally hide it from him ?)

Goasmad
  • 69
  • 9
  • this link provides some answer: https://brutaldev.com/post/installing-and-removing-fonts-using-C – Goasmad Sep 02 '19 at 16:57
  • The above case link could solve your issue ? – Nico Zhu Sep 03 '19 at 02:32
  • @NicoZhu-MSFT yes partially. It tells me how to install the font, but not how to uninstall it automatically. I will keep looking for a complete answer. – Goasmad Sep 03 '19 at 08:22
  • if your font file stored in the Assets folder, it will delete automatically when the app uninstalled. – Nico Zhu Sep 03 '19 at 08:41
  • @NicoZhu-MSFT ah ! thanks for this input ! I installed the font programmatically as in the second part of the above link, then uninstalled my app. The font remained. So I guess if I want it to be uninstalled automatically, I have to package my app with an installer. Is that correct ? (I haven't tried that yet because I'd like to avoid it if possible). – Goasmad Sep 03 '19 at 10:08
  • Correct, if the font file packaged in your app, it will delete when the app was uninstalled. And if the font was installed to OS the font will remain – Nico Zhu Sep 04 '19 at 08:13
  • @NicoZhu-MSFT Thank you a lot for your time and patience. I'm not sure if I understood well. What I want is both to install the font to the OS (so it can be available to browsers) and that it uninstalls automatically from the OS when my app is uninstalled. Will packaging my app with an installer help me achieve that ? – Goasmad Sep 04 '19 at 08:33
  • Do you want to publish font app in the ms store ? – Nico Zhu Sep 04 '19 at 08:41
  • @NicoZhu-MSFT I want to publish the app to the ms store yes. – Goasmad Sep 04 '19 at 09:58
  • You could publish your font app in the store, After install the app, the font will be will manage within OS setting page. – Nico Zhu Sep 06 '19 at 03:20
  • @NicoZhu-MSFT ok, thank you for your help. I had to move on, but I'll try that when I deploy my app to the store. – Goasmad Sep 06 '19 at 11:58

0 Answers0