You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			37 lines
		
	
	
		
			962 B
		
	
	
	
		
			JavaScript
		
	
		
		
			
		
	
	
			37 lines
		
	
	
		
			962 B
		
	
	
	
		
			JavaScript
		
	
| 
								 
											7 years ago
										 
									 | 
							
								const electron = require('electron');
							 | 
						||
| 
								 | 
							
								const Attachments = require('./attachments');
							 | 
						||
| 
								 | 
							
								const rimraf = require('rimraf');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								const { ipcMain } = electron;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.exports = {
							 | 
						||
| 
								 | 
							
								  initialize,
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								let initialized = false;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								const ERASE_ATTACHMENTS_KEY = 'erase-attachments';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								async function initialize({ configDir }) {
							 | 
						||
| 
								 | 
							
								  if (initialized) {
							 | 
						||
| 
								 | 
							
								    throw new Error('initialze: Already initialized!');
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  initialized = true;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  console.log('Ensure attachments directory exists');
							 | 
						||
| 
								 | 
							
								  await Attachments.ensureDirectory(configDir);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  const attachmentsDir = Attachments.getPath(configDir);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  ipcMain.on(ERASE_ATTACHMENTS_KEY, async event => {
							 | 
						||
| 
								 | 
							
								    try {
							 | 
						||
| 
								 | 
							
								      rimraf.sync(attachmentsDir);
							 | 
						||
| 
								 | 
							
								      event.sender.send(`${ERASE_ATTACHMENTS_KEY}-done`);
							 | 
						||
| 
								 | 
							
								    } catch (error) {
							 | 
						||
| 
								 | 
							
								      const errorForDisplay = error && error.stack ? error.stack : error;
							 | 
						||
| 
								 | 
							
								      console.log(`sql-erase error: ${errorForDisplay}`);
							 | 
						||
| 
								 | 
							
								      event.sender.send(`${ERASE_ATTACHMENTS_KEY}-done`, error);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  });
							 | 
						||
| 
								 | 
							
								}
							 |