11import { NativeImage } from '@theia/core/electron-shared/electron' ;
2+ import { ThemeService } from '@theia/core/lib/browser/theming' ;
23import {
34 Disposable ,
45 DisposableCollection ,
@@ -9,7 +10,11 @@ import { inject, injectable } from '@theia/core/shared/inversify';
910import { SketchesError } from '../../common/protocol' ;
1011import { ConfigServiceClient } from '../config/config-service-client' ;
1112import { 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' ;
1318import { NotificationCenter } from '../notification-center' ;
1419import { CloudSketchContribution } from './cloud-contribution' ;
1520import { CommandRegistry , MenuModelRegistry , Sketch } from './contribution' ;
@@ -27,21 +32,34 @@ export class OpenRecentSketch extends CloudSketchContribution {
2732 private readonly imageCache : NativeImageCache ;
2833 @inject ( ConfigServiceClient )
2934 private readonly configServiceClient : ConfigServiceClient ;
35+ @inject ( ThemeService )
36+ private readonly themeService : ThemeService ;
3037
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 ;
3343
3444 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 ( ) ;
4155 }
4256
4357 override async onReady ( ) : Promise < void > {
4458 this . update ( ) ;
59+ this . imageCache . getImage ( 'cloud' ) . then ( ( image ) => {
60+ this . cloudImage = image ;
61+ this . update ( ) ;
62+ } ) ;
4563 }
4664
4765 override registerMenus ( registry : MenuModelRegistry ) : void {
@@ -65,7 +83,7 @@ export class OpenRecentSketch extends CloudSketchContribution {
6583
6684 private register ( sketches : Sketch [ ] ) : void {
6785 const order = 0 ;
68- this . toDispose . dispose ( ) ;
86+ this . toDisposeBeforeRegister . dispose ( ) ;
6987 for ( const sketch of sketches ) {
7088 const { uri } = sketch ;
7189 const command = { id : `arduino-open-recent--${ uri } ` } ;
@@ -95,7 +113,7 @@ export class OpenRecentSketch extends CloudSketchContribution {
95113 ArduinoMenus . FILE__OPEN_RECENT_SUBMENU ,
96114 menuAction
97115 ) ;
98- this . toDispose . pushAll ( [
116+ this . toDisposeBeforeRegister . pushAll ( [
99117 new DisposableCollection (
100118 Disposable . create ( ( ) =>
101119 this . commandRegistry . unregisterCommand ( command )
@@ -109,13 +127,23 @@ export class OpenRecentSketch extends CloudSketchContribution {
109127 }
110128
111129 private assignImage ( sketch : Sketch , menuAction : MenuAction ) : MenuAction {
112- if ( this . cloudImage ) {
130+ const image = this . nativeImageForTheme ( ) ;
131+ if ( image ) {
113132 const dataDirUri = this . configServiceClient . tryGetDataDirUri ( ) ;
114133 const isCloud = this . createFeatures . isCloud ( sketch , dataDirUri ) ;
115134 if ( isCloud ) {
116- Object . assign ( menuAction , { nativeImage : this . cloudImage } ) ;
135+ Object . assign ( menuAction , { nativeImage : image } ) ;
117136 }
118137 }
119138 return menuAction ;
120139 }
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+ }
121149}
0 commit comments