@pi-unipi/info-screen 0.1.18 → 0.1.19
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/index.ts +42 -13
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -32,27 +32,56 @@ export default function (pi: ExtensionAPI) {
|
|
|
32
32
|
// Start load tracking
|
|
33
33
|
startLoadTracking();
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// Debounced MODULE_READY handling — batch module announcements
|
|
36
|
+
// to prevent layout shift from rapid per-module cache invalidation.
|
|
37
|
+
let moduleReadyBatch: Array<{ name: string; version: string; tools?: string[]; loadTimeMs?: number }> = [];
|
|
38
|
+
let moduleReadyTimer: ReturnType<typeof setTimeout> | null = null;
|
|
39
|
+
const MODULE_READY_DEBOUNCE_MS = 150;
|
|
40
|
+
|
|
41
|
+
function flushModuleReadyBatch(): void {
|
|
42
|
+
const batch = moduleReadyBatch;
|
|
43
|
+
moduleReadyBatch = [];
|
|
44
|
+
moduleReadyTimer = null;
|
|
45
|
+
|
|
46
|
+
if (batch.length === 0) return;
|
|
47
|
+
|
|
48
|
+
// Track all modules and tools
|
|
49
|
+
let hasTools = false;
|
|
50
|
+
for (const event of batch) {
|
|
38
51
|
trackModule(event.name, event.version || "unknown");
|
|
39
52
|
recordLoadTime(event.name, "module", event.loadTimeMs);
|
|
40
|
-
|
|
41
|
-
// Invalidate overview so next fetch picks up new module list
|
|
42
|
-
infoRegistry.invalidateCache("overview");
|
|
43
|
-
|
|
44
|
-
// Trigger background refresh of overview — subscribers will re-render
|
|
45
|
-
infoRegistry.getGroupData("overview");
|
|
46
|
-
|
|
47
53
|
if (event.tools && Array.isArray(event.tools)) {
|
|
48
54
|
for (const tool of event.tools) {
|
|
49
55
|
trackTool(tool, event.name);
|
|
50
56
|
}
|
|
51
|
-
|
|
52
|
-
infoRegistry.invalidateCache("tools");
|
|
53
|
-
infoRegistry.getGroupData("tools");
|
|
57
|
+
hasTools = true;
|
|
54
58
|
}
|
|
55
59
|
}
|
|
60
|
+
|
|
61
|
+
// Single cache invalidation for all modules
|
|
62
|
+
infoRegistry.invalidateCache("overview");
|
|
63
|
+
infoRegistry.getGroupData("overview");
|
|
64
|
+
|
|
65
|
+
if (hasTools) {
|
|
66
|
+
infoRegistry.invalidateCache("tools");
|
|
67
|
+
infoRegistry.getGroupData("tools");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Listen for module announcements — track and trigger reactive updates
|
|
72
|
+
pi.events.on(UNIPI_EVENTS.MODULE_READY, (event: any) => {
|
|
73
|
+
if (event.name && event.name !== MODULES.INFO_SCREEN) {
|
|
74
|
+
moduleReadyBatch.push({
|
|
75
|
+
name: event.name,
|
|
76
|
+
version: event.version,
|
|
77
|
+
tools: event.tools,
|
|
78
|
+
loadTimeMs: event.loadTimeMs,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Debounce: wait for more modules to arrive, then flush once
|
|
82
|
+
if (moduleReadyTimer) clearTimeout(moduleReadyTimer);
|
|
83
|
+
moduleReadyTimer = setTimeout(flushModuleReadyBatch, MODULE_READY_DEBOUNCE_MS);
|
|
84
|
+
}
|
|
56
85
|
});
|
|
57
86
|
|
|
58
87
|
pi.events.on(UNIPI_EVENTS.INFO_GROUP_REGISTERED, (_event: any) => {
|