@@ -2,6 +2,7 @@ const fsPromises = require('fs/promises');
22const path = require ( 'path' ) ;
33const nodeURL = require ( 'url' ) ;
44const zlib = require ( 'zlib' ) ;
5+ const nodeCrypto = require ( 'crypto' ) ;
56const { app, dialog} = require ( 'electron' ) ;
67const ProjectRunningWindow = require ( './project-running-window' ) ;
78const AddonsWindow = require ( './addons' ) ;
@@ -202,38 +203,12 @@ const isChildPath = (parent, child) => {
202203 return ! ! relative && ! relative . startsWith ( '..' ) && ! path . isAbsolute ( relative ) ;
203204} ;
204205
205- /** @type {Set<string> } */
206- const allFileIDs = new Set ( ) ;
207-
208206/**
209207 * @returns {string } A unique string.
210208 */
211209const generateFileId = ( ) => {
212- let result ;
213- let tries = 0 ;
214-
215- do {
216- tries ++ ;
217- if ( tries > 50 ) {
218- // Should never happen...
219- throw new Error ( 'Failed to generate file ID' ) ;
220- }
221-
222- result = 'desktop_file_id{' ;
223-
224- // >200 bits of randomness; impractical to brute force.
225- // Math.random() is not cryptographically secure, but even if someone can reverse it, they would
226- // still only be able to access files that were already opened, so impact is not that big.
227- const soup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ;
228- for ( let i = 0 ; i < 40 ; i ++ ) {
229- result += soup [ Math . floor ( Math . random ( ) * soup . length ) ] ;
230- }
231-
232- result += '}' ;
233- } while ( allFileIDs . has ( result ) ) ;
234-
235- allFileIDs . add ( result ) ;
236- return result ;
210+ // Note that we can't use the randomUUID from web crypto as we need to support Electron 22.
211+ return `desktop_file_id{${ nodeCrypto . randomUUID ( ) } }` ;
237212} ;
238213
239214class EditorWindow extends ProjectRunningWindow {
0 commit comments