microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
70bb7c837ccaaa18600156aa8a698af0d78c3487

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/qrCodeContentProvider.ts

34lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as qr from "qr-image";
5import { TextDocumentContentProvider, Uri, CancellationToken } from "vscode";
6
7export class QRCodeContentProvider implements TextDocumentContentProvider {
8
9 private cache: { [uri: string]: string } = {};
10
11 public provideTextDocumentContent(uri: Uri, token: CancellationToken): string {
12
13 let stringUri = uri.toString();
14
15 if (!this.cache[stringUri]) {
16 const imageBuffer: NodeBuffer = qr.imageSync(stringUri);
17 this.cache[stringUri] = "data:image/png;base64," + imageBuffer.toString("base64");
18 }
19
20 return `<!DOCTYPE html>
21 <html>
22 <body>
23 <div style="text-align:center">
24 <h3>
25 Expo is running. Open your Expo app at<br/>
26 <span style="text-decoration: underline">${stringUri}</span><br/>
27 or scan QR code below:
28 <h3>
29 <img src="${this.cache[stringUri]}" />
30 </div>
31 </body>
32 </html>`;
33 }
34}
35