Skip to content

Commit

Permalink
Show more dev container info in title bar
Browse files Browse the repository at this point in the history
  • Loading branch information
jbicker committed Dec 20, 2024
1 parent 8d7fa9e commit 9a3319e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/browser/window/window-title-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export class WindowTitleService {
if (developmentHost) {
this._title = developmentHost + this.separator + this._title;
}
const devContainer = this.titleParts.get('devContainer');
if (devContainer) {
this._title = `${this._title} [${devContainer}]`;
}
document.title = this._title || FrontendApplicationConfigProvider.get().applicationName;
this.onDidChangeTitleEmitter.fire(this._title);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { ContainerInspectInfo } from 'dockerode';
import { RemoteContainerConnectionProvider } from '../electron-common/remote-container-connection-provider';
import { PortForwardingService } from '@theia/remote/lib/electron-browser/port-forwarding/port-forwarding-service';
import { getCurrentPort } from '@theia/core/lib/electron-browser/messaging/electron-local-ws-connection-source';
import { WindowTitleService } from '@theia/core/lib/browser/window/window-title-service';

@injectable()
export class ContainerInfoContribution implements FrontendApplicationContribution {
Expand All @@ -30,11 +31,23 @@ export class ContainerInfoContribution implements FrontendApplicationContributio
@inject(PortForwardingService)
protected readonly portForwardingService: PortForwardingService;

@inject(WindowTitleService)
protected readonly windowTitleService: WindowTitleService;

containerInfo: ContainerInspectInfo | undefined;

async onStart(): Promise<void> {
this.containerInfo = await this.connectionProvider.getCurrentContainerInfo(parseInt(getCurrentPort() ?? '0'));
initialize(): void {
this.connectionProvider.getCurrentContainerInfo(parseInt(new URLSearchParams(location.search).get('port') ?? '0')).then(info => {
if (info) {
this.containerInfo = info;
this.windowTitleService.update({
devContainer: `Dev Container @ ${info?.Platform ?? ''}`
});
}
});
}

async onStart(): Promise<void> {
this.portForwardingService.forwardedPorts = Object.entries(this.containerInfo?.NetworkSettings.Ports ?? {}).flatMap(([_, ports]) => (
ports.map(port => ({
editing: false,
Expand Down

0 comments on commit 9a3319e

Please sign in to comment.