二期:修改自动同步检测逻辑
This commit is contained in:
parent
b8896bf53d
commit
57b7d3d601
|
@ -42,19 +42,23 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
|
|||
let filePath = appRootFilePath + fileNewName
|
||||
let uploadId = null
|
||||
let isOn = false
|
||||
let lastMTime = fs.statSync(filePath).mtime.getTime()
|
||||
console.log(lastMTime)
|
||||
setInterval(() => {
|
||||
getFileMD5(filePath).then((md5New) => {
|
||||
if (md5New !== md5) {
|
||||
md5 = md5New
|
||||
getFileMsg(filePath).then((msg) => {
|
||||
if (msg !== lastMTime) {
|
||||
lastMTime = msg
|
||||
if (uploadId) {
|
||||
clearTimeout(uploadId)
|
||||
}
|
||||
if (isOn === false) {
|
||||
console.log(fileNewName)
|
||||
e.reply('listen-file-change-on' + fileNewName)
|
||||
isOn = true
|
||||
}
|
||||
//倒数十秒提交更改,十秒之内有继续修改则重置倒数
|
||||
uploadId = setTimeout(() => {
|
||||
console.log(223)
|
||||
//执行更新,上传文件
|
||||
let formData = new FormData()
|
||||
formData.append('id', id)
|
||||
|
@ -77,12 +81,19 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
|
|||
console.error('Error uploading file:', err)
|
||||
}
|
||||
})
|
||||
}, 20000)
|
||||
}, 5000)
|
||||
}
|
||||
})
|
||||
}, 10000)
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
function getFileMsg(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const stats = fs.statSync(path)
|
||||
return resolve(stats.mtime.getTime())
|
||||
})
|
||||
}
|
||||
|
||||
function getFileMD5(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(path, (err, dataFile) => {
|
||||
|
|
|
@ -246,12 +246,12 @@ export default {
|
|||
fileType: item.fileType
|
||||
})
|
||||
ipcRenderer.on('listen-file-change-on' + item.fileNewName, () => {
|
||||
item.async = 'on'
|
||||
items.async = 'on'
|
||||
})
|
||||
ipcRenderer.on('listen-file-change-success' + item.fileNewName, (e, { data, md5 }) => {
|
||||
item.fileSize = data.fileSize
|
||||
item.md5 = md5
|
||||
item.async = true
|
||||
items.fileSize = data.fileSize
|
||||
items.md5 = md5
|
||||
items.async = true
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue