Skip to content

Commit

Permalink
存在下载的时候,关闭会弹出窗口确认
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingCdesu committed May 21, 2021
1 parent 551e371 commit de2fc10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
12 changes: 2 additions & 10 deletions src/common/utils/store.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import Store from 'electron-store'
import { app } from 'electron'

export default new Store({
const store = new Store({
name: 'store',
defaults: {
defaultDownloadPath: app?.getPath('downloads'),
displayWithUnicode: false
},

schema: {
defaultDownloadPath: {
type: 'string'
},
displayWithUnicode: {
type: 'boolean'
},
}
})
export default store
24 changes: 21 additions & 3 deletions src/main/download/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const listenerDownload = async (
downloadItem.fileName = path.basename(saveFilePath)
renameFile(downloadItem.path, saveFilePath)
downloadItem.path = saveFilePath

app.dock.downloadFinished(downloadItem.path)
}

Expand Down Expand Up @@ -331,13 +331,13 @@ const listenerEvent = () => {
export const registerDownloadService = (window: BrowserWindow | null): void => {
win = window
listenerEvent()
window?.on('close', () => {
const onClose = () => {
// 窗口关闭时,将下载中或中断的项暂停,并删除本地缓存
downloadItemData.forEach(item => {
if (['progressing', 'interrupted'].includes(item.state)) {
item._sourceItem?.pause()
item.paused = true
removeFile(item.path)
// removeFile(item.path)
}
})

Expand All @@ -349,5 +349,23 @@ export const registerDownloadService = (window: BrowserWindow | null): void => {
downloadCompletedIds = []
setTaskbar(downloadItemData, downloadCompletedIds, -1, win)
win = null
}
window?.on('close', (event) => {
if (downloadItemData.filter(item =>
item.state === 'progressing' || item.state === 'interrupted'
).length > 0) {
const result = dialog.showMessageBoxSync({
type: 'info',
title: '确定关闭?',
message: '还有下载在进行,确定退出吗?',
buttons: ['确定', '取消']
})
if (result === 0) {
onClose()
} else {
event.preventDefault();
}
}

})
}

0 comments on commit de2fc10

Please sign in to comment.