WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

Specifying as default file handler with content type instead of filetype

Open soumyamahunt opened this issue 5 years ago • 8 comments

Proposal: Specifying as default file handler with content type instead of filetype

Summary

Already asked in microsoft/microsoft-ui-xaml#2456 due to no proper channel to ask. Right now uwp devs have to extensively declare filetypes in manifest if they want their app to be default handler of that filetype. Instead content type should be declared in the manifest and app can be default handler of all files that have the declared content type.

Rationale

Declaring all filetypes is really taxing and in some cases like for a text editor app impossible to do. Instead declaring content type makes it easier for devs. Also in case of win32 apps, user can simply provide executable path to open the file with their app of choice but in case of uwp users can't choose it to default handler of unsupported filetypes. Current filetype association can be kept for silent take over as default handler also giving special icons to some filetypes.

  • Enable broad range of filetype support without much difficulty.
  • StorageFile methods like renaming file fails if trying to rename the file to a unsupported filetype as described in here.
  • StorageFile.GetFileAsync() fails for unsupported file types. This is useful to users as this enables them to open files from command line or WSL environments with uwp app.
  • Also, Launcher.LaunchFileAsync() fails if the filetype is undeclared which I observed when I tried to implement desktop extension in JasonStein/Notepads#534 to enable users to launch custom filetype with this app.

Scope

Capability Priority
Declaring default file handler via content type Must
Ability to change content type of file in open with menu Should

Open Questions

Should user be able set app as default handler of any kind of file like they can do so with win32?

soumyamahunt avatar May 19 '20 21:05 soumyamahunt

NOTE: The restrictions on the file extension/type are no longer present. You should see the new behavior in current OS previews

smaillet-ms avatar May 27 '20 19:05 smaillet-ms

NOTE: The restrictions on the file extension/type are no longer present. You should see the new behavior in current OS previews

Will it come in 2004 or later versions??

soumyamahunt avatar May 28 '20 05:05 soumyamahunt

Starting in Windows 10 version 2004, there are two changes which should help address some of your needs.

As @smaillet-ms mentioned, your app's file associations no longer restrict what you can do with the Windows.Storage APIs. (In prior releases, the Documents library and removable storage were restricted to block access to files of an unregistered type.)

You can register your app to handle files with any extension (and files with no extension). In your AppxManifest, add "*" as a FileType using the uap10 namespace, like this:

xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"
...
<uap:Extension Category="windows.fileTypeAssociation">
  <uap:FileTypeAssociation Name="anyfile">
    <uap:Logo>Assets\mylogo.png</uap:Logo>
    <uap:SupportedFileTypes>
      <uap10:FileType>*</uap10:FileType>
    </uap:SupportedFileTypes>
  </uap:FileTypeAssociation>
</uap:Extension>

After adding this to your AppxManifest, your app will show up in the "Open with" dialog for all files. You'll have to click "More apps..." to see it. You can handle file activation just like you do for files with an extension listed in your manifest.

mcooley avatar Jun 19 '20 02:06 mcooley

Starting in Windows 10 version 2004, there are two changes which should help address some of your needs.

As @smaillet-ms mentioned, your app's file associations no longer restrict what you can do with the Windows.Storage APIs. (In prior releases, the Documents library and removable storage were restricted to block access to files of an unregistered type.)

You can register your app to handle files with any extension (and files with no extension). In your AppxManifest, add "*" as a FileType using the uap10 namespace, like this:

xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"
...
<uap:Extension Category="windows.fileTypeAssociation">
  <uap:FileTypeAssociation Name="anyfile">
    <uap:Logo>Assets\mylogo.png</uap:Logo>
    <uap:SupportedFileTypes>
      <uap10:FileType>*</uap10:FileType>
    </uap:SupportedFileTypes>
  </uap:FileTypeAssociation>
</uap:Extension>

After adding this to your AppxManifest, your app will show up in the "Open with" dialog for all files. You'll have to click "More apps..." to see it. You can handle file activation just like you do for files with an extension listed in your manifest.

The app has to have minimum target version 19041 otherwise this fails with manifest validation error, however combining it with uap:FileType passes validation. To support earlier versions the code has to be slightly modified like this:

xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"
 ...
<uap:Extension Category="windows.fileTypeAssociation">
   <uap:FileTypeAssociation Name="anyfile">
     <uap:Logo>Assets\mylogo.png</uap:Logo>
     <uap:SupportedFileTypes>
       <uap:FileType>.txt</uap:FileType>
       <uap10:FileType>*</uap10:FileType>
     </uap:SupportedFileTypes>
   </uap:FileTypeAssociation>
</uap:Extension>

soumyamahunt avatar Jun 21 '20 08:06 soumyamahunt

@soumyamahunt - given @smaillet-ms's note https://github.com/microsoft/ProjectReunion/issues/27#issuecomment-647096712 and your response on to get back to 19041, is there anything else actionable here from Project Reunion?

stevewri avatar Nov 02 '20 19:11 stevewri

@stevewri right now the suggested solutions only work for build 19041 and later, if this could be backported to older Windows 10 versions as part of Project Reunion it would be really nice.

soumyamahunt avatar Nov 02 '20 19:11 soumyamahunt

Got it; how far back? RS4, 5?

stevewri avatar Nov 02 '20 19:11 stevewri

Preferably RS4, but I would like to see this backported as much as it is possible for reunion team.

soumyamahunt avatar Nov 03 '20 13:11 soumyamahunt