@@ -16,14 +16,12 @@ import { detectUnpackedDirs } from "./unpackDetector"
1616export class AsarPackager {
1717 private readonly outFile : string
1818 private rootForAppFilesWithoutAsar ! : string
19- private readonly tmpDir = new tempFile . TmpDir ( )
2019 private readonly fileCopier = new FileCopier ( )
21-
22- private readonly cleanup = ( ) => {
23- this . tmpDir . cleanupSync ( )
24- }
20+ private readonly tmpDir : tempFile . TmpDir
21+ private readonly cancellationToken : CancellationToken
2522
2623 constructor (
24+ readonly packager : PlatformPackager < any > ,
2725 private readonly config : {
2826 defaultDestination : string
2927 resourcePath : string
@@ -32,12 +30,12 @@ export class AsarPackager {
3230 }
3331 ) {
3432 this . outFile = path . join ( config . resourcePath , `app.asar` )
33+ this . tmpDir = packager . info . tempDirManager
34+ this . cancellationToken = packager . info . cancellationToken
3535 }
3636
37- async pack ( fileSets : Array < ResolvedFileSet > , packager : PlatformPackager < any > ) {
38- this . rootForAppFilesWithoutAsar = await packager . info . tempDirManager . getTempDir ( { prefix : "asar-app" } )
39- const cancellationToken = packager . info . cancellationToken
40- cancellationToken . addListener ( "cancel" , this . cleanup )
37+ async pack ( fileSets : Array < ResolvedFileSet > ) {
38+ this . rootForAppFilesWithoutAsar = await this . tmpDir . getTempDir ( { prefix : "asar-app" } )
4139
4240 const orderedFileSets = [
4341 // Write dependencies first to minimize offset changes to asar header
@@ -47,13 +45,10 @@ export class AsarPackager {
4745 fileSets [ 0 ] ,
4846 ] . map ( orderFileSet )
4947
50- const { unpackedPaths, copiedFiles } = await this . detectAndCopy ( orderedFileSets , cancellationToken )
48+ const { unpackedPaths, copiedFiles } = await this . detectAndCopy ( orderedFileSets )
5149 const unpackGlob = unpackedPaths . length > 1 ? `{${ unpackedPaths . join ( "," ) } }` : unpackedPaths . pop ( )
5250
5351 await this . executeElectronAsar ( copiedFiles , unpackGlob )
54-
55- this . cleanup ( )
56- cancellationToken . removeListener ( "cancel" , this . cleanup )
5752 }
5853
5954 private async executeElectronAsar ( copiedFiles : string [ ] , unpackGlob : string | undefined ) {
@@ -83,8 +78,8 @@ export class AsarPackager {
8378 console . log = consoleLogger
8479 }
8580
86- private async detectAndCopy ( fileSets : ResolvedFileSet [ ] , cancellationToken : CancellationToken ) {
87- const taskManager = new AsyncTaskManager ( cancellationToken )
81+ private async detectAndCopy ( fileSets : ResolvedFileSet [ ] ) {
82+ const taskManager = new AsyncTaskManager ( this . cancellationToken )
8883 const unpackedPaths = new Set < string > ( )
8984 const copiedFiles = new Set < string > ( )
9085
0 commit comments