mirror of
https://github.com/scratchfoundation/scratch-desktop.git
synced 2025-01-24 04:59:47 -05:00
Merge pull request #77 from cwillisf/better-project-save-detection
Better project save detection
This commit is contained in:
commit
0bf03a2199
1 changed files with 22 additions and 9 deletions
|
@ -73,6 +73,14 @@ const createAboutWindow = () => {
|
||||||
return window;
|
return window;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getIsProjectSave = downloadItem => {
|
||||||
|
switch (downloadItem.getMimeType()) {
|
||||||
|
case 'application/x.scratch.sb3':
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
const createMainWindow = () => {
|
const createMainWindow = () => {
|
||||||
const window = createWindow({
|
const window = createWindow({
|
||||||
width: defaultSize.width,
|
width: defaultSize.width,
|
||||||
|
@ -82,18 +90,21 @@ const createMainWindow = () => {
|
||||||
const webContents = window.webContents;
|
const webContents = window.webContents;
|
||||||
|
|
||||||
webContents.session.on('will-download', (ev, item) => {
|
webContents.session.on('will-download', (ev, item) => {
|
||||||
|
const isProjectSave = getIsProjectSave(item);
|
||||||
const itemPath = item.getFilename();
|
const itemPath = item.getFilename();
|
||||||
const baseName = path.basename(itemPath);
|
const baseName = path.basename(itemPath);
|
||||||
const extName = path.extname(baseName);
|
const extName = path.extname(baseName);
|
||||||
|
const options = {
|
||||||
|
defaultPath: baseName
|
||||||
|
};
|
||||||
if (extName) {
|
if (extName) {
|
||||||
const extNameNoDot = extName.replace(/^\./, '');
|
const extNameNoDot = extName.replace(/^\./, '');
|
||||||
const options = {
|
options.filters = [getFilterForExtension(extNameNoDot)];
|
||||||
defaultPath: baseName,
|
}
|
||||||
filters: [getFilterForExtension(extNameNoDot)]
|
const userChosenPath = dialog.showSaveDialog(window, options);
|
||||||
};
|
if (userChosenPath) {
|
||||||
const userChosenPath = dialog.showSaveDialog(window, options);
|
item.setSavePath(userChosenPath);
|
||||||
if (userChosenPath) {
|
if (isProjectSave) {
|
||||||
item.setSavePath(userChosenPath);
|
|
||||||
const newProjectTitle = path.basename(userChosenPath, extName);
|
const newProjectTitle = path.basename(userChosenPath, extName);
|
||||||
webContents.send('setTitleFromSave', {title: newProjectTitle});
|
webContents.send('setTitleFromSave', {title: newProjectTitle});
|
||||||
|
|
||||||
|
@ -101,8 +112,10 @@ const createMainWindow = () => {
|
||||||
// using the old title. This call lets the telemetry client know that the save was actually completed
|
// using the old title. This call lets the telemetry client know that the save was actually completed
|
||||||
// and the event should be committed to the event queue with this new title.
|
// and the event should be committed to the event queue with this new title.
|
||||||
telemetry.projectSaveCompleted(newProjectTitle);
|
telemetry.projectSaveCompleted(newProjectTitle);
|
||||||
} else {
|
}
|
||||||
item.cancel();
|
} else {
|
||||||
|
item.cancel();
|
||||||
|
if (isProjectSave) {
|
||||||
telemetry.projectSaveCanceled();
|
telemetry.projectSaveCanceled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue