@@ -22,6 +22,8 @@ export * from './version';
2222export * from './widget' ;
2323export const addLEGOMoveHubControlPanel =
2424 'bluetooth-manager:add-lego-movehub-control-panel' ;
25+ export const connectMoveHub = 'bluetooth-manager:connect-movehub' ;
26+ export const disconnectMoveHub = 'bluetooth-manager:disconnect-movehub' ;
2527export const moveHubServiceUUID = '00001623-1212-efde-1623-785feabcd123' ;
2628export const moveHubCharacteristicUUID = '00001624-1212-efde-1623-785feabcd123' ;
2729export const movehubRegistryItem : IDeviceRegistryItem = {
@@ -81,39 +83,32 @@ const LEGOMoveHubControlPanelPlugin: JupyterFrontEndPlugin<void> = {
8183 const device = result [
8284 result . length - 1
8385 ] as MoveHub ; /* the last added MoveHub device*/
84- /*let isThemeLight: boolean = themeManager.theme;
85- themeManager.themeChanged.connect((sender: any, args: IChangedArgs<string, string | null, string>) => {
86- const theme = args.newValue;
87- console.log("Is the theme light?:", themeManager.isLight(theme));
88- isThemeLight = themeManager.isLight(theme);
89- console.log('Theme is:', theme);
90- });*/
91- const content = new MoveHubPanelWidget ( device , themeManager ) ;
92- content . addClass ( 'jp-movehub-panel-content' ) ;
93- const toolbar = new Toolbar ( ) ;
94- toolbar . addClass ( 'jp-movehub-panel-toolbar' ) ;
95- const main = new MainAreaWidget ( { content, toolbar } ) ;
96- main . addClass ( 'jp-movehub-panel-main' ) ;
97- main . toolbar . addItem (
98- 'connection-status' ,
99- new ConnectionStatusWidget ( device , bluetoothManager )
100- ) ;
101- main . toolbar . addItem (
102- 'select-lego-model' ,
103- new LegoBuildSelectorWidget ( device )
104- ) ;
105- toolbar . addItem ( 'spacer' , Toolbar . createSpacerItem ( ) ) ;
106- main . toolbar . addItem ( 'battery-gauge' , new BatteryWidget ( device , themeManager ) ) ;
107- main . toolbar . addItem (
108- 'device-identifier' ,
109- new DeviceIdentifierWidget ( device )
110- ) ;
111- main . id = 'lego-movehub-control-panel' ;
112- main . title . label = 'LEGO® Move Hub' ;
113- main . title . closable = true ;
114- main . title . icon = LegoBrickIcon ;
115- app . shell . add ( main , 'main' ) ;
116-
86+ const content = new MoveHubPanelWidget ( device , themeManager ) ;
87+ content . addClass ( 'jp-movehub-panel-content' ) ;
88+ const toolbar = new Toolbar ( ) ;
89+ toolbar . addClass ( 'jp-movehub-panel-toolbar' ) ;
90+ const main = new MainAreaWidget ( { content, toolbar } ) ;
91+ main . addClass ( 'jp-movehub-panel-main' ) ;
92+ main . toolbar . addItem (
93+ 'connection-status' ,
94+ new ConnectionStatusWidget ( device , bluetoothManager , app . commands )
95+ ) ;
96+ main . toolbar . addItem (
97+ 'select-lego-model' ,
98+ new LegoBuildSelectorWidget ( device )
99+ ) ;
100+ toolbar . addItem ( 'spacer' , Toolbar . createSpacerItem ( ) ) ;
101+ main . toolbar . addItem ( 'battery-gauge' , new BatteryWidget ( device , themeManager ) ) ;
102+ main . toolbar . addItem (
103+ 'device-identifier' ,
104+ new DeviceIdentifierWidget ( device )
105+ ) ;
106+ main . id = 'lego-movehub-control-panel' ;
107+ main . title . label = 'LEGO® Move Hub' ;
108+ main . title . closable = true ;
109+ main . title . icon = LegoBrickIcon ;
110+ app . shell . add ( main , 'main' ) ;
111+
117112
118113 } else {
119114 throw new Error ( 'The device is not a Move Hub.' ) ;
@@ -123,17 +118,43 @@ const LEGOMoveHubControlPanelPlugin: JupyterFrontEndPlugin<void> = {
123118 label : trans . __ ( 'Open a LEGO® Move Hub Control Panel' )
124119 } ) ;
125120
126- app . contextMenu . addItem ( {
127- command : addLEGOMoveHubControlPanel ,
128- selector :
129- 'jp-tree-item.jp-RunningSessions-item.jp-bluetooth-LEGO-Move-Hub' ,
130- rank : 1
121+ app . commands . addCommand ( disconnectMoveHub , {
122+ execute : args => {
123+ const selectedDevice = bluetoothManager . deviceList . find ( ( device ) => device . native . id === args . deviceID as string ) ;
124+ if ( selectedDevice && selectedDevice instanceof MoveHub ) {
125+ bluetoothManager . disconnectDevice ( selectedDevice ) ;
126+ return selectedDevice ;
127+ } else {
128+ throw new Error ( 'No device provided or device is invalid' ) ;
129+ }
130+ } ,
131+ caption : 'Disconnect MoveHub' ,
132+ label : 'Disconnect MoveHub' ,
133+ isEnabled : ( args ) => {
134+ const selectedDevice = bluetoothManager . deviceList . find ( ( device ) => device . native . id === args . deviceID as string ) ;
135+ if ( selectedDevice && selectedDevice instanceof MoveHub && selectedDevice . deviceInfo . connected ) {
136+ return true ;
137+ } else {
138+ return false ;
139+ }
140+ }
131141 } ) ;
132-
133- app . contextMenu . addItem ( {
134- command : addLEGOMoveHubControlPanel ,
135- selector : 'jp-tree-item.jp-RunningSessions-item.jp-bluetooth-Move-Hub' ,
136- rank : 1
142+
143+ app . commands . addCommand ( connectMoveHub , {
144+ execute : args => {
145+ const newDevice = bluetoothManager . connectDevice ( movehubRegistryItem ) ;
146+ return newDevice ;
147+ } ,
148+ caption : 'Connect MoveHub' ,
149+ label : 'Connect MoveHub' ,
150+ isEnabled : ( args ) => {
151+ const selectedDevice = bluetoothManager . deviceList . find ( ( device ) => device . native . id === args . deviceID as string ) ;
152+ if ( selectedDevice && selectedDevice instanceof MoveHub && selectedDevice . deviceInfo . connected ) {
153+ return false ;
154+ } else {
155+ return true ;
156+ }
157+ }
137158 } ) ;
138159 }
139160} ;
0 commit comments