@pi-unipi/info-screen 0.1.11 → 0.1.13

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/info-screen",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Dashboard and module registry for Unipi — configurable info overlay with tabbed groups",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/registry.ts CHANGED
@@ -224,6 +224,7 @@ class InfoRegistry {
224
224
  const group = this.groups.get(groupId);
225
225
  if (!group) return [];
226
226
 
227
+ if (!group.config?.stats) return [];
227
228
  return group.config.stats.filter((stat) => {
228
229
  if (!isStatEnabled(groupId, stat.id)) return false;
229
230
  return stat.show;
@@ -75,6 +75,12 @@ export class InfoOverlay implements Component {
75
75
  this.unsubscribers.push(
76
76
  infoRegistry.subscribeAll((groupId, data) => {
77
77
  if (this._destroyed) return;
78
+ // Skip empty data from registration notifications — syncGroups()
79
+ // will trigger the real fetch.
80
+ if (Object.keys(data).length === 0) {
81
+ this.requestRender?.();
82
+ return;
83
+ }
78
84
  this.groupData.set(groupId, data);
79
85
  this.groupLoading.set(groupId, false);
80
86
  this.lastGlobalUpdate = Date.now();
@@ -105,25 +111,32 @@ export class InfoOverlay implements Component {
105
111
  */
106
112
  private syncGroups(): void {
107
113
  const allGroups = infoRegistry.getAllGroups();
108
- if (allGroups.length !== this.groups.length) {
114
+ const hadNewGroups = allGroups.length !== this.groups.length;
115
+ if (hadNewGroups) {
109
116
  this.groups = allGroups;
110
117
  this.applyOrder();
118
+ }
111
119
 
112
- // Seed new groups from cache
113
- for (const group of this.groups) {
114
- if (!this.groupData.has(group.id)) {
115
- const cached = infoRegistry.getCachedData(group.id);
116
- if (cached) {
117
- this.groupData.set(group.id, cached);
118
- } else {
119
- this.groupLoading.set(group.id, true);
120
- // Fetch this new group
121
- infoRegistry.getGroupData(group.id).then(() => {
122
- this.groupLoading.set(group.id, false);
123
- }).catch(() => {
124
- this.groupLoading.set(group.id, false);
125
- });
126
- }
120
+ // Ensure every group has real (non-empty) data.
121
+ // Registration notifications inject `{}` to trigger re-sync; we must
122
+ // not treat that as fetched data or the stats render as "—".
123
+ for (const group of this.groups) {
124
+ const existing = this.groupData.get(group.id);
125
+ const hasRealData = existing && Object.keys(existing).length > 0;
126
+ if (!hasRealData) {
127
+ const cached = infoRegistry.getCachedData(group.id);
128
+ if (cached && Object.keys(cached).length > 0) {
129
+ this.groupData.set(group.id, cached);
130
+ } else if (!this.groupLoading.get(group.id)) {
131
+ this.groupLoading.set(group.id, true);
132
+ infoRegistry.getGroupData(group.id).then((data) => {
133
+ this.groupData.set(group.id, data);
134
+ this.groupLoading.set(group.id, false);
135
+ this.lastGlobalUpdate = Date.now();
136
+ this.requestRender?.();
137
+ }).catch(() => {
138
+ this.groupLoading.set(group.id, false);
139
+ });
127
140
  }
128
141
  }
129
142
  }