Skip to content

Commit ea1650a

Browse files
committed
refactor(main): move emit 'file-complete' to method
1 parent e591d35 commit ea1650a

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/main/image-compressor.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ImageOptimizer {
7070
ensureDirSync(`${dir}/${MIN_FOLDER}`)
7171
}
7272

73-
this.#queue.push(() => this.#processFile(file, output, this.#context))
73+
this.#queue.push(() => this.#processFile(file, output))
7474
}
7575

7676
if (isFolder(file.path)) {
@@ -115,10 +115,7 @@ class ImageOptimizer {
115115
}
116116

117117
const compressedSize = getFileSize(output)
118-
context.webContents.send(
119-
'file-complete',
120-
this.#formatOutputData(file, originalSize, compressedSize)
121-
)
118+
this.#sendToRenderer(file, originalSize, compressedSize)
122119
resolve()
123120
}
124121
)
@@ -144,10 +141,7 @@ class ImageOptimizer {
144141
}
145142

146143
const compressedSize = getFileSize(output)
147-
context.webContents.send(
148-
'file-complete',
149-
this.#formatOutputData(file, originalSize, compressedSize)
150-
)
144+
this.#sendToRenderer(file, originalSize, compressedSize)
151145
resolve()
152146
}
153147
)
@@ -162,10 +156,7 @@ class ImageOptimizer {
162156
}
163157

164158
const compressedSize = getFileSize(output)
165-
context.webContents.send(
166-
'file-complete',
167-
this.#formatOutputData(file, originalSize, compressedSize)
168-
)
159+
this.#sendToRenderer(file, originalSize, compressedSize)
169160
resolve()
170161
})
171162
break
@@ -183,10 +174,7 @@ class ImageOptimizer {
183174
if (err) console.log(err)
184175

185176
const compressedSize = getFileSize(output)
186-
context.webContents.send(
187-
'file-complete',
188-
this.#formatOutputData(file, originalSize, compressedSize)
189-
)
177+
this.#sendToRenderer(file, originalSize, compressedSize)
190178
resolve()
191179
})
192180
})
@@ -207,6 +195,13 @@ class ImageOptimizer {
207195
).toFixed(2)
208196
}
209197
}
198+
199+
#sendToRenderer (file, originalSize, compressedSize) {
200+
this.#context.webContents.send(
201+
'file-complete',
202+
this.#formatOutputData(file, originalSize, compressedSize)
203+
)
204+
}
210205
}
211206

212207
module.exports = {

0 commit comments

Comments
 (0)