| 
									
										
										
										
											2023-08-28 13:23:10 +02:00
										 |  |  | const { app, BrowserWindow, ipcMain } = require('electron/main') | 
					
						
							| 
									
										
										
										
											2023-07-17 10:30:53 +02:00
										 |  |  | const path = require('node:path') | 
					
						
							|  |  |  | const fs = require('node:fs') | 
					
						
							|  |  |  | const https = require('node:https') | 
					
						
							| 
									
										
										
										
											2020-11-30 09:48:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 06:42:20 -07:00
										 |  |  | function createWindow () { | 
					
						
							| 
									
										
										
										
											2020-11-30 09:48:39 +02:00
										 |  |  |   const win = new BrowserWindow({ | 
					
						
							|  |  |  |     width: 800, | 
					
						
							|  |  |  |     height: 600, | 
					
						
							|  |  |  |     webPreferences: { | 
					
						
							| 
									
										
										
										
											2021-05-18 17:55:24 -07:00
										 |  |  |       preload: path.join(__dirname, 'preload.js') | 
					
						
							| 
									
										
										
										
											2020-11-30 09:48:39 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   win.loadFile('index.html') | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-05-18 17:55:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 06:42:20 -07:00
										 |  |  | const iconName = path.join(__dirname, 'iconForDragAndDrop.png') | 
					
						
							|  |  |  | const icon = fs.createWriteStream(iconName) | 
					
						
							| 
									
										
										
										
											2021-05-18 17:55:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Create a new file to copy - you can also copy existing files.
 | 
					
						
							|  |  |  | fs.writeFileSync(path.join(__dirname, 'drag-and-drop-1.md'), '# First file to test drag and drop') | 
					
						
							|  |  |  | fs.writeFileSync(path.join(__dirname, 'drag-and-drop-2.md'), '# Second file to test drag and drop') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | https.get('https://img.icons8.com/ios/452/drag-and-drop.png', (response) => { | 
					
						
							| 
									
										
										
										
											2023-04-05 06:42:20 -07:00
										 |  |  |   response.pipe(icon) | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2020-11-30 09:48:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | app.whenReady().then(createWindow) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ipcMain.on('ondragstart', (event, filePath) => { | 
					
						
							|  |  |  |   event.sender.startDrag({ | 
					
						
							| 
									
										
										
										
											2021-05-18 17:55:24 -07:00
										 |  |  |     file: path.join(__dirname, filePath), | 
					
						
							| 
									
										
										
										
											2023-04-05 06:42:20 -07:00
										 |  |  |     icon: iconName | 
					
						
							| 
									
										
										
										
											2020-11-30 09:48:39 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | app.on('window-all-closed', () => { | 
					
						
							|  |  |  |   if (process.platform !== 'darwin') { | 
					
						
							|  |  |  |     app.quit() | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | app.on('activate', () => { | 
					
						
							|  |  |  |   if (BrowserWindow.getAllWindows().length === 0) { | 
					
						
							|  |  |  |     createWindow() | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }) |