Skip to content

Commit 031d2b7

Browse files
committed
feat: add sensing_online
1 parent 069c6cc commit 031d2b7

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

packages/scratch-gui/src/lib/make-toolbox-xml.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const categorySeparator = '<sep gap="36"/>';
55

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

8-
8+
99
const motion = function (isInitialSetup, isStage, targetId, colors) {
1010
const stageSelected = ScratchBlocks.ScratchMsgs.translate(
1111
'MOTION_STAGE_SELECTED',
@@ -513,6 +513,7 @@ const sensing = function (isInitialSetup, isStage, targetId, colors) {
513513
<block id="current" type="sensing_current"/>
514514
<block type="sensing_dayssince2000"/>
515515
${blockSeparator}
516+
<block id="online" type="sensing_online" />
516517
<block type="sensing_username"/>
517518
${categorySeparator}
518519
</category>
@@ -736,7 +737,7 @@ const myBlocks = function (isInitialSetup, isStage, targetId, colors) {
736737
</category>
737738
`;
738739
};
739-
740+
740741

741742
const xmlOpen = '<xml style="display: none">';
742743
const xmlClose = '</xml>';

packages/scratch-gui/src/lib/opcode-labels.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ const messages = defineMessages({
6868
description: 'Label for the loudness monitor when shown on the stage',
6969
id: 'gui.opcodeLabels.loudness'
7070
},
71+
sensing_online: {
72+
defaultMessage: 'online',
73+
description: 'Label for the online status monitor when shown on the stage',
74+
id: 'gui.opcodeLabels.online'
75+
},
7176
sensing_username: {
7277
defaultMessage: 'username',
7378
description: 'Label for the username monitor when shown on the stage',
@@ -152,6 +157,7 @@ class OpcodeLabels {
152157
// Sensing
153158
sensing_answer: {category: 'sensing'},
154159
sensing_loudness: {category: 'sensing'},
160+
sensing_online: {category: 'sensing'},
155161
sensing_username: {category: 'sensing'},
156162
sensing_current: {category: 'sensing'},
157163
sensing_timer: {category: 'sensing'}
@@ -208,6 +214,7 @@ class OpcodeLabels {
208214
// Sensing
209215
this._opcodeMap.sensing_answer.labelFn = () => this._translator(messages.sensing_answer);
210216
this._opcodeMap.sensing_loudness.labelFn = () => this._translator(messages.sensing_loudness);
217+
this._opcodeMap.sensing_online.labelFn = () => this._translator(messages.sensing_online);
211218
this._opcodeMap.sensing_username.labelFn = () => this._translator(messages.sensing_username);
212219
this._opcodeMap.sensing_current.labelFn = params => {
213220
switch (params.CURRENTMENU.toLowerCase()) {

packages/scratch-vm/src/blocks/scratch3_sensing.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class Scratch3SensingBlocks {
7171
sensing_loud: this.isLoud,
7272
sensing_askandwait: this.askAndWait,
7373
sensing_answer: this.getAnswer,
74+
sensing_online: this.getOnline,
7475
sensing_username: this.getUsername,
7576
sensing_userid: () => {} // legacy no-op block
7677
};
@@ -84,6 +85,9 @@ class Scratch3SensingBlocks {
8485
sensing_loudness: {
8586
getId: () => 'loudness'
8687
},
88+
sensing_online: {
89+
getId: () => 'online'
90+
},
8791
sensing_timer: {
8892
getId: () => 'timer'
8993
},
@@ -328,6 +332,16 @@ class Scratch3SensingBlocks {
328332
return 0;
329333
}
330334

335+
getOnline (args, util) {
336+
const status = window.navigator.onLine;
337+
if (typeof status === 'boolean') {
338+
return status;
339+
}
340+
// an empty string will evaluate as false in a Boolean context,
341+
// but it allows distinguishing between "false" and "unknown" if needed
342+
return '';
343+
}
344+
331345
getUsername (args, util) {
332346
return util.ioQuery('userData', 'getUsername');
333347
}

0 commit comments

Comments
 (0)