Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Send page reload message to android runtime #511

Merged
merged 6 commits into from
Nov 12, 2015
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
32 changes: 24 additions & 8 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,30 @@ interface IHtmlHelpService {
interface IUsbLiveSyncServiceBase {
initialize(platform: string): IFuture<string>;
isInitialized: boolean;
sync(platform: string, appIdentifier: string, projectFilesPath: string, excludedProjectDirsAndFiles: string[], watchGlob: any,
platformSpecificLiveSyncServices: IDictionary<any>,
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<boolean>,
notRunningiOSSimulatorAction: () => IFuture<boolean>,
localProjectRootPath?: string,
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>,
iOSSimulatorRelativeToProjectBasePathAction?: (projectFile: string) => string): IFuture<void>;
sync(data: ILiveSyncData): IFuture<void>;
}

interface ILiveSyncData {
platform: string;
appIdentifier: string;
projectFilesPath: string;
excludedProjectDirsAndFiles: string[];
watchGlob: any;
platformSpecificLiveSyncServices: IDictionary<any>;
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<void>;
notRunningiOSSimulatorAction: () => IFuture<void>;
localProjectRootPath?: string;
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>;
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>;
iOSSimulatorRelativeToProjectBasePathAction?: (projectFile: string) => string;
canExecuteFastLiveSync?: (filePath: string) => boolean;
fastLiveSync?: (filePath: string) => void;
}

interface IPlatformSpecificUsbLiveSyncService {
restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void>;
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
sendPageReloadMessageToDevice?(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
}

interface ISysInfoData {
Expand Down
9 changes: 6 additions & 3 deletions definitions/mobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ declare module Mobile {
putFile(localFilePath: string, deviceFilePath: string): IFuture<void>;
deleteFile?(deviceFilePath: string, appIdentifier: string): void;
transferFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void>;
transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): IFuture<void>;
transferFile?(localFilePath: string, deviceFilePath: string): IFuture<void>;
}

Expand Down Expand Up @@ -261,7 +262,8 @@ declare module Mobile {

interface IGDBServer {
run(argv: string[]): IFuture<void>;
kill(bundleExecutableName: string): IFuture<void>;
kill(argv: string[]): IFuture<void>;
destory(): void;
}

interface INotificationProxyClient {
Expand Down Expand Up @@ -298,9 +300,10 @@ declare module Mobile {

interface IiOSSimulatorService extends IEmulatorPlatformServices {
postDarwinNotification(notification: string): IFuture<void>;
sync(appIdentifier: string, projectFilesPath: string, notRunningSimulatorAction: () => IFuture<boolean>): IFuture<void>;
syncFiles(appIdentifier: string, projectFilesPath: string, projectFiles: string[], notRunningSimulatorAction: () => IFuture<boolean>, relativeToProjectBasePathAction?: (projectFile: string) => string): IFuture<void>;
sync(appIdentifier: string, projectFilesPath: string, notRunningSimulatorAction: () => IFuture<void>): IFuture<void>;
syncFiles(appIdentifier: string, projectFilesPath: string, projectFiles: string[], notRunningSimulatorAction: () => IFuture<void>, relativeToProjectBasePathAction?: (projectFile: string) => string): IFuture<void>;
isSimulatorRunning(): IFuture<boolean>;
transferFiles(appIdentifier: string, projectFiles: string[], relativeToProjectBasePathAction?: (_projectFile: string) => string, applicationPath?: string): IFuture<void>
}

interface IEmulatorSettingsService {
Expand Down
25 changes: 20 additions & 5 deletions helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import * as uuid from "node-uuid";
import * as Fiber from "fibers";
import * as net from "net";
let Table = require("cli-table");
import Future = require("fibers/future");
import { platform } from "os";
Expand Down Expand Up @@ -238,25 +239,39 @@ export function isFuture(candidateFuture: any): boolean {
export function whenAny<T>(...futures: IFuture<T>[]): IFuture<IFuture<T>> {
let resultFuture = new Future<IFuture<T>>();
let futuresLeft = futures.length;
let futureLocal: IFuture<T>;

for (let future of futures) {
futureLocal = future;
_.each(futures, future => {
future.resolve((error, result?) => {
futuresLeft--;

if (!resultFuture.isResolved()) {
if (typeof error === "undefined") {
resultFuture.return(futureLocal);
resultFuture.return(future);
} else if (futuresLeft === 0) {
resultFuture.throw(new Error("None of the futures succeeded."));
}
}
});
}
});

return resultFuture;
}

export function connectEventually(factory: () => net.Socket, handler: (_socket: net.Socket) => void): void {
function tryConnect() {
let tryConnectAfterTimeout = setTimeout.bind(undefined, tryConnect, 1000);

let socket = factory();
socket.on("connect", () => {
socket.removeListener("error", tryConnectAfterTimeout);
handler(socket);
});
socket.on("error", tryConnectAfterTimeout);
}

tryConnect();
}

//--- begin part copied from AngularJS

//The MIT License
Expand Down
14 changes: 12 additions & 2 deletions mobile/android/android-device-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
constructor(private adb: Mobile.IAndroidDebugBridge,
private identifier: string,
private $fs: IFileSystem,
private $logger: ILogger) { }
private $logger: ILogger,
private $deviceAppDataFactory: Mobile.IDeviceAppDataFactory) { }

public listFiles(devicePath: string): IFuture<void> {
return future.fromResult();
Expand All @@ -22,7 +23,7 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
return future.fromResult();
}

public transferFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> {
public transferFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath?: string): IFuture<void> {
return (() => {
_(localToDevicePaths)
.filter(localToDevicePathData => this.$fs.getFsStats(localToDevicePathData.getLocalPath()).wait().isFile())
Expand All @@ -40,6 +41,15 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
}).future<void>()();
}

public transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): IFuture<void> {
return (() => {
this.adb.executeCommand(["push", projectFilesPath, deviceAppData.deviceProjectRootPath]).wait();

let command = _.map(localToDevicePaths, (localToDevicePathData) => localToDevicePathData.getDevicePath()).join(" ");
this.adb.executeCommand(["chmod", "0777", command]).wait();
}).future<void>()();
}

public transferFile(localPath: string, devicePath: string): IFuture<void> {
return (() => {
this.$logger.trace(`Transfering ${localPath} to ${devicePath}`);
Expand Down
8 changes: 2 additions & 6 deletions mobile/android/android-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
}

public deploy(packageFile: string, packageName: string): IFuture<void> {
return (() => {
this.applicationManager.reinstallApplication(packageName, packageFile).wait();
this.applicationManager.startApplication(packageName).wait();
this.$logger.info("Successfully deployed on device with identifier '%s'", this.identifier);
}).future<void>()();
}
return this.applicationManager.reinstallApplication(packageName, packageFile);
}

public openDeviceLogStream(): void {
this.$logcatHelper.start(this.identifier);
Expand Down
24 changes: 15 additions & 9 deletions mobile/ios/ios-application-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as iOSProxyServices from "./ios-proxy-services";

export class IOSApplicationManager implements Mobile.IDeviceApplicationManager {
private uninstallApplicationCallbackPtr: NodeBuffer = null;
private _gdbServer: Mobile.IGDBServer = null;

constructor(private device: Mobile.IiOSDevice,
private devicePointer: NodeBuffer,
Expand Down Expand Up @@ -80,13 +81,12 @@ export class IOSApplicationManager implements Mobile.IDeviceApplicationManager {
public stopApplication(applicationId: string): IFuture<void> {
let application = this.getApplicationById(applicationId);
let gdbServer = this.createGdbServer();
return gdbServer.kill(application.CFBundleExecutable);
return gdbServer.kill([`${application.Path}`]);
}

public restartApplication(applicationId: string): IFuture<void> {
return (() => {
// This must be executed in separate process because ddb sometimes fails and the cli crashes.
this.$childProcess.exec(`${process.argv[0]} ${process.argv[1]} device stop ${applicationId} ${this.$devicePlatformsConstants.iOS}`).wait();
this.stopApplication(applicationId).wait();
this.runApplicationCore(applicationId).wait();
}).future<void>()();
}
Expand Down Expand Up @@ -118,17 +118,23 @@ export class IOSApplicationManager implements Mobile.IDeviceApplicationManager {
}

private runApplicationCore(applicationId: any) {
if (this._gdbServer) {
this._gdbServer.destory();
this._gdbServer = null;
}

let application = this.getApplicationById(applicationId);
let gdbServer = this.createGdbServer();
return gdbServer.run([`${application.Path}/${application.CFBundleExecutable}`]);
return gdbServer.run([`${application.Path}`]);
}

private createGdbServer(): Mobile.IGDBServer {
let service = this.device.startService(iOSProxyServices.MobileServices.DEBUG_SERVER);
let socket = this.$hostInfo.isWindows ? service : new net.Socket({ fd: service });
let gdbServer = this.$injector.resolve(GDBServer, { socket: socket });

return gdbServer;
if(!this._gdbServer) {
let service = this.device.startService(iOSProxyServices.MobileServices.DEBUG_SERVER);
let socket = this.$hostInfo.isWindows ? service : new net.Socket({ fd: service });
this._gdbServer = this.$injector.resolve(GDBServer, { socket: socket });
}
return this._gdbServer;
}

private getApplicationById(applicationId: string): Mobile.IDeviceApplication {
Expand Down
Loading