Skip to content

Commit 8d1968a

Browse files
FatmeFatme
authored andcommitted
Merge pull request #628 from NativeScript/fatme/livesync
LiveSync support
2 parents c0acb61 + 1c1c4e0 commit 8d1968a

File tree

11 files changed

+439
-13
lines changed

11 files changed

+439
-13
lines changed

.settings/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"configurations": [
66
{
77
// Name of configuration; appears in the launch configuration drop down menu.
8-
"name": "build",
8+
"name": "livesync",
99
// Type of configuration. Possible values: "node", "mono".
1010
"type": "node",
1111
// Workspace relative or absolute path to the program.
1212
"program": "bin/nativescript.js",
1313
// Automatically stop program after launch.
1414
"stopOnEntry": true,
1515
// Command line arguments passed to the program.
16-
"args": [],
16+
"args": ["livesync", "--path", "scratch/syncProject", "--justlaunch"],
1717
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
1818
"cwd": ".",
1919
"isShellCommand": true,

lib/bootstrap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ $injector.require("analyticsSettingsService", "./services/analytics-settings-ser
2323

2424
$injector.require("emulatorSettingsService", "./services/emulator-settings-service");
2525

26+
$injector.require("usbLiveSyncService", "./services/usb-livesync-service");
27+
2628
$injector.require("platformCommandParameter", "./platform-command-param");
2729
$injector.requireCommand("create", "./commands/create-project");
2830
$injector.requireCommand("platform|*list", "./commands/list-platforms");
@@ -49,6 +51,7 @@ $injector.require("lockfile", "./lockfile");
4951
$injector.require("dynamicHelpProvider", "./dynamic-help-provider");
5052
$injector.require("mobilePlatformsCapabilities", "./mobile-platforms-capabilities");
5153
$injector.require("commandsServiceProvider", "./providers/commands-service-provider");
54+
$injector.require("deviceAppDataProvider", "./providers/device-app-data-provider");
5255

5356
$injector.require("logcatPrinter", "./providers/logcat-printer");
5457

@@ -67,3 +70,4 @@ $injector.require("initService", "./services/init-service");
6770
$injector.requireCommand("init", "./commands/init");
6871

6972
$injector.require("projectFilesManager", "./services/project-files-manager");
73+
$injector.requireCommand("livesync", "./commands/livesync");

lib/commands/livesync.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
export class LivesyncCommand implements ICommand {
5+
constructor(private $logger: ILogger,
6+
private $usbLiveSyncService: IUsbLiveSyncService,
7+
private $mobileHelper: Mobile.IMobileHelper,
8+
private $options: IOptions,
9+
private $errors: IErrors) { }
10+
11+
public execute(args: string[]): IFuture<void> {
12+
this.$options.justlaunch = true;
13+
return this.$usbLiveSyncService.liveSync(args[0]);
14+
}
15+
16+
public canExecute(args: string[]): IFuture<boolean> {
17+
return (() => {
18+
if(args.length >= 2) {
19+
this.$errors.fail("Invalid number of arguments.");
20+
}
21+
22+
let platform = args[0];
23+
if(platform) {
24+
return _.contains(this.$mobileHelper.platformNames, this.$mobileHelper.normalizePlatformName(platform));
25+
}
26+
27+
return true;
28+
}).future<boolean>()();
29+
}
30+
31+
allowedParameters: ICommandParameter[] = [];
32+
}
33+
$injector.registerCommand("livesync", LivesyncCommand);

lib/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export class StaticConfig extends staticConfigBaseLibPath.StaticConfigBase imple
3030
public TRACK_FEATURE_USAGE_SETTING_NAME = "TrackFeatureUsage";
3131
public ANALYTICS_INSTALLATION_ID_SETTING_NAME = "AnalyticsInstallationID";
3232
public START_PACKAGE_ACTIVITY_NAME = "com.tns.NativeScriptActivity";
33+
34+
constructor($injector: IInjector) {
35+
super($injector);
36+
}
37+
3338
public get SYS_REQUIREMENTS_LINK(): string {
3439
var linkToSysRequirements: string;
3540
switch(process.platform) {

lib/declarations.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ interface IOpener {
5050
open(target: string, appname: string): void;
5151
}
5252

53+
interface IUsbLiveSyncService {
54+
liveSync(platform: string): IFuture<void>;
55+
}
56+
57+
interface IPlatformSpecificUsbLiveSyncService {
58+
restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void>;
59+
}
60+
5361
interface IOptions extends ICommonOptions {
5462
frameworkPath: string;
5563
frameworkName: string;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
import deviceAppDataBaseLib = require("../common/mobile/device-app-data/device-app-data-base");
4+
import constantsLib = require("../common/mobile/constants");
5+
import Future = require("fibers/future");
6+
7+
export class IOSAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase implements Mobile.IDeviceAppData {
8+
private static DEVICE_PROJECT_ROOT_PATH = "Library/Application Support/LiveSync";
9+
10+
constructor(_appIdentifier: string) {
11+
super(_appIdentifier);
12+
}
13+
14+
public get deviceProjectRootPath(): string {
15+
return this.getDeviceProjectRootPath(IOSAppIdentifier.DEVICE_PROJECT_ROOT_PATH);
16+
}
17+
18+
public isLiveSyncSupported(device: Mobile.IDevice): IFuture<boolean> {
19+
return Future.fromResult(true);
20+
}
21+
}
22+
23+
export class AndroidAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase implements Mobile.IDeviceAppData {
24+
constructor(_appIdentifier: string) {
25+
super(_appIdentifier);
26+
}
27+
28+
public get deviceProjectRootPath(): string {
29+
return `/data/local/tmp/12590FAA-5EDD-4B12-856D-F52A0A1599F2/${this.appIdentifier}`;
30+
}
31+
32+
public isLiveSyncSupported(device: Mobile.IDevice): IFuture<boolean> {
33+
return Future.fromResult(true);
34+
}
35+
}
36+
37+
export class AndroidCompanionAppIdentifier extends deviceAppDataBaseLib.CompanionDeviceAppDataBase implements Mobile.IDeviceAppData {
38+
private static APP_IDENTIFIER = "com.telerik.NativeScript";
39+
40+
constructor() {
41+
super(AndroidCompanionAppIdentifier.APP_IDENTIFIER);
42+
}
43+
44+
public get deviceProjectRootPath(): string {
45+
return `/mnt/sdcard/Android/data/${this.appIdentifier}/files/12590FAA-5EDD-4B12-856D-F52A0A1599F2`;
46+
}
47+
}
48+
49+
export class DeviceAppDataProvider implements Mobile.IDeviceAppDataProvider {
50+
public createFactoryRules(): IDictionary<Mobile.IDeviceAppDataFactoryRule> {
51+
return {
52+
iOS: {
53+
vanilla: IOSAppIdentifier
54+
},
55+
Android: {
56+
vanilla: AndroidAppIdentifier,
57+
companion: AndroidCompanionAppIdentifier
58+
}
59+
}
60+
}
61+
}
62+
$injector.register("deviceAppDataProvider", DeviceAppDataProvider);

0 commit comments

Comments
 (0)