@@ -73,6 +73,14 @@ const createAboutWindow = () => {
73
73
return window ;
74
74
} ;
75
75
76
+ const getIsProjectSave = downloadItem => {
77
+ switch ( downloadItem . getMimeType ( ) ) {
78
+ case 'application/x.scratch.sb3' :
79
+ return true ;
80
+ }
81
+ return false ;
82
+ } ;
83
+
76
84
const createMainWindow = ( ) => {
77
85
const window = createWindow ( {
78
86
width : defaultSize . width ,
@@ -82,27 +90,32 @@ const createMainWindow = () => {
82
90
const webContents = window . webContents ;
83
91
84
92
webContents . session . on ( 'will-download' , ( ev , item ) => {
93
+ const isProjectSave = getIsProjectSave ( item ) ;
85
94
const itemPath = item . getFilename ( ) ;
86
95
const baseName = path . basename ( itemPath ) ;
87
96
const extName = path . extname ( baseName ) ;
97
+ const options = {
98
+ defaultPath : baseName
99
+ } ;
88
100
if ( extName ) {
89
101
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 ) {
97
108
const newProjectTitle = path . basename ( userChosenPath , extName ) ;
98
109
webContents . send ( 'setTitleFromSave' , { title : newProjectTitle } ) ;
99
110
100
111
// "setTitleFromSave" will set the project title but GUI has already reported the telemetry event
101
112
// using the old title. This call lets the telemetry client know that the save was actually completed
102
113
// and the event should be committed to the event queue with this new title.
103
114
telemetry . projectSaveCompleted ( newProjectTitle ) ;
104
- } else {
105
- item . cancel ( ) ;
115
+ }
116
+ } else {
117
+ item . cancel ( ) ;
118
+ if ( isProjectSave ) {
106
119
telemetry . projectSaveCanceled ( ) ;
107
120
}
108
121
}
0 commit comments