Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/scratch-gui/src/lib/make-toolbox-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const categorySeparator = '<sep gap="36"/>';

const blockSeparator = '<sep gap="36"/>'; // At default scale, about 28px


const motion = function (isInitialSetup, isStage, targetId, colors) {
const stageSelected = ScratchBlocks.ScratchMsgs.translate(
'MOTION_STAGE_SELECTED',
Expand Down Expand Up @@ -513,6 +513,7 @@ const sensing = function (isInitialSetup, isStage, targetId, colors) {
<block id="current" type="sensing_current"/>
<block type="sensing_dayssince2000"/>
${blockSeparator}
<block id="online" type="sensing_online" />
<block type="sensing_username"/>
${categorySeparator}
</category>
Expand Down Expand Up @@ -736,7 +737,7 @@ const myBlocks = function (isInitialSetup, isStage, targetId, colors) {
</category>
`;
};


const xmlOpen = '<xml style="display: none">';
const xmlClose = '</xml>';
Expand Down
7 changes: 7 additions & 0 deletions packages/scratch-gui/src/lib/opcode-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ const messages = defineMessages({
description: 'Label for the loudness monitor when shown on the stage',
id: 'gui.opcodeLabels.loudness'
},
sensing_online: {
defaultMessage: 'online',
description: 'Label for the online status monitor when shown on the stage',
id: 'gui.opcodeLabels.online'
},
sensing_username: {
defaultMessage: 'username',
description: 'Label for the username monitor when shown on the stage',
Expand Down Expand Up @@ -152,6 +157,7 @@ class OpcodeLabels {
// Sensing
sensing_answer: {category: 'sensing'},
sensing_loudness: {category: 'sensing'},
sensing_online: {category: 'sensing'},
sensing_username: {category: 'sensing'},
sensing_current: {category: 'sensing'},
sensing_timer: {category: 'sensing'}
Expand Down Expand Up @@ -208,6 +214,7 @@ class OpcodeLabels {
// Sensing
this._opcodeMap.sensing_answer.labelFn = () => this._translator(messages.sensing_answer);
this._opcodeMap.sensing_loudness.labelFn = () => this._translator(messages.sensing_loudness);
this._opcodeMap.sensing_online.labelFn = () => this._translator(messages.sensing_online);
this._opcodeMap.sensing_username.labelFn = () => this._translator(messages.sensing_username);
this._opcodeMap.sensing_current.labelFn = params => {
switch (params.CURRENTMENU.toLowerCase()) {
Expand Down
14 changes: 14 additions & 0 deletions packages/scratch-vm/src/blocks/scratch3_sensing.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Scratch3SensingBlocks {
sensing_loud: this.isLoud,
sensing_askandwait: this.askAndWait,
sensing_answer: this.getAnswer,
sensing_online: this.getOnline,
sensing_username: this.getUsername,
sensing_userid: () => {} // legacy no-op block
};
Expand All @@ -84,6 +85,9 @@ class Scratch3SensingBlocks {
sensing_loudness: {
getId: () => 'loudness'
},
sensing_online: {
getId: () => 'online'
},
sensing_timer: {
getId: () => 'timer'
},
Expand Down Expand Up @@ -328,6 +332,16 @@ class Scratch3SensingBlocks {
return 0;
}

getOnline (args, util) {
const status = window.navigator.onLine;
if (typeof status === 'boolean') {
return status;
}
// an empty string will evaluate as false in a Boolean context,
// but it allows distinguishing between "false" and "unknown" if needed
return '';
}

getUsername (args, util) {
return util.ioQuery('userData', 'getUsername');
}
Expand Down
Loading