@shiqianjiang/ceru-plugin-cli 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +4 -0
  2. package/assets/core-contracts.js +1 -1
  3. package/assets/native-view.js +125 -0
  4. package/assets/playground.js +84 -1
  5. package/assets/sandbox.js +19 -19
  6. package/assets/style.css +57 -0
  7. package/dist/dev.js +2 -1
  8. package/package.json +3 -3
  9. package/schemas/config.schema.json +43 -2
  10. package/templates/connected-library/js/README.md +6 -2
  11. package/templates/connected-library/js/ceru.plugin.json +11 -2
  12. package/templates/connected-library/js/package.json +2 -2
  13. package/templates/connected-library/js/src/index.js +52 -1
  14. package/templates/connected-library/ts/README.md +6 -2
  15. package/templates/connected-library/ts/ceru.plugin.json +11 -2
  16. package/templates/connected-library/ts/package.json +2 -2
  17. package/templates/connected-library/ts/src/index.ts +52 -1
  18. package/templates/guest-adapter/js/package.json +2 -2
  19. package/templates/guest-adapter/ts/package.json +2 -2
  20. package/templates/importer/js/package.json +2 -2
  21. package/templates/importer/ts/package.json +2 -2
  22. package/templates/react/js/package.json +2 -2
  23. package/templates/react/ts/package.json +2 -2
  24. package/templates/snapshot.json +1 -1
  25. package/templates/source/js/package.json +2 -2
  26. package/templates/source/ts/package.json +2 -2
  27. package/templates/vue/js/package.json +2 -2
  28. package/templates/vue/ts/package.json +2 -2
  29. package/templates/vue-tsx/js/package.json +2 -2
  30. package/templates/vue-tsx/ts/package.json +2 -2
  31. package/templates/web-dist/js/package.json +2 -2
  32. package/templates/web-dist/ts/package.json +2 -2
  33. package/templates/web-surface/js/package.json +2 -2
  34. package/templates/web-surface/ts/package.json +2 -2
package/assets/style.css CHANGED
@@ -111,6 +111,17 @@ textarea {
111
111
  aside button {
112
112
  margin: 4px 0;
113
113
  }
114
+ .account-item { position: relative; }
115
+ .account-logout {
116
+ display: none;
117
+ position: absolute;
118
+ left: 100%;
119
+ top: 0;
120
+ z-index: 5;
121
+ white-space: nowrap;
122
+ }
123
+ .account-item:hover .account-logout:not([hidden]),
124
+ .account-item:focus-within .account-logout:not([hidden]) { display: block; }
114
125
  aside .item {
115
126
  display: flex;
116
127
  align-items: center;
@@ -186,6 +197,52 @@ pre {
186
197
  .preview {
187
198
  min-height: 150px;
188
199
  }
200
+ .native-actions {
201
+ display: flex;
202
+ flex-wrap: wrap;
203
+ gap: 8px;
204
+ margin: 8px 0;
205
+ }
206
+ .native-section { margin: 20px 0; }
207
+ .native-grid {
208
+ display: grid;
209
+ grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
210
+ gap: 20px;
211
+ }
212
+ .native-item { min-width: 0; }
213
+ .native-item-title {
214
+ display: block;
215
+ padding: 0;
216
+ margin: 8px 0;
217
+ border: 0;
218
+ text-align: left;
219
+ background: transparent;
220
+ color: inherit;
221
+ }
222
+ .native-item .hint {
223
+ overflow: hidden;
224
+ display: -webkit-box;
225
+ -webkit-box-orient: vertical;
226
+ -webkit-line-clamp: 2;
227
+ }
228
+ .native-artwork {
229
+ display: block;
230
+ width: 100%;
231
+ aspect-ratio: 1;
232
+ object-fit: cover;
233
+ border-radius: 8px;
234
+ background: var(--line);
235
+ }
236
+ .native-list .native-item {
237
+ display: flex;
238
+ justify-content: space-between;
239
+ align-items: center;
240
+ gap: 16px;
241
+ border-bottom: 1px solid var(--line);
242
+ padding: 10px 0;
243
+ }
244
+ .native-list .native-item-content { display: flex; gap: 12px; align-items: center; }
245
+ .native-list .native-artwork { width: 48px; flex-shrink: 0; }
189
246
  .preview iframe {
190
247
  width: 100%;
191
248
  min-height: 280px;
package/dist/dev.js CHANGED
@@ -546,7 +546,7 @@ export async function runDev(project, options = {}) {
546
546
  type = 'text/html';
547
547
  response.setHeader('Content-Security-Policy', "default-src 'none'; script-src 'self' 'nonce-" +
548
548
  nonce +
549
- "'; style-src 'self'; img-src 'self' data:; media-src 'self' http: https: data: blob:; connect-src 'self'; frame-src 'self'; frame-ancestors 'none'; base-uri 'none'; object-src 'none'");
549
+ "'; style-src 'self'; img-src 'self' data: http: https:; media-src 'self' http: https: data: blob:; connect-src 'self'; frame-src 'self'; frame-ancestors 'none'; base-uri 'none'; object-src 'none'");
550
550
  }
551
551
  else if (url.pathname === '/sandbox.html') {
552
552
  const moduleId = url.searchParams.get('module') ?? '';
@@ -576,6 +576,7 @@ export async function runDev(project, options = {}) {
576
576
  else {
577
577
  const file = {
578
578
  '/playground.js': 'playground.js',
579
+ '/native-view.js': 'native-view.js',
579
580
  '/core-contracts.js': 'core-contracts.js',
580
581
  '/style.css': 'style.css',
581
582
  '/sandbox.js': 'sandbox.js',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiqianjiang/ceru-plugin-cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "TypeScript scaffolding, single-file build, watch, validation, signing and issuance for Ceru plugins",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/core": "^7.29.7",
35
- "@shiqianjiang/ceru-plugin-issuer": "0.3.1",
36
- "@shiqianjiang/ceru-plugin-sdk": "0.3.1",
35
+ "@shiqianjiang/ceru-plugin-issuer": "0.3.3",
36
+ "@shiqianjiang/ceru-plugin-sdk": "0.3.3",
37
37
  "@vue/babel-plugin-jsx": "^2.0.1",
38
38
  "@vue/compiler-sfc": "3.5.43",
39
39
  "axios": "^1.20.0",
@@ -176,7 +176,8 @@
176
176
  "kind": {
177
177
  "enum": [
178
178
  "schema",
179
- "web"
179
+ "web",
180
+ "native"
180
181
  ]
181
182
  },
182
183
  "entry": {
@@ -192,7 +193,10 @@
192
193
  "type": "object",
193
194
  "properties": {
194
195
  "kind": {
195
- "const": "drawer"
196
+ "enum": [
197
+ "drawer",
198
+ "modal"
199
+ ]
196
200
  },
197
201
  "placement": {
198
202
  "enum": [
@@ -385,6 +389,43 @@
385
389
  "additionalProperties": false
386
390
  }
387
391
  },
392
+ "accountItems": {
393
+ "type": "array",
394
+ "maxItems": 16,
395
+ "items": {
396
+ "type": "object",
397
+ "properties": {
398
+ "id": {
399
+ "type": "string",
400
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$"
401
+ },
402
+ "title": {
403
+ "type": "string",
404
+ "minLength": 1,
405
+ "maxLength": 4096
406
+ },
407
+ "view": {
408
+ "type": "string",
409
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$"
410
+ },
411
+ "action": {
412
+ "type": "string",
413
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$"
414
+ },
415
+ "logoutAction": {
416
+ "type": "string",
417
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$"
418
+ }
419
+ },
420
+ "required": [
421
+ "id",
422
+ "title",
423
+ "view",
424
+ "action"
425
+ ],
426
+ "additionalProperties": false
427
+ }
428
+ },
388
429
  "homeSections": {
389
430
  "type": "array",
390
431
  "maxItems": 32,
@@ -36,8 +36,12 @@ F5 执行当前下拉框中的配置,不会自动选择终端所在的子工
36
36
 
37
37
  ## 边界
38
38
 
39
- 本模板面向 v2 协议。开发工作台不是当前 v1 桌面 Host 的兼容层。
39
+ 本模板面向 v2 协议,需要支持 native Surface 的 Host。
40
40
  凭据保险箱、完整音乐业务和 Guest 安装需要正式 Host;不支持的调试调用会明确报错。
41
41
  不要把私人 API Key、卡密或发行私钥提交到仓库。
42
42
 
43
- 此 demo 展示连接表单和状态更新;点击“演示连接”不会联网或保存密码。
43
+ 此 demo 展示原生歌单网格、歌曲列表、账号菜单贡献、导入及播放动作,还有连接表单和状态更新;点击“演示连接”不会联网或保存密码。元数据来自本地常量,播放前需实现自己的 tracks.resolve。
44
+
45
+ 原生页面由 src/index.js 中的 defineNativeView 返回标准 JSON 内容,Host 使用自己的组件呈现。打开歌单传递完整 ResourceRef,进入 Host 歌单详情;播放调用 Host 队列和播放器;导入调用 Host 现有导入窗口。独立工作台渲染原生预览并记录导航,完整音乐业务由正式 Host 实现。
46
+
47
+ 账号摘要返回 signedIn、displayName、可选 avatarUrl/badge;账号变化通过 ctx.ui.setState 通知 Host。自定义账号登录页面也可使用 Vue 或 React 打包为 Web Surface,与原生音乐库页面同时存在。
@@ -16,6 +16,7 @@
16
16
  "activation": ["onCommand:hello", "onProvider:catalog"]
17
17
  },
18
18
  "surfaces": [
19
+ { "id": "library", "kind": "native", "entry": "render.library" },
19
20
  {
20
21
  "id": "settings",
21
22
  "kind": "schema",
@@ -25,6 +26,11 @@
25
26
  },
26
27
  "contributes": {
27
28
  "commands": [
29
+ { "id": "account.summary", "title": "账号状态", "action": "account.summary" },
30
+ { "id": "render.library", "title": "渲染音乐库", "action": "render.library" },
31
+ { "id": "playlist.open", "title": "打开歌单", "action": "playlist.open" },
32
+ { "id": "playlist.import", "title": "导入歌单", "action": "playlist.import" },
33
+ { "id": "track.play", "title": "播放", "action": "track.play" },
28
34
  {
29
35
  "id": "hello",
30
36
  "title": "Hello",
@@ -41,7 +47,7 @@
41
47
  {
42
48
  "id": "catalog",
43
49
  "name": "js",
44
- "protocols": ["music.search@1", "music.resolve@1"],
50
+ "protocols": ["music.search@1", "music.resolve@1", "music.playlists@1"],
45
51
  "icon": {
46
52
  "kind": "host",
47
53
  "name": "music-note"
@@ -49,6 +55,9 @@
49
55
  "connectionMode": "multiple"
50
56
  }
51
57
  ],
58
+ "homeSections": [{ "id": "library", "title": "我的音乐库", "kind": "custom", "view": "library" }],
59
+ "accountItems": [{ "id": "catalog", "title": "音乐库账号", "view": "settings", "action": "account.summary" }],
60
+ "playlistImporters": [{ "id": "catalog", "title": "演示歌单", "providerId": "catalog" }],
52
61
  "settingsPages": [
53
62
  {
54
63
  "id": "settings",
@@ -57,7 +66,7 @@
57
66
  }
58
67
  ]
59
68
  },
60
- "permissions": [],
69
+ "permissions": [{ "key": "playback", "name": "player.control", "reason": "使用 Host 的播放器和队列播放音乐库歌曲" }],
61
70
  "dataSchemas": {
62
71
  "config": 1,
63
72
  "state": 1
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
@@ -1,11 +1,57 @@
1
- import { definePlugin } from '@shiqianjiang/ceru-plugin-sdk'
1
+ import { assertResourceRef, defineNativeView, definePlugin } from '@shiqianjiang/ceru-plugin-sdk'
2
2
 
3
3
  export default definePlugin(async (ctx) => {
4
+ let connected = false
5
+ const playlist = {
6
+ ref: { pluginId: ctx.plugin.id, providerId: 'catalog', connectionId: 'demo', kind: 'playlist', id: 'demo' },
7
+ title: '演示歌单',
8
+ playlist: { description: '由插件提供数据,由 Host 渲染原生歌单卡片', trackCount: 1 },
9
+ capabilities: ['open'],
10
+ }
11
+ const tracks = [{
12
+ ref: { pluginId: ctx.plugin.id, providerId: 'catalog', connectionId: 'demo', kind: 'track', id: 'demo-track' },
13
+ title: '接入你的音乐库后即可播放',
14
+ metadata: { artists: ['演示歌手'] },
15
+ capabilities: ['play'],
16
+ }]
4
17
  await ctx.ui.setState('settings', {
5
18
  serverUrl: 'https://music.example.com',
6
19
  status: '等待演示连接',
7
20
  })
8
21
  ctx.actions.register('hello', () => ctx.ui.openView('settings'))
22
+ ctx.actions.register('account.summary', () => ({
23
+ signedIn: connected,
24
+ displayName: connected ? '演示音乐库' : '连接你的音乐库',
25
+ }))
26
+ ctx.actions.register('render.library', defineNativeView(() => ({
27
+ type: 'page',
28
+ description: connected ? '演示连接已建立' : '可先浏览演示内容,再接入自己的音乐库 API。',
29
+ actions: [{ label: '连接设置', action: 'hello' }],
30
+ sections: [
31
+ { id: 'playlists', title: '我的歌单', layout: 'grid', items: [playlist], onOpen: 'playlist.open',
32
+ itemActions: [{ label: '导入歌单', action: 'playlist.import' }] },
33
+ { id: 'tracks', title: '歌曲', layout: 'list', items: tracks, onPlay: 'track.play' },
34
+ ],
35
+ })))
36
+ ctx.actions.register('playlist.open', async (input) => {
37
+ const ref = input && typeof input === 'object' && !Array.isArray(input) ? input.ref : undefined
38
+ assertResourceRef(ref)
39
+ if (ref.pluginId !== ctx.plugin.id || ref.providerId !== 'catalog' || ref.id !== playlist.ref.id)
40
+ throw new Error('Unknown playlist')
41
+ await ctx.ui.navigation.open({ page: 'playlist', ref })
42
+ })
43
+ ctx.actions.register('playlist.import', () =>
44
+ ctx.ui.playlistImport.open({ importerId: 'catalog', initialValue: playlist.ref.id }))
45
+ ctx.actions.register('track.play', async (_input, operation) => {
46
+ const grants = await ctx.permissions.requestGroup({ group: 'playbackControl' })
47
+ if (grants.status !== 'granted') throw new Error('需要播放控制权限')
48
+ const call = { permissionKey: 'playback', operation }
49
+ await ctx.queue.replace(tracks, call)
50
+ await ctx.player.play(tracks[0].ref, call)
51
+ })
52
+ ctx.playlistImporters.register('catalog', {
53
+ async getTracks() { return { name: playlist.title, items: tracks } },
54
+ })
9
55
 
10
56
  ctx.actions.register('connection.connect', async (input) => {
11
57
  if (
@@ -19,6 +65,8 @@ export default definePlugin(async (ctx) => {
19
65
  const server = new URL(input.serverUrl)
20
66
  if (!['http:', 'https:'].includes(server.protocol)) throw new Error('只支持 HTTP(S) 地址')
21
67
 
68
+ connected = true
69
+ await ctx.ui.setState('library', { connected })
22
70
  // 本地 demo 不联网,也不收集密码。真实连接应使用 Host 的凭据与网络 API。
23
71
  await ctx.ui.setState('settings', {
24
72
  serverUrl: server.origin,
@@ -28,6 +76,9 @@ export default definePlugin(async (ctx) => {
28
76
  })
29
77
 
30
78
  ctx.providers.register('catalog', {
79
+ playlists: {
80
+ async get() { return { name: playlist.title, playlist: playlist.playlist, items: tracks } },
81
+ },
31
82
  tracks: {
32
83
  async search() {
33
84
  return { items: [] }
@@ -36,8 +36,12 @@ F5 执行当前下拉框中的配置,不会自动选择终端所在的子工
36
36
 
37
37
  ## 边界
38
38
 
39
- 本模板面向 v2 协议。开发工作台不是当前 v1 桌面 Host 的兼容层。
39
+ 本模板面向 v2 协议,需要支持 native Surface 的 Host。
40
40
  凭据保险箱、完整音乐业务和 Guest 安装需要正式 Host;不支持的调试调用会明确报错。
41
41
  不要把私人 API Key、卡密或发行私钥提交到仓库。
42
42
 
43
- 此 demo 展示连接表单和状态更新;点击“演示连接”不会联网或保存密码。
43
+ 此 demo 展示原生歌单网格、歌曲列表、账号菜单贡献、导入及播放动作,还有连接表单和状态更新;点击“演示连接”不会联网或保存密码。元数据来自本地常量,播放前需实现自己的 tracks.resolve。
44
+
45
+ 原生页面由 src/index.ts 中的 defineNativeView 返回标准 JSON 内容,Host 使用自己的组件呈现。打开歌单传递完整 ResourceRef,进入 Host 歌单详情;播放调用 Host 队列和播放器;导入调用 Host 现有导入窗口。独立工作台渲染原生预览并记录导航,完整音乐业务由正式 Host 实现。
46
+
47
+ 账号摘要返回 signedIn、displayName、可选 avatarUrl/badge;账号变化通过 ctx.ui.setState 通知 Host。自定义账号登录页面也可使用 Vue 或 React 打包为 Web Surface,与原生音乐库页面同时存在。
@@ -16,6 +16,7 @@
16
16
  "activation": ["onCommand:hello", "onProvider:catalog"]
17
17
  },
18
18
  "surfaces": [
19
+ { "id": "library", "kind": "native", "entry": "render.library" },
19
20
  {
20
21
  "id": "settings",
21
22
  "kind": "schema",
@@ -25,6 +26,11 @@
25
26
  },
26
27
  "contributes": {
27
28
  "commands": [
29
+ { "id": "account.summary", "title": "账号状态", "action": "account.summary" },
30
+ { "id": "render.library", "title": "渲染音乐库", "action": "render.library" },
31
+ { "id": "playlist.open", "title": "打开歌单", "action": "playlist.open" },
32
+ { "id": "playlist.import", "title": "导入歌单", "action": "playlist.import" },
33
+ { "id": "track.play", "title": "播放", "action": "track.play" },
28
34
  {
29
35
  "id": "hello",
30
36
  "title": "Hello",
@@ -41,7 +47,7 @@
41
47
  {
42
48
  "id": "catalog",
43
49
  "name": "ts",
44
- "protocols": ["music.search@1", "music.resolve@1"],
50
+ "protocols": ["music.search@1", "music.resolve@1", "music.playlists@1"],
45
51
  "icon": {
46
52
  "kind": "host",
47
53
  "name": "music-note"
@@ -49,6 +55,9 @@
49
55
  "connectionMode": "multiple"
50
56
  }
51
57
  ],
58
+ "homeSections": [{ "id": "library", "title": "我的音乐库", "kind": "custom", "view": "library" }],
59
+ "accountItems": [{ "id": "catalog", "title": "音乐库账号", "view": "settings", "action": "account.summary" }],
60
+ "playlistImporters": [{ "id": "catalog", "title": "演示歌单", "providerId": "catalog" }],
52
61
  "settingsPages": [
53
62
  {
54
63
  "id": "settings",
@@ -57,7 +66,7 @@
57
66
  }
58
67
  ]
59
68
  },
60
- "permissions": [],
69
+ "permissions": [{ "key": "playback", "name": "player.control", "reason": "使用 Host 的播放器和队列播放音乐库歌曲" }],
61
70
  "dataSchemas": {
62
71
  "config": 1,
63
72
  "state": 1
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
@@ -1,11 +1,57 @@
1
- import { definePlugin } from '@shiqianjiang/ceru-plugin-sdk'
1
+ import { assertResourceRef, defineNativeView, definePlugin } from '@shiqianjiang/ceru-plugin-sdk'
2
2
 
3
3
  export default definePlugin(async (ctx) => {
4
+ let connected = false
5
+ const playlist = {
6
+ ref: { pluginId: ctx.plugin.id, providerId: 'catalog', connectionId: 'demo', kind: 'playlist', id: 'demo' },
7
+ title: '演示歌单',
8
+ playlist: { description: '由插件提供数据,由 Host 渲染原生歌单卡片', trackCount: 1 },
9
+ capabilities: ['open'],
10
+ }
11
+ const tracks = [{
12
+ ref: { pluginId: ctx.plugin.id, providerId: 'catalog', connectionId: 'demo', kind: 'track', id: 'demo-track' },
13
+ title: '接入你的音乐库后即可播放',
14
+ metadata: { artists: ['演示歌手'] },
15
+ capabilities: ['play'],
16
+ }]
4
17
  await ctx.ui.setState('settings', {
5
18
  serverUrl: 'https://music.example.com',
6
19
  status: '等待演示连接',
7
20
  })
8
21
  ctx.actions.register('hello', () => ctx.ui.openView('settings'))
22
+ ctx.actions.register('account.summary', () => ({
23
+ signedIn: connected,
24
+ displayName: connected ? '演示音乐库' : '连接你的音乐库',
25
+ }))
26
+ ctx.actions.register('render.library', defineNativeView(() => ({
27
+ type: 'page',
28
+ description: connected ? '演示连接已建立' : '可先浏览演示内容,再接入自己的音乐库 API。',
29
+ actions: [{ label: '连接设置', action: 'hello' }],
30
+ sections: [
31
+ { id: 'playlists', title: '我的歌单', layout: 'grid', items: [playlist], onOpen: 'playlist.open',
32
+ itemActions: [{ label: '导入歌单', action: 'playlist.import' }] },
33
+ { id: 'tracks', title: '歌曲', layout: 'list', items: tracks, onPlay: 'track.play' },
34
+ ],
35
+ })))
36
+ ctx.actions.register('playlist.open', async (input) => {
37
+ const ref = input && typeof input === 'object' && !Array.isArray(input) ? input.ref : undefined
38
+ assertResourceRef(ref)
39
+ if (ref.pluginId !== ctx.plugin.id || ref.providerId !== 'catalog' || ref.id !== playlist.ref.id)
40
+ throw new Error('Unknown playlist')
41
+ await ctx.ui.navigation.open({ page: 'playlist', ref })
42
+ })
43
+ ctx.actions.register('playlist.import', () =>
44
+ ctx.ui.playlistImport.open({ importerId: 'catalog', initialValue: playlist.ref.id }))
45
+ ctx.actions.register('track.play', async (_input, operation) => {
46
+ const grants = await ctx.permissions.requestGroup({ group: 'playbackControl' })
47
+ if (grants.status !== 'granted') throw new Error('需要播放控制权限')
48
+ const call = { permissionKey: 'playback', operation }
49
+ await ctx.queue.replace(tracks, call)
50
+ await ctx.player.play(tracks[0].ref, call)
51
+ })
52
+ ctx.playlistImporters.register('catalog', {
53
+ async getTracks() { return { name: playlist.title, items: tracks } },
54
+ })
9
55
 
10
56
  ctx.actions.register('connection.connect', async (input) => {
11
57
  if (
@@ -19,6 +65,8 @@ export default definePlugin(async (ctx) => {
19
65
  const server = new URL(input.serverUrl)
20
66
  if (!['http:', 'https:'].includes(server.protocol)) throw new Error('只支持 HTTP(S) 地址')
21
67
 
68
+ connected = true
69
+ await ctx.ui.setState('library', { connected })
22
70
  // 本地 demo 不联网,也不收集密码。真实连接应使用 Host 的凭据与网络 API。
23
71
  await ctx.ui.setState('settings', {
24
72
  serverUrl: server.origin,
@@ -28,6 +76,9 @@ export default definePlugin(async (ctx) => {
28
76
  })
29
77
 
30
78
  ctx.providers.register('catalog', {
79
+ playlists: {
80
+ async get() { return { name: playlist.title, playlist: playlist.playlist, items: tracks } },
81
+ },
31
82
  tracks: {
32
83
  async search() {
33
84
  return { items: [] }
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2",
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 1,
3
3
  "source": "https://github.com/CeruMusic/CeruMusic-Plugin-Template",
4
- "digest": "sha256:4a9b69d1c8c0742faf77ece05955e571b4004276ff4f936766cffea65e0f496f",
4
+ "digest": "sha256:31f6521365e6ea22a9f553b7061c6f0fc99037e9aebb82b7b46540d2f7cfb865",
5
5
  "files": [
6
6
  "connected-library/js/_gitignore",
7
7
  "connected-library/js/.prettierrc.json",
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2",
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2",
@@ -11,10 +11,10 @@
11
11
  "preview": "ceru-plugin preview dist/plugin.js"
12
12
  },
13
13
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.1"
14
+ "@shiqianjiang/ceru-plugin-sdk": "^0.3.3"
15
15
  },
16
16
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.1",
17
+ "@shiqianjiang/ceru-plugin-cli": "^0.3.3",
18
18
  "typescript": "~5.9.3",
19
19
  "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2",