@@ -34,7 +34,15 @@ import GoogleDriveSaverHOC from '../../containers/google-drive-saver-hoc.jsx';
3434import GoogleDriveSaveDialog from '../google-drive-save-dialog/google-drive-save-dialog.jsx' ;
3535import SettingsMenu from './settings-menu.jsx' ;
3636
37- import { openDebugModal , openKoshienTestModal , openConnectionModal } from '../../reducers/modals' ;
37+ import {
38+ openDebugModal ,
39+ openKoshienTestModal ,
40+ openMeshDomainModal ,
41+ openConnectionModal
42+ } from '../../reducers/modals' ;
43+ import {
44+ setDomain as setMeshV2Domain
45+ } from '../../reducers/mesh-v2' ;
3846import { setConnectionModalExtensionId } from '../../reducers/connection-modal' ;
3947import { openBlockDisplayModal } from '../../reducers/block-display' ;
4048import { setPlayer } from '../../reducers/mode' ;
@@ -226,6 +234,7 @@ class MenuBar extends React.Component {
226234 'handleExtensionAdded' ,
227235 'handleClickKoshienEntryForm' ,
228236 'handleMeshV2MenuClick' ,
237+ 'handleMeshDomainClick' ,
229238 'handleClickLearn'
230239 ] ) ;
231240 }
@@ -239,6 +248,13 @@ class MenuBar extends React.Component {
239248 this . props . vm . runtime . on ( 'PERIPHERAL_DISCONNECTED' , this . handleExtensionAdded ) ;
240249 this . props . vm . runtime . on ( 'PERIPHERAL_REQUEST_ERROR' , this . handleExtensionAdded ) ;
241250 }
251+
252+ this . syncMeshV2Domain ( ) ;
253+ }
254+ componentDidUpdate ( prevProps ) {
255+ if ( this . props . extensionLoadCounter !== prevProps . extensionLoadCounter ) {
256+ this . syncMeshV2Domain ( ) ;
257+ }
242258 }
243259 componentWillUnmount ( ) {
244260 document . removeEventListener ( 'keydown' , this . handleKeyPress ) ;
@@ -251,6 +267,16 @@ class MenuBar extends React.Component {
251267 this . props . vm . runtime . off ( 'PERIPHERAL_REQUEST_ERROR' , this . handleExtensionAdded ) ;
252268 }
253269 }
270+ syncMeshV2Domain ( ) {
271+ const extension = this . props . vm && this . props . vm . runtime &&
272+ this . props . vm . runtime . peripheralExtensions &&
273+ this . props . vm . runtime . peripheralExtensions . meshV2 ;
274+ if ( extension && extension . domain !== this . props . meshV2Domain ) {
275+ if ( this . props . onSetMeshV2Domain ) {
276+ this . props . onSetMeshV2Domain ( extension . domain ) ;
277+ }
278+ }
279+ }
254280 handleExtensionAdded ( ) {
255281 // Dispatch Redux action to trigger re-render
256282 if ( this . props . onExtensionLoaded ) {
@@ -259,7 +285,7 @@ class MenuBar extends React.Component {
259285 }
260286 getMeshV2Status ( ) {
261287 const vm = this . props . vm ;
262-
288+
263289 if ( ! vm ) return { loaded : false } ;
264290
265291 // In Smalruby 3 / Scratch 3, extensionManager is directly on the vm instance
@@ -269,7 +295,7 @@ class MenuBar extends React.Component {
269295 }
270296
271297 const isLoaded = extensionManager . isExtensionLoaded ( 'meshV2' ) ;
272-
298+
273299 if ( ! isLoaded ) {
274300 return { loaded : false } ;
275301 }
@@ -303,6 +329,22 @@ class MenuBar extends React.Component {
303329 // Open connection modal
304330 this . props . onOpenConnectionModal ( 'meshV2' ) ;
305331 }
332+ handleMeshDomainClick ( ) {
333+ // Close the Mesh V2 menu
334+ this . props . onRequestCloseMeshV2 ( ) ;
335+
336+ const extension = this . props . vm && this . props . vm . runtime &&
337+ this . props . vm . runtime . peripheralExtensions &&
338+ this . props . vm . runtime . peripheralExtensions . meshV2 ;
339+ if ( extension && ( extension . connectionState === 'connected' || extension . connectionState === 'connecting' ) ) {
340+ alert ( this . props . intl . formatMessage ( { // eslint-disable-line no-alert
341+ id : 'mesh.domainConnectedAlert' ,
342+ default : 'Mesh V2 is connected. To change the domain, please disconnect first.'
343+ } ) ) ;
344+ return ;
345+ }
346+ this . props . onOpenMeshDomainModal ( ) ;
347+ }
306348 handleClickNew ( ) {
307349 // if the project is dirty, and user owns the project, we will autosave.
308350 // but if they are not logged in and can't save, user should consider
@@ -959,9 +1001,28 @@ class MenuBar extends React.Component {
9591001 place = { this . props . isRtl ? 'left' : 'right' }
9601002 onRequestClose = { this . props . onRequestCloseMeshV2 }
9611003 >
962- < MenuItem onClick = { this . handleMeshV2MenuClick } >
963- { meshV2Status . message }
1004+ < MenuItem onClick = { this . handleMeshDomainClick } >
1005+ < FormattedMessage
1006+ defaultMessage = "Domain: {domain}"
1007+ description = "Label for Mesh V2 domain"
1008+ id = "mesh.domain"
1009+ values = { {
1010+ domain : (
1011+ < span className = { styles . meshV2Domain } >
1012+ { this . props . meshV2Domain || this . props . intl . formatMessage ( {
1013+ id : 'mesh.domainNotSet' ,
1014+ defaultMessage : 'Not set'
1015+ } ) }
1016+ </ span >
1017+ )
1018+ } }
1019+ />
9641020 </ MenuItem >
1021+ < MenuSection >
1022+ < MenuItem onClick = { this . handleMeshV2MenuClick } >
1023+ { meshV2Status . message }
1024+ </ MenuItem >
1025+ </ MenuSection >
9651026 </ MenuBarMenu >
9661027 </ div >
9671028 ) ;
@@ -1342,6 +1403,7 @@ MenuBar.propTypes = {
13421403 locale : PropTypes . string . isRequired ,
13431404 loginMenuOpen : PropTypes . bool ,
13441405 logo : PropTypes . string ,
1406+ meshV2Domain : PropTypes . string ,
13451407 meshV2MenuOpen : PropTypes . bool ,
13461408 mode1920 : PropTypes . bool ,
13471409 mode1990 : PropTypes . bool ,
@@ -1376,6 +1438,7 @@ MenuBar.propTypes = {
13761438 onOpenRegistration : PropTypes . func ,
13771439 onOpenBlockDisplayModal : PropTypes . func ,
13781440 onOpenConnectionModal : PropTypes . func ,
1441+ onOpenMeshDomainModal : PropTypes . func ,
13791442 onOpenDebugModal : PropTypes . func ,
13801443 onOpenKoshienTestModal : PropTypes . func ,
13811444 onProjectTelemetryEvent : PropTypes . func ,
@@ -1399,6 +1462,7 @@ MenuBar.propTypes = {
13991462 onStartSavingToGoogleDrive : PropTypes . func ,
14001463 onSaveDirectlyToGoogleDrive : PropTypes . func ,
14011464 onSetAiSaveStatus : PropTypes . func ,
1465+ onSetMeshV2Domain : PropTypes . func ,
14021466 onClearAiSaveStatus : PropTypes . func ,
14031467 onStartSelectingUrlLoad : PropTypes . func ,
14041468 projectFilename : PropTypes . string ,
@@ -1431,6 +1495,7 @@ const mapStateToProps = (state, ownProps) => {
14311495 fileMenuOpen : fileMenuOpen ( state ) ,
14321496 editMenuOpen : editMenuOpen ( state ) ,
14331497 koshienMenuOpen : koshienMenuOpen ( state ) ,
1498+ meshV2Domain : state . scratchGui . meshV2 ? state . scratchGui . meshV2 . domain : null ,
14341499 meshV2MenuOpen : meshV2MenuOpen ( state ) ,
14351500 extensionLoadCounter : state . scratchGui . koshienFile . extensionLoadCounter ,
14361501 aiSaveStatus : state . scratchGui . koshienFile . aiSaveStatus ,
@@ -1465,6 +1530,7 @@ const mapDispatchToProps = dispatch => ({
14651530 dispatch ( setConnectionModalExtensionId ( id ) ) ;
14661531 dispatch ( openConnectionModal ( ) ) ;
14671532 } ,
1533+ onOpenMeshDomainModal : ( ) => dispatch ( openMeshDomainModal ( ) ) ,
14681534 onOpenBlockDisplayModal : ( ) => dispatch ( openBlockDisplayModal ( ) ) ,
14691535 onOpenKoshienTestModal : ( ) => dispatch ( openKoshienTestModal ( ) ) ,
14701536 onClickAccount : ( ) => dispatch ( openAccountMenu ( ) ) ,
@@ -1493,6 +1559,7 @@ const mapDispatchToProps = dispatch => ({
14931559 onClickSave : ( ) => dispatch ( manualUpdateProject ( ) ) ,
14941560 onClickSaveAsCopy : ( ) => dispatch ( saveProjectAsCopy ( ) ) ,
14951561 onExtensionLoaded : ( ) => dispatch ( incrementExtensionLoad ( ) ) ,
1562+ onSetMeshV2Domain : domain => dispatch ( setMeshV2Domain ( domain ) ) ,
14961563 onSetAiSaveStatus : status => dispatch ( setAiSaveStatus ( status ) ) ,
14971564 onClearAiSaveStatus : ( ) => dispatch ( clearAiSaveStatus ( ) ) ,
14981565 onSeeCommunity : ( ) => dispatch ( setPlayer ( true ) ) ,
0 commit comments