@@ -52,6 +52,7 @@ const {
52
52
SHOW_LOAD_SPACE_PROMPT_CHANNEL ,
53
53
RESPOND_LOAD_SPACE_PROMPT_CHANNEL ,
54
54
SAVE_SPACE_CHANNEL ,
55
+ GET_USER_FOLDER_CHANNEL ,
55
56
} = require ( './app/config/channels' ) ;
56
57
const {
57
58
ERROR_SPACE_ALREADY_AVAILABLE ,
@@ -273,7 +274,7 @@ app.on('ready', async () => {
273
274
274
275
const { phases, image } = spaceToSave ;
275
276
276
- const spacePath = ` ${ VAR_FOLDER } / ${ id } ` ;
277
+ const spacePath = id ;
277
278
278
279
// todo: follow new format
279
280
// if there is a background/thumbnail image, save it
@@ -292,18 +293,18 @@ app.on('ready', async () => {
292
293
const hash = generateHash ( { url } ) ;
293
294
const imageFileName = `${ hash } .${ ext } ` ;
294
295
const imagePath = `${ spacePath } /${ imageFileName } ` ;
296
+ const absoluteSpacePath = `${ VAR_FOLDER } /${ spacePath } ` ;
297
+ const absoluteImagePath = `${ VAR_FOLDER } /${ imagePath } ` ;
295
298
// eslint-disable-next-line no-await-in-loop
296
- const imageAvailable = await isFileAvailable ( imagePath ) ;
297
- if ( imageAvailable ) {
298
- spaceToSave . image [ key ] = imagePath ;
299
- } else {
299
+ const imageAvailable = await isFileAvailable ( absoluteImagePath ) ;
300
+ if ( ! imageAvailable ) {
300
301
// eslint-disable-next-line no-await-in-loop
301
- const imageDl = await download ( mainWindow , url , {
302
- directory : spacePath ,
302
+ await download ( mainWindow , url , {
303
+ directory : absoluteSpacePath ,
303
304
filename : imageFileName ,
304
305
} ) ;
305
- spaceToSave . image [ key ] = imageDl . getSavePath ( ) ;
306
306
}
307
+ spaceToSave . image [ key ] = imagePath ;
307
308
}
308
309
}
309
310
}
@@ -325,22 +326,22 @@ app.on('ready', async () => {
325
326
const ext = getExtension ( resource ) ;
326
327
const fileName = `${ hash } .${ ext } ` ;
327
328
const filePath = `${ spacePath } /${ fileName } ` ;
329
+ const absoluteSpacePath = `${ VAR_FOLDER } /${ spacePath } ` ;
330
+ const absoluteFilePath = `${ VAR_FOLDER } /${ filePath } ` ;
328
331
phase . items [ i ] . hash = hash ;
329
332
330
333
// eslint-disable-next-line no-await-in-loop
331
- const fileAvailable = await isFileAvailable ( filePath ) ;
334
+ const fileAvailable = await isFileAvailable ( absoluteFilePath ) ;
332
335
333
336
// if the file is available, point this resource to its path
334
- if ( fileAvailable ) {
335
- phase . items [ i ] . asset = filePath ;
336
- } else {
337
+ if ( ! fileAvailable ) {
337
338
// eslint-disable-next-line no-await-in-loop
338
- const dl = await download ( mainWindow , url , {
339
- directory : spacePath ,
339
+ await download ( mainWindow , url , {
340
+ directory : absoluteSpacePath ,
340
341
filename : fileName ,
341
342
} ) ;
342
- phase . items [ i ] . asset = dl . getSavePath ( ) ;
343
343
}
344
+ phase . items [ i ] . asset = filePath ;
344
345
}
345
346
}
346
347
}
@@ -557,6 +558,16 @@ app.on('ready', async () => {
557
558
mainWindow . webContents . send ( RESPOND_DELETE_SPACE_PROMPT_CHANNEL , respond ) ;
558
559
} ) ;
559
560
} ) ;
561
+
562
+ // called when getting user folder
563
+ ipcMain . on ( GET_USER_FOLDER_CHANNEL , ( ) => {
564
+ try {
565
+ mainWindow . webContents . send ( GET_USER_FOLDER_CHANNEL , VAR_FOLDER ) ;
566
+ } catch ( e ) {
567
+ logger . error ( e ) ;
568
+ mainWindow . webContents . send ( GET_USER_FOLDER_CHANNEL , ERROR_GENERAL ) ;
569
+ }
570
+ } ) ;
560
571
} ) ;
561
572
562
573
app . on ( 'window-all-closed' , ( ) => {
0 commit comments