Skip to content

Commit 3e8bf27

Browse files
committed
Add more mime types to showOpenFilePicker
This may fix various issues on Android. If not, we'll just disable using this API on Android because otherwise we just have a file picker that doesn't work half the time. Related to TurboWarp/unpackager#14 (comment)
1 parent 063c399 commit 3e8bf27

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/lib/sb-file-uploader-hoc.jsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,43 @@ const SBFileUploaderHOC = function (WrappedComponent) {
7676
if (this.props.showOpenFilePicker) {
7777
(async () => {
7878
try {
79+
const extensions = ['.sb', '.sb2', '.sb3'];
7980
const [handle] = await this.props.showOpenFilePicker({
8081
multiple: false,
8182
types: [
8283
{
8384
description: 'Scratch Project',
8485
accept: {
85-
// Using application/x.scratch.sb3 as done in scratch-vm causes file pickers
86-
// to disallow picking any items in Chrome 133 on Android.
87-
'application/octet-stream': ['.sb', '.sb2', '.sb3']
86+
// Chrome on Android seems to track the MIME type that a file has when it is
87+
// downloaded and then the file picker enforces that it must match one of
88+
// the types given here. Unfortunately, Scratch projects are not a very popular
89+
// file type so there is no actual standard and everyone uses a different
90+
// string. We are thus forced to enumerate them all here so that the file picker
91+
// actually works as Android does not allow the user to manually disable the
92+
// type filters.
93+
94+
// Most file hosting serivces won't recognize Scratch projects, so they'll
95+
// serve it as an opaque byte stream.
96+
'application/octet-stream': extensions,
97+
98+
// https://github.com/scratchfoundation/scratch-editor/blob/22f44c64a5287d6d511f4819f065270a6981f2c8/packages/scratch-vm/src/virtual-machine.js#L451C24-L451C53
99+
'application/x.scratch.sb3': extensions,
100+
101+
// The dots are unusual, so sometimes hyphens are used instead.
102+
'application/x-scratch-sb3': extensions,
103+
104+
// https://aur.archlinux.org/cgit/aur.git/tree/scratch3.xml?h=scratch3#n3
105+
'application/x-scratch3-project': extensions,
106+
107+
// Used in various places but no clear origin
108+
// https://github.com/search?q=%22application%2Fx-scratch2%22&type=code
109+
'application/x-scratch2': extensions,
110+
111+
// https://aur.archlinux.org/cgit/aur.git/tree/scratch2.xml?h=scratch2#n3
112+
'application/x-scratch2-project': extensions,
113+
114+
// https://github.com/scratchfoundation/Scratch_1.4/blob/d26f099e3d8358760d0129de4a57e792d97d146f/src/scratch.xml
115+
'application/x-scratch-project': extensions
88116
}
89117
}
90118
]
@@ -101,8 +129,7 @@ const SBFileUploaderHOC = function (WrappedComponent) {
101129
if (err && err.name === 'AbortError') {
102130
return;
103131
}
104-
// eslint-disable-next-line no-console
105-
console.error(err);
132+
log.error(err);
106133
}
107134
})();
108135
} else {

0 commit comments

Comments
 (0)