Skip to content

Fix LiveSync on iOS when app is uninstalled manually #3005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2017
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
1 change: 1 addition & 0 deletions PublicAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ tns.liveSyncService.on("liveSyncStarted", data => {
* Full paths to files synced during the operation. In case the `syncedFiles.length` is 0, the operation is "fullSync" (i.e. all project files are synced).
*/
syncedFiles: string[];
isFullSync: boolean;
}
```
Expand Down
12 changes: 11 additions & 1 deletion lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ interface IEnsureLatestAppPackageIsInstalledOnDeviceOptions {
modifiedFiles?: string[];
}

/**
* Describes the action that has been executed during ensureLatestAppPackageIsInstalledOnDevice execution.
*/
interface IAppInstalledOnDeviceResult {
/**
* Defines if the app has been installed on device from the ensureLatestAppPackageIsInstalledOnDevice method.
*/
appInstalled: boolean;
}

/**
* Describes LiveSync operations.
*/
Expand Down Expand Up @@ -187,7 +197,7 @@ interface ILiveSyncWatchInfo {
projectData: IProjectData;
filesToRemove: string[];
filesToSync: string[];
isRebuilt: boolean;
isReinstalled: boolean;
syncAllFiles: boolean;
useLiveEdit?: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/livesync/ios-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
}

public liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
if (liveSyncInfo.isRebuilt) {
if (liveSyncInfo.isReinstalled) {
// In this case we should execute fullsync because iOS Runtime requires the full content of app dir to be extracted in the root of sync dir.
return this.fullSync({ projectData: liveSyncInfo.projectData, device, syncAllFiles: liveSyncInfo.syncAllFiles, watch: true });
} else {
Expand Down
17 changes: 11 additions & 6 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
projectDir: projectData.projectDir,
applicationIdentifier: projectData.projectId,
syncedFiles: liveSyncResultInfo.modifiedFilesData.map(m => m.getLocalPath()),
deviceIdentifier: liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier
deviceIdentifier: liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier,
isFullSync: liveSyncResultInfo.isFullSync
});

this.$logger.info(`Successfully synced application ${liveSyncResultInfo.deviceAppData.appIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}.`);
Expand Down Expand Up @@ -154,8 +155,9 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
throw new Error(`Invalid platform ${platform}. Supported platforms are: ${this.$mobileHelper.platformNames.join(", ")}`);
}

private async ensureLatestAppPackageIsInstalledOnDevice(options: IEnsureLatestAppPackageIsInstalledOnDeviceOptions, nativePrepare?: INativePrepare): Promise<void> {
private async ensureLatestAppPackageIsInstalledOnDevice(options: IEnsureLatestAppPackageIsInstalledOnDeviceOptions, nativePrepare?: INativePrepare): Promise<IAppInstalledOnDeviceResult> {
const platform = options.device.deviceInfo.platform;
const appInstalledOnDeviceResult: IAppInstalledOnDeviceResult = { appInstalled: false };
if (options.preparedPlatforms.indexOf(platform) === -1) {
options.preparedPlatforms.push(platform);
// TODO: Pass provision and sdk as a fifth argument here
Expand All @@ -167,7 +169,8 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {

const buildResult = await this.installedCachedAppPackage(platform, options);
if (buildResult) {
return;
appInstalledOnDeviceResult.appInstalled = true;
return appInstalledOnDeviceResult;
}

// TODO: Pass provision and sdk as a fifth argument here
Expand All @@ -176,7 +179,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
let action = LiveSyncTrackActionNames.LIVESYNC_OPERATION;
if (shouldBuild) {
pathToBuildItem = await options.deviceBuildInfoDescriptor.buildAction();
// Is it possible to return shouldBuild for two devices? What about android device and android emulator?
options.rebuiltInformation.push({ isEmulator: options.device.isEmulator, platform, pathToBuildItem });
action = LiveSyncTrackActionNames.LIVESYNC_OPERATION_BUILD;
}
Expand All @@ -186,7 +188,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
const shouldInstall = await this.$platformService.shouldInstall(options.device, options.projectData, options.deviceBuildInfoDescriptor.outputPath);
if (shouldInstall) {
await this.$platformService.installApplication(options.device, { release: false }, options.projectData, pathToBuildItem, options.deviceBuildInfoDescriptor.outputPath);
appInstalledOnDeviceResult.appInstalled = true;
}

return appInstalledOnDeviceResult;
}

private async trackAction(action: string, platform: string, options: IEnsureLatestAppPackageIsInstalledOnDeviceOptions): Promise<void> {
Expand Down Expand Up @@ -331,7 +336,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
const liveSyncProcessInfo = this.liveSyncProcessesInfo[projectData.projectDir];
const deviceBuildInfoDescriptor = _.find(liveSyncProcessInfo.deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);

await this.ensureLatestAppPackageIsInstalledOnDevice({
const appInstalledOnDeviceResult = await this.ensureLatestAppPackageIsInstalledOnDevice({
device,
preparedPlatforms,
rebuiltInformation,
Expand All @@ -346,7 +351,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
projectData,
filesToRemove: currentFilesToRemove,
filesToSync: currentFilesToSync,
isRebuilt: !!_.find(rebuiltInformation, info => info.isEmulator === device.isEmulator && info.platform === device.deviceInfo.platform),
isReinstalled: appInstalledOnDeviceResult.appInstalled,
syncAllFiles: liveSyncData.watchAllFiles,
useLiveEdit: liveSyncData.useLiveEdit
};
Expand Down
15 changes: 9 additions & 6 deletions lib/services/livesync/platform-livesync-service-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export abstract class PlatformLiveSyncServiceBase {

const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, null, []);
await this.transferFiles(deviceAppData, localToDevicePaths, projectFilesPath, true);
const modifiedFilesData = await this.transferFiles(deviceAppData, localToDevicePaths, projectFilesPath, true);

return {
modifiedFilesData: localToDevicePaths,
modifiedFilesData,
isFullSync: true,
deviceAppData
};
Expand Down Expand Up @@ -96,19 +96,22 @@ export abstract class PlatformLiveSyncServiceBase {

return {
modifiedFilesData: modifiedLocalToDevicePaths,
isFullSync: liveSyncInfo.isRebuilt,
isFullSync: liveSyncInfo.isReinstalled,
deviceAppData
};
}

protected async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<void> {
protected async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<Mobile.ILocalToDevicePathData[]> {
let transferredFiles = localToDevicePaths;
if (isFullSync) {
await deviceAppData.device.fileSystem.transferDirectory(deviceAppData, localToDevicePaths, projectFilesPath);
transferredFiles = await deviceAppData.device.fileSystem.transferDirectory(deviceAppData, localToDevicePaths, projectFilesPath);
} else {
await deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
}

this.logFilesSyncInformation(localToDevicePaths, "Successfully transferred %s.", this.$logger.info);
this.logFilesSyncInformation(transferredFiles, "Successfully transferred %s.", this.$logger.info);

return transferredFiles;
}

protected async getAppData(syncInfo: IFullSyncInfo): Promise<Mobile.IDeviceAppData> {
Expand Down