mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
ble/alerts/NoGatt: move gatt message from notifications
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022 The Pybricks Authors
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import React from 'react';
|
||||
import { CreateToast } from '../../i18nToaster';
|
||||
import { I18nId, useI18n } from './i18n';
|
||||
|
||||
const NoGatt: React.VoidFunctionComponent = () => {
|
||||
const i18n = useI18n();
|
||||
return <p>{i18n.translate(I18nId.NoGattMessage)}</p>;
|
||||
};
|
||||
|
||||
export const noGatt: CreateToast = (onAction) => {
|
||||
return {
|
||||
message: <NoGatt />,
|
||||
icon: 'error',
|
||||
intent: Intent.DANGER,
|
||||
onDismiss: () => onAction('dismiss'),
|
||||
};
|
||||
};
|
||||
@@ -15,4 +15,5 @@ export enum I18nId {
|
||||
NoWebBluetoothLinux = 'noWebBluetooth.linux',
|
||||
BluetoothNotAvailableMessage = 'bluetoothNotAvailable.message',
|
||||
BluetoothNotAvailableSuggestion = 'bluetoothNotAvailable.suggestion',
|
||||
NoGattMessage = 'noGatt.message',
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// Copyright (c) 2022 The Pybricks Authors
|
||||
|
||||
import { bluetoothNotAvailable } from './BluetoothNotAvailable';
|
||||
import { noGatt } from './NoGatt';
|
||||
import { noWebBluetooth } from './NoWebBluetooth';
|
||||
|
||||
// gathers all of the alert creation functions for passing up to the top level
|
||||
export default { bluetoothNotAvailable, noWebBluetooth };
|
||||
export default { bluetoothNotAvailable, noGatt, noWebBluetooth };
|
||||
|
||||
@@ -8,5 +8,8 @@
|
||||
"bluetoothNotAvailable": {
|
||||
"message": "No Bluetooth adapter could be found.",
|
||||
"suggestion": "Please connect or enable a Bluetooth Low Energy adapter and restart the browser."
|
||||
},
|
||||
"noGatt": {
|
||||
"message": "The web browser did not give permission to use Bluetooth Low Energy."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,6 +314,9 @@ describe('connect action is dispatched', () => {
|
||||
|
||||
await runConnectUntil(saga, ConnectRunPoint.Connect);
|
||||
|
||||
await expect(saga.take()).resolves.toEqual(
|
||||
alertsShowAlert('ble', 'noGatt'),
|
||||
);
|
||||
await expect(saga.take()).resolves.toEqual(
|
||||
bleDidFailToConnectPybricks({
|
||||
reason: BleDeviceFailToConnectReasonType.NoGatt,
|
||||
|
||||
@@ -149,6 +149,7 @@ function* handleBleConnectPybricks(): Generator {
|
||||
const gatt = device.gatt;
|
||||
|
||||
if (!gatt) {
|
||||
yield* put(alertsShowAlert('ble', 'noGatt'));
|
||||
yield* put(bleDidFailToConnectPybricks({ reason: Reason.NoGatt }));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ export function useI18n(): I18n {
|
||||
export enum I18nId {
|
||||
AppNoUpdateFound = 'app.noUpdateFound',
|
||||
BleUnexpectedError = 'ble.unexpectedError',
|
||||
BleGattPermission = 'ble.gattPermission',
|
||||
BleGattServiceNotFound = 'ble.gattServiceNotFound',
|
||||
EditorFailedToOpenFile = 'editor.failedToOpenFile',
|
||||
EditorFailedToSaveFile = 'editor.failedToSaveFile',
|
||||
|
||||
@@ -61,7 +61,6 @@ function createTestToasterSaga(): { toaster: IToaster; saga: AsyncSaga } {
|
||||
}
|
||||
|
||||
test.each([
|
||||
bleDidFailToConnectPybricks({ reason: BleDeviceFailToConnectReasonType.NoGatt }),
|
||||
bleDidFailToConnectPybricks({
|
||||
reason: BleDeviceFailToConnectReasonType.NoDeviceInfoService,
|
||||
}),
|
||||
@@ -130,6 +129,7 @@ test.each([
|
||||
reason: BleDeviceFailToConnectReasonType.NoBluetooth,
|
||||
}),
|
||||
bleDidFailToConnectPybricks({ reason: BleDeviceFailToConnectReasonType.Canceled }),
|
||||
bleDidFailToConnectPybricks({ reason: BleDeviceFailToConnectReasonType.NoGatt }),
|
||||
bleDidFailToConnectPybricks({
|
||||
reason: BleDeviceFailToConnectReasonType.Unknown,
|
||||
err: { name: 'test', message: 'unknown' },
|
||||
|
||||
@@ -174,10 +174,6 @@ function* showBleDeviceDidFailToConnectError(
|
||||
action: ReturnType<typeof bleDidFailToConnectPybricks>,
|
||||
): Generator {
|
||||
switch (action.reason) {
|
||||
case BleDeviceFailToConnectReasonType.NoGatt:
|
||||
yield* showSingleton(Level.Error, I18nId.BleGattPermission);
|
||||
break;
|
||||
|
||||
case BleDeviceFailToConnectReasonType.NoPybricksService:
|
||||
yield* showSingleton(Level.Error, I18nId.BleGattServiceNotFound, {
|
||||
serviceName: 'Pybricks',
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
"noUpdateFound": "{appName} is already up to date."
|
||||
},
|
||||
"ble": {
|
||||
"gattPermission": "The web browser did not give permission to use Bluetooth Low Energy",
|
||||
"gattServiceNotFound": "Connected to hub but failed to get {serviceName} service.\nEnsure that you are using the most recent firmware.\nIf the problem persists, try removing the \"{hubName}\" device in your OS Bluetooth settings, then try connecting again.",
|
||||
"unexpectedError": "Unexpected error while trying to connect: {errorMessage}"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user