自定义源添加更新地址参数

This commit is contained in:
lyswhut
2022-02-17 10:13:45 +08:00
parent 48fc96226c
commit fc12a235f2
9 changed files with 54 additions and 25 deletions
+12 -7
View File
@@ -121,10 +121,16 @@ const handleInit = (context, info) => {
})
}
const handleShowUpdateAlert = (message) => {
if (!message || typeof message != 'string') return
if (message.length > 1024) message = message.substring(0, 1024) + '...'
sendMessage(USER_API_RENDERER_EVENT_NAME.showUpdateAlert, message)
const handleShowUpdateAlert = (data, resolve, reject) => {
if (!data || typeof data != 'object') return reject(new Error('parameter format error.'))
if (!data.log || typeof data.log != 'string') return reject(new Error('log is required.'))
if (data.updateUrl && !/^https?:\/\/[^\s$.?#].[^\s]*$/.test(data.updateUrl) && data.updateUrl.length > 1024) delete data.updateUrl
if (data.log.length > 1024) data.log = data.log.substring(0, 1024) + '...'
sendMessage(USER_API_RENDERER_EVENT_NAME.showUpdateAlert, {
log: data.log,
updateUrl: data.updateUrl,
})
resolve()
}
contextBridge.exposeInMainWorld('lx', {
@@ -179,10 +185,9 @@ contextBridge.exposeInMainWorld('lx', {
resolve()
break
case EVENT_NAMES.updateAlert:
if (isShowedUpdateAlert) return reject(new Error('The update alert can only be called once'))
if (isShowedUpdateAlert) return reject(new Error('The update alert can only be called once.'))
isShowedUpdateAlert = true
handleShowUpdateAlert(data)
resolve()
handleShowUpdateAlert(data, resolve, reject)
break
default:
reject(new Error('Unknown event name: ' + eventName))
@@ -42,7 +42,8 @@ const handleShowUpdateAlert = (event, { data }) => {
global.lx_event.userApi.showUpdateAlert({
name: userApi.name,
description: userApi.description,
message: data,
log: data.log,
updateUrl: data.updateUrl,
})
}
mainOn(USER_API_RENDERER_EVENT_NAME.init, handleInit)