@@ -27,6 +27,7 @@ import { DevicePool } from '../../device/DevicePool';
2727
2828const NEW_BOOT_UPRATE_FIRMWARE_VERSION = '2.4.5' ;
2929const SESSION_ERROR = 'session not found' ;
30+ const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed' ;
3031
3132const Log = getLogger ( LoggerNames . Core ) ;
3233
@@ -223,6 +224,59 @@ const newTouchUpdateProcess = async (
223224 path : filePath ,
224225 reboot_on_success : rebootOnSuccess ,
225226 } ) ;
227+
228+ if (
229+ response . type === 'Success' &&
230+ ( response as any ) ?. message ?. message === FIRMWARE_UPDATE_CONFIRM
231+ ) {
232+ const timeout = 2 * 60 * 1000 ;
233+ // eslint-disable-next-line no-constant-condition
234+ // Check if timeout exceeded
235+ const startTime = Date . now ( ) ;
236+ const isBleReconnect = DataManager . isBleConnect ( env ) ;
237+ while ( Date . now ( ) - startTime < timeout ) {
238+ try {
239+ if ( isBleReconnect ) {
240+ try {
241+ await device . deviceConnector ?. acquire ( device . originalDescriptor . id , null , true ) ;
242+ const typedCall = device . getCommands ( ) . typedCall . bind ( device . getCommands ( ) ) ;
243+ await Promise . race ( [
244+ typedCall ( 'Initialize' , 'Features' , { } ) ,
245+ new Promise ( ( _ , reject ) => {
246+ setTimeout ( ( ) => {
247+ reject ( ERRORS . TypedError ( HardwareErrorCode . DeviceInitializeFailed ) ) ;
248+ } , 3000 ) ;
249+ } ) ,
250+ ] ) ;
251+ } catch ( e ) {
252+ // ignore error because of device is not connected
253+ Log . log ( 'catch Bluetooth error when device is restarting: ' , e ) ;
254+ }
255+ } else {
256+ const deviceDiff = await device . deviceConnector ?. enumerate ( ) ;
257+ const devicesDescriptor = deviceDiff ?. descriptors ?? [ ] ;
258+ const { deviceList } = await DevicePool . getDevices (
259+ devicesDescriptor ,
260+ device . originalDescriptor . id
261+ ) ;
262+ if ( deviceList . length === 1 ) {
263+ device . updateFromCache ( deviceList [ 0 ] ) ;
264+ await device . acquire ( ) ;
265+ device . commands . disposed = false ;
266+ device . getCommands ( ) . mainId = device . mainId ?? '' ;
267+ }
268+ }
269+ const typedCall = device . getCommands ( ) . typedCall . bind ( device . getCommands ( ) ) ;
270+ await typedCall ( 'GetFeatures' , 'Features' , { } ) ;
271+ DevicePool . resetState ( ) ;
272+ break ;
273+ } catch ( error ) {
274+ console . error ( 'Device reconnect failed: ' , error ) ;
275+ Log . error ( 'Device reconnect failed:' , error ) ;
276+ await wait ( 1000 ) ;
277+ }
278+ }
279+ }
226280 return response ;
227281} ;
228282
0 commit comments