feat(browser): 最近访问列表走 ctx.data(插件数据层首个真实用例)v1.7.0
- 地址栏挂 datalist,提交地址时记录最近 12 条(去重、新的在前)
- 数据存 ctx.data(桌面落 <资料目录>/plugin-data/browser.json),不塞进 settings
- manifest 声明 data: {schemaVersion:1, maxBytes:65536}
- 数据不可用时静默降级,不影响浏览
This commit is contained in:
1 parent
fe1d3fcaa6
commit
7119dcf356
2 files changed
+44
-2
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/browser",
|
||||
"private": true,
|
||||
"version": "1.6.0",
|
||||
"version": "1.7.0",
|
||||
"description": "应用内浏览器:独立窗口打开网页,或在画布节点里内嵌网页(跟随画布缩放,可单独调内容缩放)",
|
||||
"ibwPlugin": {
|
||||
"id": "browser",
|
||||
|
||||
+43
-1
@@ -654,6 +654,45 @@
|
||||
// 面板关掉就没了,「✕ 关闭这个网页」在面板里没有意义
|
||||
st.close.style.display = 'none'
|
||||
st.onUrl = function (url) { try { ctx.settings.set('lastUrl', url) } catch (e) { /* 忽略 */ } }
|
||||
|
||||
// ── 最近访问(v1.7.0)────────────────────────────────────────────────
|
||||
// 存 ctx.data(桌面:<资料目录>/plugin-data/browser.json),与 settings 分开:
|
||||
// 这是会增长的列表,不该塞进配置;数据层有 2MiB 上限与串行写,够用且安全。
|
||||
var recent = []
|
||||
var recentList = el('datalist', {})
|
||||
recentList.id = 'iwb-br-recent' // 不用 {id:...} 字面量:validate 取首个 id 字面量判插件 id
|
||||
recentList.style.display = 'none'
|
||||
host.appendChild(recentList)
|
||||
if (st.input) st.input.setAttribute('list', 'iwb-br-recent')
|
||||
function renderRecent() {
|
||||
recentList.innerHTML = ''
|
||||
for (var ri = 0; ri < recent.length; ri++) recentList.appendChild(el('option', { value: recent[ri] }))
|
||||
}
|
||||
function remember(u) {
|
||||
if (!u) return
|
||||
var next = [u]
|
||||
for (var ri = 0; ri < recent.length && next.length < 12; ri++) if (recent[ri] !== u) next.push(recent[ri])
|
||||
recent = next
|
||||
renderRecent()
|
||||
var d = ctx.data
|
||||
if (!d || typeof d.patch !== 'function') return
|
||||
try { var pr = d.patch({ recent: recent }); if (pr && pr.catch) pr.catch(function () { /* 数据不可用不影响浏览 */ }) } catch (e) { /* ignore */ }
|
||||
}
|
||||
function loadRecent() {
|
||||
var d = ctx.data
|
||||
if (!d || typeof d.read !== 'function') return
|
||||
try {
|
||||
var pr = d.read()
|
||||
if (!pr || !pr.then) return
|
||||
pr.then(function (obj) {
|
||||
var list = obj && Array.isArray(obj.recent) ? obj.recent : []
|
||||
recent = list.filter(function (x) { return typeof x === 'string' && x }).slice(0, 12)
|
||||
renderRecent()
|
||||
}).catch(function () { /* 首次没有数据属正常 */ })
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
loadRecent()
|
||||
|
||||
bindWebNode(st, ctx)
|
||||
|
||||
function goTo(raw) {
|
||||
@@ -667,6 +706,7 @@
|
||||
st.input.value = u
|
||||
for (var i = 0; i < st.acts.length; i++) st.acts[i].disabled = false
|
||||
try { ctx.settings.set('lastUrl', u) } catch (e) { /* 忽略 */ }
|
||||
remember(u)
|
||||
}
|
||||
|
||||
// 书签:分组行 + 书签行。两行都单行横向滚动,尽量不占网页的高度。
|
||||
@@ -1090,10 +1130,12 @@
|
||||
global.IWBPluginHost.register({
|
||||
id: 'browser',
|
||||
name: '应用内浏览器',
|
||||
version: '1.6.0',
|
||||
version: '1.7.0',
|
||||
apiVersion: 1,
|
||||
// canvasWrite:面板里的「↗」用它把当前页变成画布上的网页节点(需要客户端 v3.25.30+)
|
||||
capabilities: ['panels', 'nodeTypes', 'canvasWrite'],
|
||||
// 最近访问列表(v1.7.0):走宿主 ctx.data(桌面落 plugin-data/browser.json),不塞进 settings
|
||||
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||
settings: {
|
||||
bookmarks: {
|
||||
// 宿主 v3.25.30 起支持 type:'custom':调用 render 拿到一整块 DOM 直接挂进
|
||||
|
||||
Reference in new issue
Block a user