Skip to content

Commit d4eba93

Browse files
author
Fatme
authored
Merge pull request #3951 from NativeScript/fatme/qr-code-messages
fix: show color messages above the QR code on preview command
2 parents 44bab5d + ee4d224 commit d4eba93

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

lib/definitions/qr-code.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
interface IQrCodeTerminalService {
2-
generate(url: string): void;
2+
generate(url: string, message: string): void;
33
}

lib/services/livesync/playground/qr-code-generator.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,26 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
1111
}
1212

1313
public async generateQrCodeForiOS(): Promise<void> {
14-
await this.generateQrCode(PlaygroundStoreUrls.APP_STORE_URL);
14+
const message = `Scan the QR code below to install ${"NativeScript Playground app".underline.bold} on your ${"iOS".underline.bold} device or get it from ${PlaygroundStoreUrls.APP_STORE_URL.underline.bold}.`;
15+
await this.generateQrCode(PlaygroundStoreUrls.APP_STORE_URL, message);
1516
}
1617

1718
public async generateQrCodeForAndroid(): Promise<void> {
18-
await this.generateQrCode(PlaygroundStoreUrls.GOOGLE_PLAY_URL);
19+
const message = `Scan the QR code below to install ${"NativeScript Playground app".underline.bold} on your ${"Android".underline.bold} device or get it from ${PlaygroundStoreUrls.GOOGLE_PLAY_URL.underline.bold}.`;
20+
await this.generateQrCode(PlaygroundStoreUrls.GOOGLE_PLAY_URL, message);
1921
}
2022

2123
public async generateQrCodeForCurrentApp(options: IHasUseHotModuleReloadOption): Promise<void> {
22-
await this.generateQrCode(this.$previewSdkService.getQrCodeUrl(options));
24+
const message = `Use ${"NativeScript Playground app".underline.bold} and scan the QR code below to preview the application on your device.`;
25+
await this.generateQrCode(this.$previewSdkService.getQrCodeUrl(options), message);
2326
}
2427

25-
private async generateQrCode(url: string): Promise<void> {
26-
await this.generateQrCodeCore(url);
28+
private async generateQrCode(url: string, message: string): Promise<void> {
29+
await this.generateQrCodeCore(url, message);
2730
this.printUsage();
2831
}
2932

30-
private async generateQrCodeCore(url: string): Promise<void> {
33+
private async generateQrCodeCore(url: string, message: string): Promise<void> {
3134
const shortenUrlEndpoint = util.format(this.$config.SHORTEN_URL_ENDPOINT, encodeURIComponent(url));
3235
try {
3336
const response = await this.$httpClient.httpRequest(shortenUrlEndpoint);
@@ -37,14 +40,14 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
3740
// use the longUrl
3841
}
3942

40-
this.$qrCodeTerminalService.generate(url);
43+
this.$qrCodeTerminalService.generate(url, message);
4144
}
4245

4346
private printUsage(): void {
4447
this.$logger.info(`
45-
-> Press ${this.underlineBoldCyan("a")} to show the QR code of NativeScript Playground app for ${this.underlineBoldCyan("Android")} devices
46-
-> Press ${this.underlineBoldCyan("i")} to show the QR code of NativeScript Playground app for ${this.underlineBoldCyan("iOS")} devices
47-
-> Press ${this.underlineBoldCyan("c")} to display the QR code of the ${this.underlineBoldCyan("current application")}.
48+
-> Press ${this.underlineBoldCyan("a")} to get a link to NativeScript Playground app for ${this.underlineBoldCyan("Android")}
49+
-> Press ${this.underlineBoldCyan("i")} to get a link to NativeScript Playground app for ${this.underlineBoldCyan("iOS")}
50+
-> Press ${this.underlineBoldCyan("c")} to show the QR code of the ${this.underlineBoldCyan("current application")}.
4851
`);
4952
}
5053

lib/services/qr-code-terminal-service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { EOL } from "os";
2+
13
const qrcode = require("qrcode-terminal");
24

35
export class QrCodeTerminalService implements IQrCodeTerminalService {
46
constructor(private $logger: ILogger) { }
57

6-
public generate(url: string): void {
7-
this.$logger.info(`Generating qrcode for url ${url}.`);
8+
public generate(url: string, message: string): void {
9+
this.$logger.info(`${EOL} ${message.blue}`);
10+
this.$logger.info(`${EOL} Generating qrcode for url ${url}.`);
811

912
try {
1013
qrcode.generate(url);

0 commit comments

Comments
 (0)