Skip to content

Commit 0bf03a2

Browse files
authored
Merge pull request scratchfoundation#77 from cwillisf/better-project-save-detection
Better project save detection
2 parents 9ec118e + 1df51fa commit 0bf03a2

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/main/index.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ const createAboutWindow = () => {
7373
return window;
7474
};
7575

76+
const getIsProjectSave = downloadItem => {
77+
switch (downloadItem.getMimeType()) {
78+
case 'application/x.scratch.sb3':
79+
return true;
80+
}
81+
return false;
82+
};
83+
7684
const createMainWindow = () => {
7785
const window = createWindow({
7886
width: defaultSize.width,
@@ -82,27 +90,32 @@ const createMainWindow = () => {
8290
const webContents = window.webContents;
8391

8492
webContents.session.on('will-download', (ev, item) => {
93+
const isProjectSave = getIsProjectSave(item);
8594
const itemPath = item.getFilename();
8695
const baseName = path.basename(itemPath);
8796
const extName = path.extname(baseName);
97+
const options = {
98+
defaultPath: baseName
99+
};
88100
if (extName) {
89101
const extNameNoDot = extName.replace(/^\./, '');
90-
const options = {
91-
defaultPath: baseName,
92-
filters: [getFilterForExtension(extNameNoDot)]
93-
};
94-
const userChosenPath = dialog.showSaveDialog(window, options);
95-
if (userChosenPath) {
96-
item.setSavePath(userChosenPath);
102+
options.filters = [getFilterForExtension(extNameNoDot)];
103+
}
104+
const userChosenPath = dialog.showSaveDialog(window, options);
105+
if (userChosenPath) {
106+
item.setSavePath(userChosenPath);
107+
if (isProjectSave) {
97108
const newProjectTitle = path.basename(userChosenPath, extName);
98109
webContents.send('setTitleFromSave', {title: newProjectTitle});
99110

100111
// "setTitleFromSave" will set the project title but GUI has already reported the telemetry event
101112
// using the old title. This call lets the telemetry client know that the save was actually completed
102113
// and the event should be committed to the event queue with this new title.
103114
telemetry.projectSaveCompleted(newProjectTitle);
104-
} else {
105-
item.cancel();
115+
}
116+
} else {
117+
item.cancel();
118+
if (isProjectSave) {
106119
telemetry.projectSaveCanceled();
107120
}
108121
}

0 commit comments

Comments
 (0)