Skip to content

Commit d885d21

Browse files
committed
Refactor: Replace UA sniffing with feature detection
1 parent 4d478b7 commit d885d21

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/component/fileBrowser.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const LocalFileBrowser = ({ superState, dispatcher }) => {
1515
const [fileState, setFileState] = useState([]);
1616

1717
useEffect(() => {
18-
if (navigator.userAgent.indexOf('Edg') !== -1 || navigator.userAgent.indexOf('Chrome') !== -1) {
18+
if ('showDirectoryPicker' in window) {
1919
setDirButton(true);
2020
}
2121
dispatcher({ type: T.SET_FILE_REF, payload: fileRef });
@@ -159,7 +159,7 @@ const LocalFileBrowser = ({ superState, dispatcher }) => {
159159
webkitdirectory="true"
160160
/>
161161
</label>
162-
) }
162+
)}
163163
{dirButton && (
164164
<button
165165
type="button"
@@ -204,7 +204,7 @@ const LocalFileBrowser = ({ superState, dispatcher }) => {
204204
<h4>
205205
Folder Name :
206206
{' '}
207-
{fileState[0] ? fileState[0].key.split('/')[0] : '' }
207+
{fileState[0] ? fileState[0].key.split('/')[0] : ''}
208208
</h4>
209209
<FileBrowser
210210
files={fileState}

src/graph-builder/graph-core/5-load-save.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class GraphLoadSave extends GraphUndoRedo {
106106
const str = graphmlBuilder(this.jsonifyGraph());
107107
const bytes = new TextEncoder().encode(str);
108108
const blob = new Blob([bytes], { type: 'application/json;charset=utf-8' });
109-
if (navigator.userAgent.indexOf('Edg') !== -1 || navigator.userAgent.indexOf('Chrome') !== -1) {
109+
if ('showSaveFilePicker' in window) {
110110
const options = {
111111
types: [
112112
{
@@ -140,8 +140,7 @@ class GraphLoadSave extends GraphUndoRedo {
140140
}
141141

142142
async saveWithoutFileHandle() {
143-
const { userAgent } = navigator;
144-
if (userAgent.match(/firefox|fxios/i)) {
143+
if (!('showSaveFilePicker' in window)) {
145144
toast.info('Switch to Edge/Chrome!');
146145
return;
147146
}

0 commit comments

Comments
 (0)