Skip to content

Commit 1df51fa

Browse files
author
Christopher Willis-Ford
committed
detect project save based on content type
Also, if saving a file is canceled, only try to cancel project save telemetry if the save was a project save. Also also, don't skip showing the save dialog just because a file doesn't have an extension. Instead, just skip trying to determine filters for the extension in this case.
1 parent 9ef9d8f commit 1df51fa

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/main/index.js

Lines changed: 29 additions & 18 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,29 +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);
97-
if (extNameNoDot.toUpperCase() == "SB3") { // when a project is downloaded, not an asset
98-
const newProjectTitle = path.basename(userChosenPath, extName);
99-
webContents.send('setTitleFromSave', {title: newProjectTitle});
100-
101-
// "setTitleFromSave" will set the project title but GUI has already reported the telemetry event
102-
// using the old title. This call lets the telemetry client know that the save was actually completed
103-
// and the event should be committed to the event queue with this new title.
104-
telemetry.projectSaveCompleted(newProjectTitle);
105-
}
106-
} else {
107-
item.cancel();
102+
options.filters = [getFilterForExtension(extNameNoDot)];
103+
}
104+
const userChosenPath = dialog.showSaveDialog(window, options);
105+
if (userChosenPath) {
106+
item.setSavePath(userChosenPath);
107+
if (isProjectSave) {
108+
const newProjectTitle = path.basename(userChosenPath, extName);
109+
webContents.send('setTitleFromSave', {title: newProjectTitle});
110+
111+
// "setTitleFromSave" will set the project title but GUI has already reported the telemetry event
112+
// using the old title. This call lets the telemetry client know that the save was actually completed
113+
// and the event should be committed to the event queue with this new title.
114+
telemetry.projectSaveCompleted(newProjectTitle);
115+
}
116+
} else {
117+
item.cancel();
118+
if (isProjectSave) {
108119
telemetry.projectSaveCanceled();
109120
}
110121
}

0 commit comments

Comments
 (0)