Skip to content

Commit 9536b60

Browse files
committed
fix(api): return correct store urls based on the schema from getPlaygroundAppQrCode method
1 parent cd32805 commit 9536b60

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

lib/definitions/preview-app-livesync.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ declare global {
4545
printLiveSyncQrCode(options: IPrintLiveSyncOptions): Promise<void>;
4646
}
4747

48-
interface IPlaygroundAppQrCodeOptions {
48+
interface IPlaygroundAppQrCodeOptions extends IProjectDir {
4949
platform?: string;
5050
}
5151

@@ -71,8 +71,10 @@ declare global {
7171

7272
interface IPreviewSchemaData {
7373
name: string;
74-
previewAppId: string;
7574
scannerAppId: string;
75+
scannerAppStoreId: string;
76+
previewAppId: string;
77+
previewAppStoreId: string;
7678
msvKey: string;
7779
publishKey: string;
7880
subscribeKey: string;

lib/services/livesync/playground/preview-app-constants.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ export class PubnubKeys {
88
public static SUBSCRIBE_KEY = "sub-c-3dad1ebe-aaa3-11e8-8027-363023237e0b";
99
}
1010

11-
export class PlaygroundStoreUrls {
12-
public static GOOGLE_PLAY_URL = "https://play.google.com/store/apps/details?id=org.nativescript.play";
13-
public static APP_STORE_URL = "https://itunes.apple.com/us/app/nativescript-playground/id1263543946?mt=8&ls=1";
14-
}
15-
1611
export class PluginComparisonMessages {
1712
public static PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP = "Plugin %s is not included in preview app on device %s and will not work.";
1813
public static LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION = "Local plugin %s differs in major version from plugin in preview app. The local plugin has version %s and the plugin in preview app has version %s. Some features might not work as expected.";

lib/services/livesync/playground/preview-qr-code-service.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as util from "util";
22
import { EOL } from "os";
3-
import { PlaygroundStoreUrls } from "./preview-app-constants";
43
import { exported } from "../../../common/decorators";
54

65
export class PreviewQrCodeService implements IPreviewQrCodeService {
@@ -10,20 +9,22 @@ export class PreviewQrCodeService implements IPreviewQrCodeService {
109
private $logger: ILogger,
1110
private $mobileHelper: Mobile.IMobileHelper,
1211
private $previewSdkService: IPreviewSdkService,
12+
private $previewSchemaService: IPreviewSchemaService,
1313
private $qrCodeTerminalService: IQrCodeTerminalService,
1414
private $qr: IQrCodeGenerator
1515
) { }
1616

1717
@exported("previewQrCodeService")
1818
public async getPlaygroundAppQrCode(options?: IPlaygroundAppQrCodeOptions): Promise<IDictionary<IQrCodeImageData>> {
19+
const { projectDir } = options;
1920
const result = Object.create(null);
2021

2122
if (!options || !options.platform || this.$mobileHelper.isAndroidPlatform(options.platform)) {
22-
result.android = await this.getLiveSyncQrCode(PlaygroundStoreUrls.GOOGLE_PLAY_URL);
23+
result.android = await this.getLiveSyncQrCode(this.getGooglePlayUrl(projectDir));
2324
}
2425

2526
if (!options || !options.platform || this.$mobileHelper.isiOSPlatform(options.platform)) {
26-
result.ios = await this.getLiveSyncQrCode(PlaygroundStoreUrls.APP_STORE_URL);
27+
result.ios = await this.getLiveSyncQrCode(this.getAppStoreUrl(projectDir));
2728
}
2829

2930
return result;
@@ -56,8 +57,8 @@ export class PreviewQrCodeService implements IPreviewQrCodeService {
5657
this.$logger.printMarkdown(`# Use \`NativeScript Playground app\` and scan the \`QR code\` above to preview the application on your device.`);
5758
this.$logger.printMarkdown(`
5859
To scan the QR code and deploy your app on a device, you need to have the \`NativeScript Playground app\`:
59-
App Store (iOS): ${PlaygroundStoreUrls.APP_STORE_URL}
60-
Google Play (Android): ${PlaygroundStoreUrls.GOOGLE_PLAY_URL}`);
60+
App Store (iOS): ${this.getAppStoreUrl(options.projectDir)}
61+
Google Play (Android): ${this.getGooglePlayUrl(options.projectDir)}`);
6162
}
6263
}
6364

@@ -73,5 +74,15 @@ To scan the QR code and deploy your app on a device, you need to have the \`Nati
7374

7475
return url;
7576
}
77+
78+
private getGooglePlayUrl(projectDir: string): string {
79+
const schema = this.$previewSchemaService.getSchemaData(projectDir);
80+
return `https://play.google.com/store/apps/details?id=${schema.scannerAppId}`;
81+
}
82+
83+
private getAppStoreUrl(projectDir: string): string {
84+
const schema = this.$previewSchemaService.getSchemaData(projectDir);
85+
return `https://itunes.apple.com/us/app/nativescript-playground/id${schema.scannerAppStoreId}?mt=8&ls=1`;
86+
}
7687
}
7788
$injector.register("previewQrCodeService", PreviewQrCodeService);

lib/services/livesync/playground/preview-schema-service.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ export class PreviewSchemaService implements IPreviewSchemaService {
44
private previewSchemas: IDictionary<IPreviewSchemaData> = {
55
"nsplay": {
66
name: "nsplay",
7-
previewAppId: "org.nativescript.preview",
87
scannerAppId: "org.nativescript.play",
8+
scannerAppStoreId: "1263543946",
9+
previewAppId: "org.nativescript.preview",
10+
previewAppStoreId: "1264484702",
911
msvKey: "cli",
1012
publishKey: PubnubKeys.PUBLISH_KEY,
1113
subscribeKey: PubnubKeys.SUBSCRIBE_KEY,
1214
default: true
1315
},
1416
"ksplay": {
1517
name: "ksplay",
16-
previewAppId: "com.kinvey.preview",
1718
scannerAppId: "com.kinvey.scanner",
19+
scannerAppStoreId: "1263543946",
20+
previewAppId: "com.kinvey.preview",
21+
previewAppStoreId: "1264484702",
1822
msvKey: "kinveyStudio",
1923
publishKey: PubnubKeys.PUBLISH_KEY,
2024
subscribeKey: PubnubKeys.SUBSCRIBE_KEY
@@ -25,9 +29,7 @@ export class PreviewSchemaService implements IPreviewSchemaService {
2529
private $projectDataService: IProjectDataService) { }
2630

2731
public getSchemaData(projectDir: string): IPreviewSchemaData {
28-
const projectData = this.$projectDataService.getProjectData(projectDir);
29-
30-
let schemaName = projectData.previewAppSchema;
32+
let schemaName = this.getSchemaNameFromProject(projectDir);
3133
if (!schemaName) {
3234
schemaName = _.findKey(this.previewSchemas, previewSchema => previewSchema.default);
3335
}
@@ -39,5 +41,14 @@ export class PreviewSchemaService implements IPreviewSchemaService {
3941

4042
return result;
4143
}
44+
45+
private getSchemaNameFromProject(projectDir: string): string {
46+
try {
47+
const projectData = this.$projectDataService.getProjectData(projectDir);
48+
return projectData.previewAppSchema;
49+
} catch (err) { /* ignore the error */ }
50+
51+
return null;
52+
}
4253
}
4354
$injector.register("previewSchemaService", PreviewSchemaService);

0 commit comments

Comments
 (0)