Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Show CPU indicator widget only if available
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Apr 6, 2020
1 parent 91d5750 commit 4a1ddd1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/system-monitor-base/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export namespace ResourceUsage {
});
}

/**
* A promise that resolves after the next request.
*/
async refresh(): Promise<void> {
await this._poll.refresh();
await this._poll.tick;
}

/**
* Whether the memory metric is available.
*/
Expand Down
8 changes: 5 additions & 3 deletions packages/system-monitor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ const extension: JupyterFrontEndPlugin<void> = {
}

const model = new ResourceUsage.Model({ refreshRate });
const cpu = CpuView.createCpuView(model, cpuLabel);
await model.refresh();
if (model.cpuAvailable) {
const cpu = CpuView.createCpuView(model, cpuLabel);
topBar.addItem('cpu', cpu);
}
const memory = MemoryView.createMemoryView(model, memoryLabel);

topBar.addItem('cpu', cpu);
topBar.addItem('memory', memory);
},
};
Expand Down

0 comments on commit 4a1ddd1

Please sign in to comment.