diff --git a/FAQ.md b/FAQ.md index 71c061bd..aa7307a2 100644 --- a/FAQ.md +++ b/FAQ.md @@ -445,7 +445,7 @@ send(EVENT_NAMES.inited, { | --- | --- | `inited` | 脚本初始化完成后发送给应用的事件名,发送该事件时需要传入以下信息:`{status, sources, openDevTools}`
`status`:初始化结果(`true`成功,`false`失败)
`openDevTools`:是否打开DevTools,此选项可用于开发脚本时的调试
`sources`:支持的源信息对象,
`sources[kw/kg/tx/wy/mg].name`:源的名字(目前非必须)
`sources[kw/kg/tx/wy/mg].type`:源类型,目前固定值需为`music`
`sources[kw/kg/tx/wy/mg].actions`:支持的actions,由于目前只支持`musicUrl`,所以固定传`['musicUrl']`即可
`sources[kw/kg/tx/wy/mg].qualitys`:该源支持的音质列表,有效的值为`['128k', '320k', 'flac']`,该字段用于控制应用可用的音质类型 | `request` | 应用API请求事件名,回调入参:`handler({ source, action, info})`,回调必须返回`Promise`对象
`source`:音乐源,可能的值取决于初始化时传入的`sources`对象的源key值
`info`:请求附加信息,内容根据`action`变化
`action`:请求操作类型,目前只有`musicUrl`,即获取音乐URL链接,需要在 Promise 返回歌曲 url,`info`的结构:`{type, musicInfo}`,`info.type`:音乐质量,可能的值有`128k` / `320k` / `flac`(取决于初始化时对应源传入的`qualitys`值中的一个),`info.musicInfo`:音乐信息对象,里面有音乐ID、名字等信息 -| `updateAlert` | 显示源更新弹窗,发送此事件时,需要传入一个字符串(更新日志),内容可以使用`\n`换行,最大长度1024,超过此长度后将被截取超出的部分,此事件每次运行脚本只能调用一次(源版本v1.2.0新增)
例子:`lx.send(lx.EVENT_NAMES.updateAlert, 'hello world')` +| `updateAlert` | 显示源更新弹窗,发送该事件时的参数:`{log, updateUrl}`
`log`:更新日志,必传,字符串类型,内容可以使用`\n`换行,最大长度1024,超过此长度后将被截取超出的部分
`updateUrl`:更新地址,用于引导用户去该地址更新源,选传,需为http协议的url地址,最大长度1024
此事件每次运行脚本只能调用一次(源版本v1.2.0新增)
例子:`lx.send(lx.EVENT_NAMES.updateAlert, { log: 'hello world', updateUrl: 'https://xxx.com' })` #### `window.lx.on` diff --git a/src/lang/en-us.json b/src/lang/en-us.json index b83b3bb0..7f083a4b 100644 --- a/src/lang/en-us.json +++ b/src/lang/en-us.json @@ -140,7 +140,7 @@ "my_list": "Your Library", "no_item": "Nothing's here...", "not_agree": "Not accept", - "ok": "Ok", + "ok": "OK", "pagination__next": "Next page", "pagination__page": "Page {num}", "pagination__prev": "Previous page", @@ -419,5 +419,6 @@ "user_api__note": "Tip: Although we have isolated the script's running environment as much as possible, importing scripts containing malicious behaviors may still affect your system. Please import them carefully.", "user_api__readme": "Source writing instructions: ", "user_api__title": "Custom Source Management", - "user_api__update_alert": "Custom source [{name}] found new version:" + "user_api__update_alert": "Custom source [{name}] found new version:", + "user_api__update_alert_open_url": "Open update address" } diff --git a/src/lang/zh-cn.json b/src/lang/zh-cn.json index fdf2c8c5..cb7ea4ac 100644 --- a/src/lang/zh-cn.json +++ b/src/lang/zh-cn.json @@ -140,7 +140,7 @@ "my_list": "我的列表", "no_item": "列表竟然是空的...", "not_agree": "不接受", - "ok": "好吧", + "ok": "我知道了", "pagination__next": "下一页", "pagination__page": "第 {num} 页", "pagination__prev": "上一页", @@ -419,5 +419,6 @@ "user_api__note": "提示:虽然我们已经尽可能地隔离了脚本的运行环境,但导入包含恶意行为的脚本仍可能会影响你的系统,请谨慎导入。", "user_api__readme": "源编写说明:", "user_api__title": "自定义源管理", - "user_api__update_alert": "自定义源 [{name}] 发现新版本:" + "user_api__update_alert": "自定义源 [{name}] 发现新版本:", + "user_api__update_alert_open_url": "打开更新地址" } diff --git a/src/lang/zh-tw.json b/src/lang/zh-tw.json index 10febd01..fbf348d1 100644 --- a/src/lang/zh-tw.json +++ b/src/lang/zh-tw.json @@ -140,7 +140,7 @@ "my_list": "我的列表", "no_item": "列表竟然是空的...", "not_agree": "不接受", - "ok": "好吧", + "ok": "我知道了", "pagination__next": "下一頁", "pagination__page": "第 {num} 頁", "pagination__prev": "上一頁", @@ -419,5 +419,6 @@ "user_api__note": "提示:雖然我們已經盡可能地隔離了腳本的運行環境,但導入包含惡意行為的腳本仍可能會影響你的系統,請謹慎導入。", "user_api__readme": "源編寫說明:", "user_api__title": "自定義源管理", - "user_api__update_alert": "自定義源 [{name}] 發現新版本:" + "user_api__update_alert": "自定義源 [{name}] 發現新版本:", + "user_api__update_alert_open_url": "打開更新地址" } diff --git a/src/main/modules/userApi/renderer/preload.js b/src/main/modules/userApi/renderer/preload.js index 8bc4e4d9..18e2c3f5 100644 --- a/src/main/modules/userApi/renderer/preload.js +++ b/src/main/modules/userApi/renderer/preload.js @@ -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)) diff --git a/src/main/modules/userApi/rendererEvent/rendererEvent.js b/src/main/modules/userApi/rendererEvent/rendererEvent.js index 5a7ab10b..2982416b 100644 --- a/src/main/modules/userApi/rendererEvent/rendererEvent.js +++ b/src/main/modules/userApi/rendererEvent/rendererEvent.js @@ -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) diff --git a/src/renderer/core/useApp/useInitUserApi.js b/src/renderer/core/useApp/useInitUserApi.js index 020f8ca3..beb0dd0f 100644 --- a/src/renderer/core/useApp/useInitUserApi.js +++ b/src/renderer/core/useApp/useInitUserApi.js @@ -1,5 +1,6 @@ import { onBeforeUnmount, useI18n } from '@renderer/utils/vueTools' import { onUserApiStatus, setUserApi, getUserApiList, userApiRequest, userApiRequestCancel, onShowUserApiUpdateAlert } from '@renderer/utils/tools' +import { openUrl } from '@renderer/utils' import apiSourceInfo from '@renderer/utils/music/api-source-info' import music from '@renderer/utils/music' import { apiSource, qualityList, userApi } from '@renderer/core/share' @@ -69,11 +70,27 @@ export default ({ setting }) => { } }) - const rUserApiShowUpdateAlert = onShowUserApiUpdateAlert((event, { name, message }) => { - dialog({ - message: `${t('user_api__update_alert', { name })}\n${message}`, - confirmButtonText: t('ok'), - }) + const rUserApiShowUpdateAlert = onShowUserApiUpdateAlert((event, { name, log, updateUrl }) => { + if (updateUrl) { + dialog({ + message: `${t('user_api__update_alert', { name })}\n${log}`, + selection: true, + showCancel: true, + confirmButtonText: t('user_api__update_alert_open_url'), + cancelButtonText: t('close'), + }).then(confirm => { + if (!confirm) return + setTimeout(() => { + openUrl(updateUrl) + }, 300) + }) + } else { + dialog({ + message: `${t('user_api__update_alert', { name })}\n${log}`, + selection: true, + confirmButtonText: t('ok'), + }) + } }) onBeforeUnmount(() => { diff --git a/src/renderer/plugins/Dialog/Dialog.vue b/src/renderer/plugins/Dialog/Dialog.vue index 96853de1..ba496f23 100644 --- a/src/renderer/plugins/Dialog/Dialog.vue +++ b/src/renderer/plugins/Dialog/Dialog.vue @@ -1,6 +1,6 @@