Skip to content

Commit

Permalink
Merge pull request #490 from microbit-foundation/main
Browse files Browse the repository at this point in the history
backport
  • Loading branch information
r59q authored May 23, 2024
2 parents 7c350c4 + a90b7f1 commit af5fc44
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 113 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/__tests__/microbit-bluetooth-connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ describe('Microbit Bluetooth interface tests', () => {

test('Request device yields device', async () => {
const device = await MicrobitBluetooth.requestDevice(
'vatav',
TypingUtils.emptyFunction,
'vatav',
);
expect(device).toBeDefined();
});

test('Can connect to requested device', async () => {
const device = await MicrobitBluetooth.requestDevice(
'vatav',
TypingUtils.emptyFunction,
'vatav',
);

const con = await MicrobitBluetooth.createMicrobitBluetooth(
Expand Down
3 changes: 3 additions & 0 deletions src/appInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { ApplicationInsights } from '@microsoft/applicationinsights-web';
import CookieManager from './script/CookieManager';

const load = () => {
if (location.hostname !== "ml-machine.org") {
return;
}
if (CookieManager.getComplianceChoices().analytics) {
appInsights.loadAppInsights();
appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import { DeviceRequestStates } from '../../../script/stores/connectDialogStore';
import Environment from '../../../script/Environment';
import StaticConfiguration from '../../../StaticConfiguration';
import Logger from '../../../script/utils/Logger';
// callbacks
export let deviceState: DeviceRequestStates;
Expand All @@ -38,36 +39,47 @@
let timeouted = writable<boolean>(false);
const connectButtonClicked = () => {
const connectUsingPatternName = () => {
if (!isInputPatternValid()) {
attemptedToPairWithInvalidPattern = true;
return;
}
const name = MBSpecs.Utility.patternToName($patternMatrixState);
attemptToConnect(name);
};
const attemptToConnect = (name?: string) => {
timeoutProgress.set(0);
if (isConnecting) {
// Safeguard to prevent trying to connect multiple times at once
return;
}
isConnecting = true;
let name = MBSpecs.Utility.patternToName($patternMatrixState);
const connectionResult = () => {
if (deviceState == DeviceRequestStates.INPUT) {
return Microbits.assignInput(name);
if (name) {
return Microbits.assignInput(name);
}
return Microbits.assignInputNoName();
} else {
return Microbits.assignOutput(name);
if (name) {
return Microbits.assignOutput(name);
}
return Microbits.assignOutputNoName();
}
};
const connectTimeout = setTimeout(() => {
Environment.isInDevelopment && console.log('Connection timed out');
Logger.log('BluetoothConnectDialog', 'Connection timed-out');
timeouted.set(true);
}, StaticConfiguration.connectTimeoutDuration);
void connectionResult()
.then(didSucceed => {
clearTimeout(connectTimeout);
timeouted.set(false);
Environment.isInDevelopment && console.log('Connection result ', didSucceed);
Logger.log('BluetoothConnectDialog', 'Connection result:', didSucceed);
if (didSucceed) {
onBluetoothConnected();
} else {
Expand All @@ -83,7 +95,7 @@
if (event.code !== 'Enter') {
return;
}
void connectButtonClicked();
void connectUsingPatternName();
}
function updateMatrix(matrix: boolean[]): void {
Expand All @@ -102,6 +114,10 @@
// Resets the bluetooth connection prompt for cancelled device requests
$state.requestDeviceWasCancelled = false;
});
const handleSearchWithoutName = () => {
attemptToConnect();
};
</script>

<main>
Expand All @@ -111,6 +127,14 @@

{#if $state.requestDeviceWasCancelled && !isConnecting}
<p class="text-warning mb-1">{$t('popup.connectMB.bluetooth.cancelledConnection')}</p>
<p class="text-warning mb-1">
{$t('popup.connectMB.bluetooth.cancelledConnection.noNameDescription')}
<span
class="underline text-link cursor-pointer select-none"
on:click={handleSearchWithoutName}>
{$t('popup.connectMB.bluetooth.cancelledConnection.noNameLink')}
</span>
</p>
{/if}
{#if attemptedToPairWithInvalidPattern}
<p class="text-warning mb-1">{$t('popup.connectMB.bluetooth.invalidPattern')}</p>
Expand Down Expand Up @@ -138,7 +162,7 @@
<PatternMatrix matrix={$patternMatrixState} onMatrixChange={updateMatrix} />
</div>
</div>
<StandardButton onClick={connectButtonClicked}
<StandardButton onClick={connectUsingPatternName}
>{$t('popup.connectMB.bluetooth.connect')}</StandardButton>
{/if}
<!-- </div> -->
Expand Down
Loading

0 comments on commit af5fc44

Please sign in to comment.