Skip to content

Commit 8e92b02

Browse files
committed
removed the constant file edit feature
1 parent 14ecd6c commit 8e92b02

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

‎src/containers/sb3-downloader.jsx‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import downloadBlob from '../lib/download-blob';
77
import {setProjectUnchanged} from '../reducers/project-changed';
88
import {showStandardAlert, showAlertWithTimeout} from '../reducers/alerts';
99
import {setFileHandle} from '../reducers/tw';
10+
import FileSystemAPI from '../lib/tw-filesystem-api';
1011
import {getIsShowingProject} from '../reducers/project-state';
1112
import log from '../lib/log';
1213

@@ -96,18 +97,7 @@ class SB3Downloader extends React.Component {
9697
return;
9798
}
9899
try {
99-
const handle = await this.props.showSaveFilePicker({
100-
suggestedName: this.props.projectFilename,
101-
types: [
102-
{
103-
description: 'CodeTorch Project',
104-
accept: {
105-
'application/x.scratch.sb3': '.torch'
106-
}
107-
}
108-
],
109-
excludeAcceptAllOption: true
110-
});
100+
const handle = await FileSystemAPI.showSaveFilePicker(this.props.projectFilename);
111101
await this.saveToHandle(handle);
112102
this.props.onSetFileHandle(handle);
113103
const title = getProjectTitleFromFilename(handle.name);
@@ -251,7 +241,7 @@ class SB3Downloader extends React.Component {
251241
return children(
252242
this.props.className,
253243
this.downloadProject,
254-
this.props.showSaveFilePicker ? {
244+
FileSystemAPI.available() ? {
255245
available: true,
256246
name: this.props.fileHandle ? this.props.fileHandle.name : null,
257247
saveAsNew: this.saveAsNew,
@@ -290,12 +280,10 @@ SB3Downloader.propTypes = {
290280
onShowSavingAlert: PropTypes.func,
291281
onShowSaveSuccessAlert: PropTypes.func,
292282
onShowSaveErrorAlert: PropTypes.func,
293-
onProjectUnchanged: PropTypes.func,
294-
showSaveFilePicker: PropTypes.func
283+
onProjectUnchanged: PropTypes.func
295284
};
296285
SB3Downloader.defaultProps = {
297-
className: '',
298-
showSaveFilePicker: typeof showSaveFilePicker === 'function' ? window.showSaveFilePicker.bind(window) : null
286+
className: ''
299287
};
300288

301289
const mapStateToProps = state => ({

‎src/lib/tw-filesystem-api.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const available = () => !!window.showSaveFilePicker;
2+
3+
const showSaveFilePicker = fileName => window.showSaveFilePicker({
4+
suggestedName: fileName,
5+
types: [
6+
{
7+
description: 'Scratch 3 Project',
8+
accept: {
9+
'application/x.scratch.sb3': '.sb3'
10+
}
11+
}
12+
],
13+
excludeAcceptAllOption: true
14+
});
15+
16+
const showOpenFilePicker = async () => {
17+
const [handle] = await window.showOpenFilePicker({
18+
multiple: false,
19+
types: [
20+
{
21+
description: 'Scratch Project',
22+
accept: {
23+
'application/x.scratch.sb3': ['.torch' ,'.sb', '.sb2', '.sb3']
24+
}
25+
}
26+
]
27+
});
28+
return handle;
29+
};
30+
31+
export default {
32+
available,
33+
showOpenFilePicker,
34+
showSaveFilePicker
35+
};

0 commit comments

Comments
 (0)