1
1
import { NativeImage } from '@theia/core/electron-shared/electron' ;
2
+ import { ThemeService } from '@theia/core/lib/browser/theming' ;
2
3
import {
3
4
Disposable ,
4
5
DisposableCollection ,
@@ -9,7 +10,11 @@ import { inject, injectable } from '@theia/core/shared/inversify';
9
10
import { SketchesError } from '../../common/protocol' ;
10
11
import { ConfigServiceClient } from '../config/config-service-client' ;
11
12
import { ArduinoMenus } from '../menu/arduino-menus' ;
12
- import { NativeImageCache } from '../native-image-cache' ;
13
+ import {
14
+ isThemeNativeImage ,
15
+ NativeImageCache ,
16
+ ThemeNativeImage ,
17
+ } from '../native-image-cache' ;
13
18
import { NotificationCenter } from '../notification-center' ;
14
19
import { CloudSketchContribution } from './cloud-contribution' ;
15
20
import { CommandRegistry , MenuModelRegistry , Sketch } from './contribution' ;
@@ -27,21 +32,34 @@ export class OpenRecentSketch extends CloudSketchContribution {
27
32
private readonly imageCache : NativeImageCache ;
28
33
@inject ( ConfigServiceClient )
29
34
private readonly configServiceClient : ConfigServiceClient ;
35
+ @inject ( ThemeService )
36
+ private readonly themeService : ThemeService ;
30
37
31
- private readonly toDispose = new DisposableCollection ( ) ;
32
- private cloudImage : NativeImage | undefined ;
38
+ private readonly toDisposeBeforeRegister = new DisposableCollection ( ) ;
39
+ private readonly toDispose = new DisposableCollection (
40
+ this . toDisposeBeforeRegister
41
+ ) ;
42
+ private cloudImage : NativeImage | ThemeNativeImage ;
33
43
34
44
override onStart ( ) : void {
35
- this . notificationCenter . onRecentSketchesDidChange ( ( { sketches } ) =>
36
- this . refreshMenu ( sketches )
37
- ) ;
38
- this . imageCache
39
- . getImage ( 'cloud' )
40
- . then ( ( image ) => ( this . cloudImage = image ) ) ;
45
+ this . toDispose . pushAll ( [
46
+ this . notificationCenter . onRecentSketchesDidChange ( ( { sketches } ) =>
47
+ this . refreshMenu ( sketches )
48
+ ) ,
49
+ this . themeService . onDidColorThemeChange ( ( ) => this . update ( ) ) ,
50
+ ] ) ;
51
+ }
52
+
53
+ onStop ( ) : void {
54
+ this . toDispose . dispose ( ) ;
41
55
}
42
56
43
57
override async onReady ( ) : Promise < void > {
44
58
this . update ( ) ;
59
+ this . imageCache . getImage ( 'cloud' ) . then ( ( image ) => {
60
+ this . cloudImage = image ;
61
+ this . update ( ) ;
62
+ } ) ;
45
63
}
46
64
47
65
override registerMenus ( registry : MenuModelRegistry ) : void {
@@ -65,7 +83,7 @@ export class OpenRecentSketch extends CloudSketchContribution {
65
83
66
84
private register ( sketches : Sketch [ ] ) : void {
67
85
const order = 0 ;
68
- this . toDispose . dispose ( ) ;
86
+ this . toDisposeBeforeRegister . dispose ( ) ;
69
87
for ( const sketch of sketches ) {
70
88
const { uri } = sketch ;
71
89
const command = { id : `arduino-open-recent--${ uri } ` } ;
@@ -95,7 +113,7 @@ export class OpenRecentSketch extends CloudSketchContribution {
95
113
ArduinoMenus . FILE__OPEN_RECENT_SUBMENU ,
96
114
menuAction
97
115
) ;
98
- this . toDispose . pushAll ( [
116
+ this . toDisposeBeforeRegister . pushAll ( [
99
117
new DisposableCollection (
100
118
Disposable . create ( ( ) =>
101
119
this . commandRegistry . unregisterCommand ( command )
@@ -109,13 +127,23 @@ export class OpenRecentSketch extends CloudSketchContribution {
109
127
}
110
128
111
129
private assignImage ( sketch : Sketch , menuAction : MenuAction ) : MenuAction {
112
- if ( this . cloudImage ) {
130
+ const image = this . nativeImageForTheme ( ) ;
131
+ if ( image ) {
113
132
const dataDirUri = this . configServiceClient . tryGetDataDirUri ( ) ;
114
133
const isCloud = this . createFeatures . isCloud ( sketch , dataDirUri ) ;
115
134
if ( isCloud ) {
116
- Object . assign ( menuAction , { nativeImage : this . cloudImage } ) ;
135
+ Object . assign ( menuAction , { nativeImage : image } ) ;
117
136
}
118
137
}
119
138
return menuAction ;
120
139
}
140
+
141
+ private nativeImageForTheme ( ) : NativeImage | undefined {
142
+ const image = this . cloudImage ;
143
+ if ( isThemeNativeImage ( image ) ) {
144
+ const themeType = this . themeService . getCurrentTheme ( ) . type ;
145
+ return themeType === 'light' ? image . light : image . dark ;
146
+ }
147
+ return image ;
148
+ }
121
149
}
0 commit comments