dsh-duet 0.3.2 → 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.
@@ -1,8 +1,33 @@
1
1
  /** Desired voice mode is independent of a temporarily suspended connection. */
2
- export const PLUGIN_VERSION = '0.3.2'
2
+ export const PLUGIN_VERSION = '0.3.3'
3
3
  export const IDLE_RELEASE_MS = 60_000
4
4
 
5
5
  const safeVersion = value => typeof value === 'string' && value.length <= 32 && /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(value) ? value : ''
6
+ const compareVersions = (a, b) => a.split('.').reduce((result, v, i) => result || Math.sign(Number(v) - Number(b.split('.')[i])), 0)
7
+
8
+ /** Display only upgrades the installed client has not received yet. */
9
+ export function updateDetails(info = {}, current = PLUGIN_VERSION) {
10
+ const target = safeVersion(info.recommended_client_version)
11
+ const entries = new Map()
12
+ if (safeVersion(current) && target && compareVersions(target, current) > 0) {
13
+ for (const row of (Array.isArray(info.release_history) ? info.release_history.slice(0, 64) : [])) {
14
+ if (!safeVersion(row?.version) || typeof row.notes !== 'string' || !row.notes.trim()) continue
15
+ if (compareVersions(row.version, current) > 0 && compareVersions(row.version, target) <= 0) {
16
+ entries.set(row.version, {version: row.version, notes: row.notes.slice(0, 1000).trim()})
17
+ }
18
+ }
19
+ if (!entries.has(target) && typeof info.recommended_release_notes === 'string' && info.recommended_release_notes.trim()) {
20
+ entries.set(target, {version: target, notes: info.recommended_release_notes.slice(0, 1000).trim()})
21
+ }
22
+ }
23
+ let remaining = 16000
24
+ const releases = [...entries.values()].sort((a, b) => compareVersions(b.version, a.version)).filter(row => {
25
+ remaining -= row.notes.length
26
+ return remaining >= 0
27
+ })
28
+ return {currentVersion: current, targetVersion: target, releases,
29
+ releaseNotes: info.recommended_release_notes}
30
+ }
6
31
  export function compatibilityNotice(code, details = {}, mode = 'online') {
7
32
  const key = mode === 'tts_only' ? 'tts_only' : 'online'
8
33
  const info = details.compatibility || {}
@@ -85,11 +110,11 @@ export class DuetState {
85
110
  if(event.reconnect_required===true&&this.mode!=='off')void this.replaceConnection({reason:'voice_policy_changed'})
86
111
  } else if (event.type === 'compatibility') {
87
112
  const recommended = safeVersion(event.compatibility?.recommended_client_version)
88
- const newer = recommended && recommended.split('.').reduce((result, v, i) => result || Math.sign(Number(v) - Number(PLUGIN_VERSION.split('.')[i])), 0) > 0
113
+ const newer = recommended && compareVersions(recommended, PLUGIN_VERSION) > 0
89
114
  if (newer && this.recommendationShown !== recommended) {
90
115
  this.recommendationShown = recommended
91
116
  this.notice(`当前插件 ${PLUGIN_VERSION},推荐更新到 ${recommended}。当前连接可以继续使用。`, {
92
- upgrade: true, releaseNotes: event.compatibility?.recommended_release_notes,
117
+ upgrade: true, ...updateDetails(event.compatibility),
93
118
  })
94
119
  }
95
120
  } else if (event.type === 'ready') {
@@ -122,7 +147,7 @@ export class DuetState {
122
147
  const compatibility = compatibilityNotice(code, details, this.mode)
123
148
  if (compatibility) {
124
149
  this.notice(compatibility, { upgrade: code !== 'client_version_unsupported',
125
- releaseNotes: details.compatibility?.recommended_release_notes || details.policy?.recommended_release_notes })
150
+ ...updateDetails({...details.policy, ...details.compatibility}) })
126
151
  void this.setMode('off', {reason:'error',code})
127
152
  return
128
153
  }