Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Adding infobar to screencast #2432

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/Images/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/Images/info-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ export function activate(context: vscode.ExtensionContext): void {
const normalizedPath = new URL(target.description).toString();
if (browserInstance) {
const browserPages = await browserInstance.pages();

// First we validate we have pages to close, some non-visual targets could keep the browser
// instance alive.
if (!browserPages || browserPages.length === 0){
void browserInstance.close();
return;
}

for (const page of browserPages) {
// URL needs to be accessed through the target as the page could be handling errors in a different way.
// e.g redirecting to chrome-error: protocol
Expand Down
57 changes: 57 additions & 0 deletions src/screencast/infobar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { html, render } from 'lit-html';
import { createRef, ref } from 'lit-html/directives/ref.js'
import { styleMap, StyleInfo } from 'lit-html/directives/style-map.js';

interface InfobarProps {
message: string;
}

export default class InfobarComponent {
#buttonRef = createRef();
#message: string;
#container: HTMLElement | undefined;

constructor(props: InfobarProps, container?: HTMLElement) {
this.#message = props.message;
this.#container = container;
this.#update();
}

#update(styles?: StyleInfo) {
let customStyles = styles ?? {
display: 'flex'
};

if (!this.#container) {
return;
}
render(this.template(customStyles), this.#container);
}

template(styles: StyleInfo) {
return html`
<div class="infobar" style=${styleMap(styles)}>
<div class="infobar-message">${this.#message}</div>
<button class="infobar-close-button" ${ref(this.#buttonRef)} @click=${this.#onClick}></button>
</div>
`;
}

#onClick = () => {
let styles = {
display: 'none',
} as StyleInfo;

this.#update(styles);
};

static render(props: InfobarProps, elementId: string) {
const currentContainer = document.getElementById(elementId);
if (currentContainer) {
new InfobarComponent(props, currentContainer);
}
}
}
3 changes: 2 additions & 1 deletion src/screencast/screencast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MouseEventMap, ScreencastInputHandler } from './input';
import DimensionComponent from './dimensionComponent';
import { getEmulatedDeviceDetails, groupEmulatedDevicesByType } from './emulatedDeviceHelpers';
import FlyoutMenuComponent, {OffsetDirection} from './flyoutMenuComponent';
import InfobarComponent from './infobar';

import { encodeMessageForChannel } from '../common/webviewEvents';

Expand Down Expand Up @@ -58,7 +59,7 @@ export class Screencast {
this.urlInput.addEventListener('keydown', event => this.onUrlKeyDown(event));

const emulatedDevices = groupEmulatedDevicesByType();

InfobarComponent.render({message: "This is a simulated preview with limited functionality. Deactivate 'Headless mode' in extension settings for a full experience."}, 'infobar');
FlyoutMenuComponent.render({
iconName: 'codicon-chevron-down',
title: 'Emulate devices',
Expand Down
28 changes: 28 additions & 0 deletions src/screencast/view.css
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,31 @@ body {
.devtools-open {
color: #7dbae9;
}

.infobar {
flex-direction: row;
width: 100vw;
color: black;
background-color: rgb(254 246 213 / 100%);
height: 30px;
}

.infobar-message {
text-align: left;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: small;
padding: 5px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

.infobar-close-button {
background-image: url('../../resources/Images/cross.svg');
background-repeat: no-repeat;
align-self: right;
background-size: 18px;
width: 20px;
height: 20px;
margin: 5px 10px 5px auto;
}
1 change: 1 addition & 0 deletions src/screencast/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class ScreencastView {
</head>
<body>
<div id="main">
<div id="infobar"></div>
<div id="toolbar">
<button id="back" title="Back">
<i class="codicon codicon-arrow-left"></i>
Expand Down
Loading