22 * @Author : Leo Ding <leoding86@msn.com>
33 * @Date : 2024-08-11 11:09:14
44 * @LastEditors : Leo Ding <leoding86@msn.com>
5- * @LastEditTime : 2024-08-21 19:54:16
5+ * @LastEditTime : 2024-09-22 13:13:08
66 * @FilePath : \webextension-pixiv-toolkit\src\background\services\DownloadService.js
77 */
88import browser from "@/modules/Extension/browser" ;
@@ -24,6 +24,12 @@ class DownloadService extends AbstractService {
2424
2525 constructor ( ) {
2626 super ( ) ;
27+ this . listenOnDeterminingFilename ( ) ;
28+ }
29+
30+ listenOnDeterminingFilename ( ) {
31+ if ( DownloadService . onDeterminingFilenameListenered === true ) return ;
32+ DownloadService . onDeterminingFilenameListenered = true ;
2733
2834 browser . downloads . onDeterminingFilename . addListener ( ( downloadItem , suggest ) => {
2935 const filenameSuggestion = {
@@ -37,8 +43,6 @@ class DownloadService extends AbstractService {
3743 filenameSuggestion . filename = downloadItem . filename ;
3844 }
3945
40- console . log ( downloadItem , filenameSuggestion ) ;
41-
4246 suggest ( filenameSuggestion ) ;
4347 } ) ;
4448 }
@@ -133,4 +137,9 @@ class DownloadService extends AbstractService {
133137 }
134138}
135139
140+ /**
141+ * @type {boolean } Prevent listen the event multiple times
142+ */
143+ DownloadService . onDeterminingFilenameListenered = false ;
144+
136145export default DownloadService ;
0 commit comments