11import { injectable , inject } from 'inversify' ;
22import { Emitter } from '@theia/core/lib/common/event' ;
33import { ILogger } from '@theia/core/lib/common/logger' ;
4+ import { CommandService } from '@theia/core/lib/common/command' ;
45import { MessageService } from '@theia/core/lib/common/message-service' ;
5- import { StorageService } from '@theia/core/lib/browser/storage-service' ;
66import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application' ;
77import { RecursiveRequired } from '../../common/types' ;
88import {
@@ -16,8 +16,8 @@ import {
1616import { BoardsConfig } from './boards-config' ;
1717import { naturalCompare } from '../../common/utils' ;
1818import { NotificationCenter } from '../notification-center' ;
19- import { CommandService } from '@theia/core' ;
2019import { ArduinoCommands } from '../arduino-commands' ;
20+ import { StorageWrapper } from '../storage-wrapper' ;
2121
2222@injectable ( )
2323export class BoardsServiceProvider implements FrontendApplicationContribution {
@@ -28,8 +28,6 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
2828 @inject ( MessageService )
2929 protected messageService : MessageService ;
3030
31- @inject ( StorageService )
32- protected storageService : StorageService ;
3331
3432 @inject ( BoardsService )
3533 protected boardsService : BoardsService ;
@@ -349,7 +347,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
349347 return undefined ;
350348 }
351349 const key = this . getLastSelectedBoardOnPortKey ( port ) ;
352- return this . storageService . getData < Board > ( key ) ;
350+ return this . getData < Board > ( key ) ;
353351 }
354352
355353 protected async saveState ( ) : Promise < void > {
@@ -360,11 +358,11 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
360358 const { selectedBoard, selectedPort } = this . boardsConfig ;
361359 if ( selectedBoard && selectedPort ) {
362360 const key = this . getLastSelectedBoardOnPortKey ( selectedPort ) ;
363- await this . storageService . setData ( key , selectedBoard ) ;
361+ await this . setData ( key , selectedBoard ) ;
364362 }
365363 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 )
368366 ] ) ;
369367 }
370368
@@ -374,21 +372,33 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
374372 }
375373
376374 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' ) ;
378376 if ( storedLatestValidBoardsConfig ) {
379377 this . latestValidBoardsConfig = storedLatestValidBoardsConfig ;
380378 if ( this . canUploadTo ( this . latestValidBoardsConfig ) ) {
381379 this . boardsConfig = this . latestValidBoardsConfig ;
382380 }
383381 } else {
384382 // 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+ }
386388 if ( storedLatestBoardsConfig ) {
387389 this . latestBoardsConfig = storedLatestBoardsConfig ;
388390 this . boardsConfig = this . latestBoardsConfig ;
389391 }
390392 }
391393 }
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+ }
392402}
393403
394404/**
0 commit comments