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