@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
77import type * as messages from '../../webviews/sessionLogView/messages' ;
88import { AuthProvider } from '../common/authentication' ;
99import { Disposable } from '../common/lifecycle' ;
10- import { CopilotApi } from '../github/copilotApi' ;
10+ import { CopilotApi , SessionInfo } from '../github/copilotApi' ;
1111import { CredentialStore } from '../github/credentials' ;
1212import { PullRequestModel } from '../github/pullRequestModel' ;
1313import { hasEnterpriseUri } from '../github/utils' ;
@@ -92,7 +92,7 @@ export class SessionLogViewManager extends Disposable {
9292 <meta charset="UTF-8">
9393 <meta name="viewport" content="width=device-width, initial-scale=1.0">
9494 <title>Session Log</title>
95- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline' ${ webviewPanel . webview . cspSource } ; script-src ${ webviewPanel . webview . cspSource } ;">
95+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline' ${ webviewPanel . webview . cspSource } ; script-src ${ webviewPanel . webview . cspSource } 'unsafe-eval' ;">
9696 </head>
9797 <body>
9898 <div id="app"></div>
@@ -106,14 +106,89 @@ export class SessionLogViewManager extends Disposable {
106106 copilotApi . getLogsFromSession ( sessionId )
107107 ] ) ;
108108
109- webviewPanel . webview . postMessage ( {
110- type : 'init' ,
111- info,
112- logs,
113- } as messages . InitMessage ) ;
109+ new SessionLogView ( info , logs , webviewPanel ) ;
114110 }
115111}
116112
113+ class SessionLogView extends Disposable {
114+ constructor (
115+ info : SessionInfo ,
116+ logs : string ,
117+ webviewPanel : vscode . WebviewPanel
118+ ) {
119+ super ( ) ;
120+
121+ loadCurrentThemeData ( ) . then ( themeData => {
122+ webviewPanel . webview . postMessage ( {
123+ type : 'init' ,
124+ info,
125+ logs,
126+ themeData,
127+ } as messages . InitMessage ) ;
128+ } ) ;
129+
130+ this . _register ( webviewPanel . onDidDispose ( ( ) => {
131+ this . dispose ( ) ;
132+ } ) ) ;
133+
134+ this . _register ( vscode . workspace . onDidChangeConfiguration ( async e => {
135+ if ( e . affectsConfiguration ( 'workbench.colorTheme' ) ) {
136+ const themeData = await loadCurrentThemeData ( ) ;
137+ webviewPanel . webview . postMessage ( {
138+ type : 'changeTheme' ,
139+ themeData,
140+ } as messages . ChangeThemeMessage ) ;
141+ }
142+ } ) ) ;
143+ }
144+ }
145+
146+
147+ async function loadCurrentThemeData ( ) : Promise < any > {
148+ let themeData : any = null ;
149+ const currentThemeName = vscode . workspace . getConfiguration ( 'workbench' ) . get < string > ( 'colorTheme' ) ;
150+ if ( currentThemeName ) {
151+ const path = getCurrentThemePath ( currentThemeName ) ;
152+ if ( path ) {
153+ themeData = await loadThemeFromFile ( path ) ;
154+ }
155+ }
156+ return themeData ;
157+ }
158+
159+ async function loadThemeFromFile ( path : vscode . Uri ) : Promise < any > {
160+ const decoder = new TextDecoder ( ) ;
161+
162+ let themeData = JSON . parse ( decoder . decode ( await vscode . workspace . fs . readFile ( path ) ) ) ;
163+
164+ // Also load the include file if specified
165+ if ( themeData . include ) {
166+ try {
167+ const includePath = vscode . Uri . joinPath ( path , '..' , themeData . include ) ;
168+ const includeData = await loadThemeFromFile ( includePath ) ;
169+ themeData = {
170+ ...themeData ,
171+ colors : {
172+ ...( includeData . colors || { } ) ,
173+ ...( themeData . colors || { } ) ,
174+ } ,
175+ tokenColors : [
176+ ...( includeData . tokenColors || [ ] ) ,
177+ ...( themeData . tokenColors || [ ] ) ,
178+ ] ,
179+ semanticTokenColors : {
180+ ...( includeData . semanticTokenColors || { } ) ,
181+ ...( themeData . semanticTokenColors || { } ) ,
182+ } ,
183+ } ;
184+ } catch ( error ) {
185+ console . warn ( `Failed to load theme include file: ${ error } ` ) ;
186+ }
187+ }
188+
189+ return themeData ;
190+ }
191+
117192async function getCopilotApi ( credentialStore : CredentialStore ) : Promise < CopilotApi | undefined > {
118193 let authProvider : AuthProvider | undefined ;
119194 if ( credentialStore . isAuthenticated ( AuthProvider . githubEnterprise ) && hasEnterpriseUri ( ) ) {
@@ -132,3 +207,16 @@ async function getCopilotApi(credentialStore: CredentialStore): Promise<CopilotA
132207 const { token } = await github . octokit . api . auth ( ) as { token : string } ;
133208 return new CopilotApi ( github . octokit , token ) ;
134209}
210+
211+ function getCurrentThemePath ( themeName : string ) : vscode . Uri | undefined {
212+ for ( const ext of vscode . extensions . all ) {
213+ const themes = ext . packageJSON . contributes && ext . packageJSON . contributes . themes ;
214+ if ( ! themes ) {
215+ continue ;
216+ }
217+ const theme = themes . find ( theme => theme . label === themeName || theme . id === themeName ) ;
218+ if ( theme ) {
219+ return vscode . Uri . joinPath ( ext . extensionUri , theme . path ) ;
220+ }
221+ }
222+ }
0 commit comments