Skip to content

Commit 7efbed3

Browse files
committed
hopefully finally fix safari file selectors
1 parent 8448b2f commit 7efbed3

4 files changed

Lines changed: 34 additions & 7 deletions

File tree

src/lib/is-safari.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// taken from the packager so this should be accurate?
2+
const isSafari = () =>
3+
!navigator.userAgentData &&
4+
/Safari\//.test(navigator.userAgent) &&
5+
!/Chrom(e|ium)\//.test(navigator.userAgent);
6+
7+
export default isSafari;

src/lib/pm-mature-fs-available.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @fileoverview Module to help determine how much of the file-system APIs can be used.
3+
* NOTE: This module is meant to help with a few things,
4+
* 1. Recognize that Chrome on Desktop should support everything
5+
* 2. Tell if a browser (like Firefox & Safari) is missing File System Access API
6+
* 3. State if the browser is known to be extremely bad at supporting the file type filters (mobile browsers + Safari on all platforms)
7+
*/
8+
import { isMobile } from './pm-mobile';
9+
import isSafari from './is-safari';
10+
11+
// NOTE: handles point 1 & 2
12+
const isApiAvailable = () => !!window.showSaveFilePicker;
13+
14+
// NOTE: handles point 3
15+
const isTypeFilterAvailable = () => !(isMobile() || isSafari());
16+
17+
export {
18+
isApiAvailable,
19+
isTypeFilterAvailable,
20+
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {connect} from 'react-redux';
66
import log from '../lib/log';
77
import sharedMessages from './shared-messages';
88
import FileSystemAPI from './tw-filesystem-api';
9-
import {isMobile} from './pm-mobile';
9+
import {isTypeFilterAvailable} from './pm-mature-fs-available';
1010
import {setFileHandle} from '../reducers/tw';
1111
import JSZip from 'jszip';
1212

@@ -109,8 +109,8 @@ const SBFileUploaderHOC = function (WrappedComponent) {
109109
// create <input> element and add it to DOM
110110
this.inputElement = document.createElement('input');
111111

112-
// pm: Some bad mobile devices block any file type (iOS)
113-
if (!isMobile()) {
112+
// pm: Some bad browsers block any file type (Safari) so we need to only add .accept for those which can handle it properly
113+
if (isTypeFilterAvailable()) {
114114
this.inputElement.accept = '.sb,.sb2,.sb3,.pm,.pmp';
115115
}
116116

src/lib/tw-filesystem-api.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { isMobile } from './pm-mobile';
1+
import { isApiAvailable, isTypeFilterAvailable } from './pm-mature-fs-available';
22

3-
const available = () => !!window.showSaveFilePicker;
3+
const available = isApiAvailable;
44

55
// pm: Some bad mobile devices block any file type (iOS), so these funcs should allow all files on mobile
66
const showSaveFilePicker = fileName => window.showSaveFilePicker({
77
suggestedName: fileName,
8-
...(isMobile() ? {} : {
8+
...(!isTypeFilterAvailable() ? {} : {
99
types: [
1010
{
1111
description: 'PenguinMod Project',
@@ -21,7 +21,7 @@ const showSaveFilePicker = fileName => window.showSaveFilePicker({
2121
const showOpenFilePicker = async () => {
2222
const [handle] = await window.showOpenFilePicker({
2323
multiple: false,
24-
...(isMobile() ? {} : {
24+
...(!isTypeFilterAvailable() ? {} : {
2525
types: [
2626
{
2727
description: 'Supported Files',

0 commit comments

Comments
 (0)