5
5
import { INotebookTracker } from '@jupyterlab/notebook' ;
6
6
import { LabIcon } from '@jupyterlab/ui-components' ;
7
7
import { ICommandPalette } from '@jupyterlab/apputils' ;
8
+ import { nullTranslator } from '@jupyterlab/translation' ;
8
9
import { KernelUsagePanel } from './panel' ;
9
10
import tachometer from '../style/tachometer.svg' ;
10
11
@@ -24,32 +25,34 @@ namespace CommandIDs {
24
25
const extension : JupyterFrontEndPlugin < void > = {
25
26
id : '@jupyter-server/resource-usage:memory-status-item' ,
26
27
autoStart : true ,
27
- requires : [ IStatusBar , ITranslator , ICommandPalette , INotebookTracker ] ,
28
28
activate : (
29
29
app : JupyterFrontEnd ,
30
- statusBar : IStatusBar ,
31
- translator : ITranslator ,
32
- palette : ICommandPalette ,
33
- notebookTracker : INotebookTracker
30
+ statusBar : IStatusBar | null ,
31
+ translator : ITranslator | null ,
32
+ palette : ICommandPalette | null ,
33
+ notebookTracker : INotebookTracker | null
34
34
) => {
35
+ translator = translator || nullTranslator ;
35
36
const trans = translator . load ( 'jupyterlab' ) ;
36
37
const item = new MemoryUsage ( translator ) ;
37
38
38
- statusBar . registerStatusItem ( extension . id , {
39
- item,
40
- align : 'left' ,
41
- rank : 2 ,
42
- isActive : ( ) => item . model . metricsAvailable ,
43
- activeStateChanged : item . model . stateChanged ,
44
- } ) ;
39
+ if ( statusBar ) {
40
+ statusBar . registerStatusItem ( extension . id , {
41
+ item,
42
+ align : 'left' ,
43
+ rank : 2 ,
44
+ isActive : ( ) => item . model . metricsAvailable ,
45
+ activeStateChanged : item . model . stateChanged ,
46
+ } ) ;
47
+ }
45
48
46
49
const { commands, shell } = app ;
47
50
const category = 'Kernel Resource' ;
48
51
49
52
let panel : KernelUsagePanel | null = null ;
50
53
51
54
function createPanel ( ) {
52
- if ( ! panel || panel . isDisposed ) {
55
+ if ( ( ! panel || panel . isDisposed ) && notebookTracker ) {
53
56
panel = new KernelUsagePanel ( {
54
57
widgetAdded : notebookTracker . widgetAdded ,
55
58
currentNotebookChanged : notebookTracker . currentChanged ,
@@ -68,7 +71,9 @@ const extension: JupyterFrontEndPlugin<void> = {
68
71
execute : createPanel ,
69
72
} ) ;
70
73
71
- palette . addItem ( { command : CommandIDs . getKernelUsage , category } ) ;
74
+ if ( palette ) {
75
+ palette . addItem ( { command : CommandIDs . getKernelUsage , category } ) ;
76
+ }
72
77
73
78
createPanel ( ) ;
74
79
} ,
0 commit comments