Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSavePicker FileTypeChoices incorrect #5685

Closed
3 of 24 tasks
trungnt2910 opened this issue Apr 6, 2021 · 3 comments · Fixed by #5689
Closed
3 of 24 tasks

FileSavePicker FileTypeChoices incorrect #5685

trungnt2910 opened this issue Apr 6, 2021 · 3 comments · Fixed by #5689
Assignees
Labels
area/storage 📦 Categorizes an issue or PR as relevant to file storage difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI kind/bug Something isn't working project/non-ui ⚙️ Categorizes an issue or PR as relevant to winrt (non-ui)

Comments

@trungnt2910
Copy link
Contributor

trungnt2910 commented Apr 6, 2021

Current behavior

I have this code:

            var savePicker = new Windows.Storage.Pickers.FileSavePicker();
            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            savePicker.FileTypeChoices.Add("C/C++ source files", new List<string>() { ".cpp", ".c", ".cc", ".cxx", ".c++", ".cp" });
            savePicker.SuggestedFileName = "Hacked";
            Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

However, instead of showing these file types, they show .cp, .com, .exe, .bin.

image

Expected behavior

It shows the right file types, like in the my UWP-only project:

image

How to reproduce it (as minimally and precisely as possible)

  • Create a Uno project.
  • Open a FileSavePicker, like in the code above.
  • Build the WASM project.

Workaround

Found none.

Environment

Nuget Package:

  • Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
  • Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
  • Uno.SourceGenerationTasks
  • Uno.UI.RemoteControl / Uno.WinUI.RemoteControl
  • Other:

Nuget Package Version(s):

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Skia
    • WPF
    • GTK (Linux)
    • Tizen
  • Windows
  • Build tasks
  • Solution Templates

IDE:

  • Visual Studio 2017 (version: )
  • Visual Studio 2019 (version: 16.9.3)
  • Visual Studio for Mac (version: )
  • Rider Windows (version: )
  • Rider macOS (version: )
  • Visual Studio Code (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

FileOpenPicker seems to work well. Only FileSavePicker fails.

@trungnt2910 trungnt2910 added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Apr 6, 2021
@jeromelaban
Copy link
Member

/cc @MartinZikmund

@jeromelaban jeromelaban added difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI project/non-ui ⚙️ Categorizes an issue or PR as relevant to winrt (non-ui) area/storage 📦 Categorizes an issue or PR as relevant to file storage and removed difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. triage/untriaged Indicates an issue requires triaging or verification labels Apr 6, 2021
@MartinZikmund MartinZikmund self-assigned this Apr 6, 2021
@trungnt2910
Copy link
Contributor Author

trungnt2910 commented Apr 6, 2021

This seems to be the browser's bug. Calling showSaveFilePicker always make Edge add some unrelated file types.

In your implementation, .cpp files map to the default application/octet-stream, which somehow includes .com, .exe, .bin

A workaround is to associate all files with application/x-nonsense-file-type-that-will-never-exist.

@trungnt2910
Copy link
Contributor Author

var acceptItems = new List<NativeFilePickerAcceptTypeItem>();
foreach (var extension in choice.Value)
{
var acceptItem = new NativeFilePickerAcceptTypeItem()
{
MimeType = MimeTypeService.GetFromExtension(extension),
Extensions = new[] { extension }
};
acceptItems.Add(acceptItem);
}
acceptType.Accept = acceptItems.ToArray();
acceptTypes.Add(acceptType);

Is this expected behavior? This creates a something like this:

[{"accept":[{"extensions":[".cpp"],"mimeType":"application\/octet-stream"},{"extensions":[".c"],"mimeType":"application\/octet-stream"},{"extensions":[".cc"],"mimeType":"application\/octet-stream"},{"extensions":[".cxx"],"mimeType":"application\/octet-stream"},{"extensions":[".c++"],"mimeType":"application\/octet-stream"},{"extensions":[".cp"],"mimeType":"application\/octet-stream"}],"description":"C\/C++ source files"}]

The JS browser code seems to process the "accept" part as a dictionary, meaning that all options, except the last, that has the same mime type will be discarded. That's why only .cp is visible in my browser.

After that, they will append the default, but unrelated .com, .exe, and .bin types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/storage 📦 Categorizes an issue or PR as relevant to file storage difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI kind/bug Something isn't working project/non-ui ⚙️ Categorizes an issue or PR as relevant to winrt (non-ui)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants