@@ -12,7 +12,6 @@ import {
12
12
Sketch ,
13
13
LibraryService ,
14
14
ArduinoDaemon ,
15
- SketchesError ,
16
15
} from '../common/protocol' ;
17
16
import { Mutex } from 'async-mutex' ;
18
17
import {
@@ -21,7 +20,6 @@ import {
21
20
MenuModelRegistry ,
22
21
ILogger ,
23
22
DisposableCollection ,
24
- ApplicationError ,
25
23
} from '@theia/core' ;
26
24
import {
27
25
Dialog ,
@@ -47,12 +45,7 @@ import {
47
45
} from '@theia/core/lib/common/command' ;
48
46
import { MessageService } from '@theia/core/lib/common/message-service' ;
49
47
import URI from '@theia/core/lib/common/uri' ;
50
- import {
51
- EditorCommands ,
52
- EditorMainMenu ,
53
- EditorManager ,
54
- EditorOpenerOptions ,
55
- } from '@theia/editor/lib/browser' ;
48
+ import { EditorCommands , EditorMainMenu } from '@theia/editor/lib/browser' ;
56
49
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu' ;
57
50
import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution' ;
58
51
import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution' ;
@@ -78,8 +71,7 @@ import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
78
71
import { IDEUpdater } from '../common/protocol/ide-updater' ;
79
72
import { FileSystemFrontendContribution } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution' ;
80
73
import { HostedPluginEvents } from './hosted-plugin-events' ;
81
- import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service' ;
82
- import { Notifications } from './contributions/notifications' ;
74
+ import { OpenSketchFiles } from './contributions/open-sketch-files' ;
83
75
84
76
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages' ;
85
77
export const SKIP_IDE_VERSION = 'skipIDEVersion' ;
@@ -108,9 +100,6 @@ export class ArduinoFrontendContribution
108
100
@inject ( BoardsServiceProvider )
109
101
private readonly boardsServiceClientImpl : BoardsServiceProvider ;
110
102
111
- @inject ( EditorManager )
112
- private readonly editorManager : EditorManager ;
113
-
114
103
@inject ( FileService )
115
104
private readonly fileService : FileService ;
116
105
@@ -159,12 +148,6 @@ export class ArduinoFrontendContribution
159
148
@inject ( ArduinoDaemon )
160
149
private readonly daemon : ArduinoDaemon ;
161
150
162
- @inject ( WorkspaceService )
163
- private readonly workspaceService : WorkspaceService ;
164
-
165
- protected invalidConfigPopup :
166
- | Promise < void | 'No' | 'Yes' | undefined >
167
- | undefined ;
168
151
protected toDisposeOnStop = new DisposableCollection ( ) ;
169
152
170
153
@postConstruct ( )
@@ -247,9 +230,14 @@ export class ArduinoFrontendContribution
247
230
sketch . uri
248
231
) ;
249
232
if ( Sketch . isInSketch ( resource , reloadedSketch ) ) {
250
- this . ensureOpened ( resource . toString ( ) , true , {
251
- mode : 'open' ,
252
- } ) ;
233
+ this . commandRegistry . executeCommand (
234
+ OpenSketchFiles . Commands . ENSURE_OPENED . id ,
235
+ resource . toString ( ) ,
236
+ true ,
237
+ {
238
+ mode : 'open' ,
239
+ }
240
+ ) ;
253
241
}
254
242
}
255
243
}
@@ -321,6 +309,11 @@ export class ArduinoFrontendContribution
321
309
}
322
310
}
323
311
} ) ;
312
+
313
+ // TODO: Verify this! If true IDE2 can start ~100ms faster.
314
+ // If the preferences is resolved, then the `ready` call will happen in the same tick
315
+ // and will do a `send_sync` request to the electron main to get the current window.
316
+ // Consider moving after app `ready`.
324
317
this . arduinoPreferences . ready . then ( ( ) => {
325
318
const webContents = remote . getCurrentWebContents ( ) ;
326
319
const zoomLevel = this . arduinoPreferences . get ( 'arduino.window.zoomLevel' ) ;
@@ -462,11 +455,6 @@ export class ArduinoFrontendContribution
462
455
execute : ( ) => this . editorMode . toggleCompileForDebug ( ) ,
463
456
isToggled : ( ) => this . editorMode . compileForDebug ,
464
457
} ) ;
465
- registry . registerCommand ( ArduinoCommands . OPEN_SKETCH_FILES , {
466
- execute : async ( uri : URI ) => {
467
- this . openSketchFiles ( uri ) ;
468
- } ,
469
- } ) ;
470
458
registry . registerCommand ( ArduinoCommands . OPEN_BOARDS_DIALOG , {
471
459
execute : async ( query ?: string | undefined ) => {
472
460
const boardsConfig = await this . boardsConfigDialog . open ( query ) ;
@@ -518,104 +506,6 @@ export class ArduinoFrontendContribution
518
506
} ) ;
519
507
}
520
508
521
- protected async openSketchFiles ( uri : URI ) : Promise < void > {
522
- try {
523
- const sketch = await this . sketchService . loadSketch ( uri . toString ( ) ) ;
524
- const { mainFileUri, rootFolderFileUris } = sketch ;
525
- for ( const uri of [ mainFileUri , ...rootFolderFileUris ] ) {
526
- await this . ensureOpened ( uri ) ;
527
- }
528
- if ( mainFileUri . endsWith ( '.pde' ) ) {
529
- const message = nls . localize (
530
- 'arduino/common/oldFormat' ,
531
- "The '{0}' still uses the old `.pde` format. Do you want to switch to the new `.ino` extension?" ,
532
- sketch . name
533
- ) ;
534
- const yes = nls . localize ( 'vscode/extensionsUtils/yes' , 'Yes' ) ;
535
- this . messageService
536
- . info ( message , nls . localize ( 'arduino/common/later' , 'Later' ) , yes )
537
- . then ( async ( answer ) => {
538
- if ( answer === yes ) {
539
- this . commandRegistry . executeCommand (
540
- SaveAsSketch . Commands . SAVE_AS_SKETCH . id ,
541
- {
542
- execOnlyIfTemp : false ,
543
- openAfterMove : true ,
544
- wipeOriginal : false ,
545
- }
546
- ) ;
547
- }
548
- } ) ;
549
- }
550
- } catch ( err ) {
551
- if ( SketchesError . NotFound . is ( err ) ) {
552
- this . openFallbackSketch ( err ) ;
553
- } else {
554
- console . error ( err ) ;
555
- const message =
556
- err instanceof Error
557
- ? err . message
558
- : typeof err === 'string'
559
- ? err
560
- : String ( err ) ;
561
- this . messageService . error ( message ) ;
562
- }
563
- }
564
- }
565
-
566
- private openFallbackSketch (
567
- err : ApplicationError <
568
- number ,
569
- {
570
- uri : string ;
571
- }
572
- >
573
- ) {
574
- this . sketchService . createNewSketch ( ) . then ( ( sketch ) => {
575
- this . workspaceService . open (
576
- new URI ( sketch . uri ) ,
577
- Object . assign (
578
- {
579
- preserveWindow : true ,
580
- } ,
581
- {
582
- tasks : [
583
- {
584
- command : Notifications . Commands . NOTIFY . id ,
585
- args : [
586
- {
587
- type : 'error' ,
588
- message : err . message ,
589
- } ,
590
- ] ,
591
- } ,
592
- ] ,
593
- }
594
- )
595
- ) ;
596
- } ) ;
597
- }
598
-
599
- protected async ensureOpened (
600
- uri : string ,
601
- forceOpen = false ,
602
- options ?: EditorOpenerOptions | undefined
603
- ) : Promise < unknown > {
604
- const widget = this . editorManager . all . find (
605
- ( widget ) => widget . editor . uri . toString ( ) === uri
606
- ) ;
607
- if ( ! widget || forceOpen ) {
608
- return this . editorManager . open (
609
- new URI ( uri ) ,
610
- options ?? {
611
- mode : 'reveal' ,
612
- preview : false ,
613
- counter : 0 ,
614
- }
615
- ) ;
616
- }
617
- }
618
-
619
509
registerColors ( colors : ColorRegistry ) : void {
620
510
colors . register (
621
511
{
0 commit comments