mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 10:34:18 +00:00
improve serialize safe
This commit is contained in:
parent
e7cd36a5b3
commit
fd64d24470
@ -5,27 +5,35 @@ const forbidden = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export default (event, data) => {
|
export default (event, data) => {
|
||||||
function serializeIpc(data) {
|
try {
|
||||||
if (!data) {
|
function serializeIpc(data) {
|
||||||
return undefined
|
if (!data) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
data = JSON.stringify(data)
|
||||||
|
|
||||||
|
data = JSON.parse(data)
|
||||||
|
|
||||||
|
const copy = lodash.cloneDeep(data)
|
||||||
|
|
||||||
|
if (!Array.isArray(copy)) {
|
||||||
|
Object.keys(copy).forEach((key) => {
|
||||||
|
if (forbidden.includes(key)) {
|
||||||
|
delete copy[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof copy[key] === "function") {
|
||||||
|
delete copy[key]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy
|
||||||
}
|
}
|
||||||
|
|
||||||
const copy = lodash.cloneDeep(data)
|
global.win.webContents.send(event, serializeIpc(data))
|
||||||
|
} catch (error) {
|
||||||
if (!Array.isArray(copy)) {
|
console.error(error)
|
||||||
Object.keys(copy).forEach((key) => {
|
|
||||||
if (forbidden.includes(key)) {
|
|
||||||
delete copy[key]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof copy[key] === "function") {
|
|
||||||
delete copy[key]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return copy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
global.win.webContents.send(event, serializeIpc(data))
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user