1
1
import { injectable , inject } from 'inversify' ;
2
2
import { Emitter } from '@theia/core/lib/common/event' ;
3
3
import { ILogger } from '@theia/core/lib/common/logger' ;
4
+ import { CommandService } from '@theia/core/lib/common/command' ;
4
5
import { MessageService } from '@theia/core/lib/common/message-service' ;
5
- import { StorageService } from '@theia/core/lib/browser/storage-service' ;
6
6
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application' ;
7
7
import { RecursiveRequired } from '../../common/types' ;
8
8
import {
@@ -16,8 +16,8 @@ import {
16
16
import { BoardsConfig } from './boards-config' ;
17
17
import { naturalCompare } from '../../common/utils' ;
18
18
import { NotificationCenter } from '../notification-center' ;
19
- import { CommandService } from '@theia/core' ;
20
19
import { ArduinoCommands } from '../arduino-commands' ;
20
+ import { StorageWrapper } from '../storage-wrapper' ;
21
21
22
22
@injectable ( )
23
23
export class BoardsServiceProvider implements FrontendApplicationContribution {
@@ -28,8 +28,6 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
28
28
@inject ( MessageService )
29
29
protected messageService : MessageService ;
30
30
31
- @inject ( StorageService )
32
- protected storageService : StorageService ;
33
31
34
32
@inject ( BoardsService )
35
33
protected boardsService : BoardsService ;
@@ -349,7 +347,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
349
347
return undefined ;
350
348
}
351
349
const key = this . getLastSelectedBoardOnPortKey ( port ) ;
352
- return this . storageService . getData < Board > ( key ) ;
350
+ return this . getData < Board > ( key ) ;
353
351
}
354
352
355
353
protected async saveState ( ) : Promise < void > {
@@ -360,11 +358,11 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
360
358
const { selectedBoard, selectedPort } = this . boardsConfig ;
361
359
if ( selectedBoard && selectedPort ) {
362
360
const key = this . getLastSelectedBoardOnPortKey ( selectedPort ) ;
363
- await this . storageService . setData ( key , selectedBoard ) ;
361
+ await this . setData ( key , selectedBoard ) ;
364
362
}
365
363
await Promise . all ( [
366
- this . storageService . setData ( 'latest-valid-boards-config' , this . latestValidBoardsConfig ) ,
367
- this . storageService . setData ( 'latest-boards-config' , this . latestBoardsConfig )
364
+ this . setData ( 'latest-valid-boards-config' , this . latestValidBoardsConfig ) ,
365
+ this . setData ( 'latest-boards-config' , this . latestBoardsConfig )
368
366
] ) ;
369
367
}
370
368
@@ -374,21 +372,33 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
374
372
}
375
373
376
374
protected async loadState ( ) : Promise < void > {
377
- const storedLatestValidBoardsConfig = await this . storageService . getData < RecursiveRequired < BoardsConfig . Config > > ( 'latest-valid-boards-config' ) ;
375
+ const storedLatestValidBoardsConfig = await this . getData < RecursiveRequired < BoardsConfig . Config > > ( 'latest-valid-boards-config' ) ;
378
376
if ( storedLatestValidBoardsConfig ) {
379
377
this . latestValidBoardsConfig = storedLatestValidBoardsConfig ;
380
378
if ( this . canUploadTo ( this . latestValidBoardsConfig ) ) {
381
379
this . boardsConfig = this . latestValidBoardsConfig ;
382
380
}
383
381
} else {
384
382
// If we could not restore the latest valid config, try to restore something, the board at least.
385
- const storedLatestBoardsConfig = await this . storageService . getData < BoardsConfig . Config | undefined > ( 'latest-boards-config' ) ;
383
+ let storedLatestBoardsConfig = await this . getData < BoardsConfig . Config | undefined > ( 'latest-boards-config' ) ;
384
+ // Try to get from the URL if it was not persisted.
385
+ if ( ! storedLatestBoardsConfig ) {
386
+ storedLatestBoardsConfig = BoardsConfig . Config . getConfig ( new URL ( window . location . href ) ) ;
387
+ }
386
388
if ( storedLatestBoardsConfig ) {
387
389
this . latestBoardsConfig = storedLatestBoardsConfig ;
388
390
this . boardsConfig = this . latestBoardsConfig ;
389
391
}
390
392
}
391
393
}
394
+
395
+ private setData < T > ( key : string , value : T ) : Promise < void > {
396
+ return this . commandService . executeCommand ( StorageWrapper . Commands . SET_DATA . id , key , value ) ;
397
+ }
398
+
399
+ private getData < T > ( key : string ) : Promise < T | undefined > {
400
+ return this . commandService . executeCommand < T > ( StorageWrapper . Commands . GET_DATA . id , key ) ;
401
+ }
392
402
}
393
403
394
404
/**
0 commit comments