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

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
+3 -2
View File
@@ -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"
}
+3 -2
View File
@@ -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": "打开更新地址"
}
+3 -2
View File
@@ -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": "打開更新地址"
}
+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)
+22 -5
View File
@@ -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(() => {
+5 -4
View File
@@ -1,6 +1,6 @@
<template>
<Modal :show="visible" @close="handleCancel" @after-leave="afterLeave" :closeBtn="false" :teleport="teleport">
<main :class="$style.main">{{message}}</main>
<main class="scroll" :class="[$style.main, { 'select': selection }]">{{message}}</main>
<footer :class="$style.footer">
<Btn :class="$style.btn" v-if="showCancel" @click="handleCancel">{{cancelBtnText}}</Btn>
<Btn :class="$style.btn" @click="handleComfirm">{{confirmBtnText}}</Btn>
@@ -30,6 +30,7 @@ export default {
cancelButtonText: '',
confirmButtonText: '',
teleport: '#root',
selection: false,
}
},
computed: {
@@ -58,9 +59,9 @@ export default {
.main {
flex: auto;
min-height: 40px;
padding: 15px;
padding: 15px 15px 0;
font-size: 14px;
max-width: 320px;
// max-width: 320px;
min-width: 220px;
line-height: 1.5;
white-space: pre-line;
@@ -68,7 +69,7 @@ export default {
.footer {
flex: none;
padding: 0 15px 15px;
padding: 15px;
display: flex;
flex-flow: row nowrap;
justify-content: flex-end;
+3 -1
View File
@@ -10,10 +10,11 @@ const defaultOptions = {
showCancel: false,
cancelButtonText: '',
confirmButtonText: '',
selection: false,
}
export const dialog = function(options) {
const { message, showCancel, cancelButtonText, confirmButtonText, teleport } =
const { message, showCancel, cancelButtonText, confirmButtonText, teleport, selection } =
Object.assign({}, defaultOptions, typeof options == 'string' ? { message: options } : options || {})
return new Promise((resolve, reject) => {
let app = createApp(Dialog, {
@@ -32,6 +33,7 @@ export const dialog = function(options) {
instance.cancelButtonText = cancelButtonText
instance.confirmButtonText = confirmButtonText
instance.teleport = teleport
instance.selection = selection
// 挂载
document.getElementById('container').appendChild(instance.$el)