-
-
Notifications
You must be signed in to change notification settings - Fork 194
Livesync service refactoring #1941
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
dd27d53
Remove getPlatform. Initialize is called before live sync in the live…
KristinaKoeva 9e45c5d
Abstract the base service and provide platform dependent implementati…
KristinaKoeva 703e386
Integrate the new live sync + debug logic in the current refactoring
KristinaKoeva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
interface IDebugService { | ||
debug(shouldBreak?: boolean): IFuture<void>; | ||
debugStart(): IFuture<void>; | ||
debugStop?(): IFuture<void> | ||
debugStop(): IFuture<void> | ||
platform: string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ices/livesync/android-livesync-service.ts → ...vesync/android-device-livesync-service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
lib/services/livesync/android-platform-livesync-service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {PlatformLiveSyncServiceBase} from "./platform-livesync-service-base"; | ||
|
||
class AndroidPlatformLiveSyncService extends PlatformLiveSyncServiceBase { | ||
constructor(_liveSyncData: ILiveSyncData, | ||
protected $devicesService: Mobile.IDevicesService, | ||
protected $mobileHelper: Mobile.IMobileHelper, | ||
protected $logger: ILogger, | ||
protected $options: ICommonOptions, | ||
protected $deviceAppDataFactory: Mobile.IDeviceAppDataFactory, | ||
protected $fs: IFileSystem, | ||
protected $injector: IInjector, | ||
protected $projectFilesManager: IProjectFilesManager, | ||
protected $projectFilesProvider: IProjectFilesProvider, | ||
protected $liveSyncProvider: ILiveSyncProvider) { | ||
super(_liveSyncData, $devicesService, $mobileHelper, $logger, $options, $deviceAppDataFactory, $fs, $injector, $projectFilesManager, $projectFilesProvider, $liveSyncProvider); | ||
} | ||
|
||
public fullSync(postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void> { | ||
return (() => { | ||
let appIdentifier = this.liveSyncData.appIdentifier; | ||
let platform = this.liveSyncData.platform; | ||
let projectFilesPath = this.liveSyncData.projectFilesPath; | ||
let canExecute = this.getCanExecuteAction(platform, appIdentifier); | ||
let action = (device: Mobile.IDevice): IFuture<void> => { | ||
return (() => { | ||
let deviceLiveSyncService = this.resolveDeviceSpecificLiveSyncService(platform, device); | ||
let deviceAppData = this.$deviceAppDataFactory.create(appIdentifier, this.$mobileHelper.normalizePlatformName(platform), device); | ||
|
||
deviceLiveSyncService.beforeLiveSyncAction(deviceAppData).wait();; | ||
|
||
let installed = this.tryInstallApplication(device, deviceAppData).wait(); | ||
let localToDevicePaths = this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, null, this.liveSyncData.excludedProjectDirsAndFiles); | ||
let afterSyncAction: () => IFuture<void>; | ||
|
||
if (installed) { | ||
deviceLiveSyncService.afterInstallApplicationAction(deviceAppData, localToDevicePaths).wait(); | ||
afterSyncAction = () => device.applicationManager.tryStartApplication(deviceAppData.appIdentifier); | ||
} else { | ||
this.transferFiles(deviceAppData, localToDevicePaths, this.liveSyncData.projectFilesPath, true).wait(); | ||
afterSyncAction = () => this.refreshApplication(deviceAppData, localToDevicePaths); | ||
} | ||
|
||
if (postAction) { | ||
return postAction(deviceAppData, localToDevicePaths); | ||
} | ||
|
||
return afterSyncAction(); | ||
}).future<void>()(); | ||
}; | ||
this.$devicesService.execute(action, canExecute).wait(); | ||
}).future<void>()(); | ||
} | ||
|
||
protected getCanExecuteActionCore(platform: string, appIdentifier: string): (dev: Mobile.IDevice) => boolean { | ||
return (device: Mobile.IDevice) => true; | ||
} | ||
} | ||
|
||
$injector.register("androidPlatformLiveSyncServiceLocator", {factory: AndroidPlatformLiveSyncService}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export abstract class DeviceLiveSyncServiceBase<T extends Mobile.IDevice> { | ||
protected get device(): T { | ||
return <T>(this._device); | ||
} | ||
|
||
constructor(private _device: Mobile.IDevice, | ||
private $liveSyncProvider: ILiveSyncProvider) { } | ||
|
||
public refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], forceExecuteFullSync: boolean): IFuture<void> { | ||
let canExecuteFastSync = !forceExecuteFullSync && !_.some(localToDevicePaths, (localToDevicePath:any) => !this.$liveSyncProvider.canExecuteFastSync(localToDevicePath.getLocalPath(), deviceAppData.platform)); | ||
|
||
if (canExecuteFastSync) { | ||
return this.reloadPage(deviceAppData); | ||
} | ||
|
||
return this.restartApplication(deviceAppData); | ||
} | ||
|
||
protected abstract restartApplication(deviceAppData: Mobile.IDeviceAppData): IFuture<void>; | ||
protected abstract reloadPage(deviceAppData: Mobile.IDeviceAppData): IFuture<void>; | ||
} |
4 changes: 2 additions & 2 deletions
4
...services/livesync/ios-livesync-service.ts → ...s/livesync/ios-device-livesync-service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import {PlatformLiveSyncServiceBase} from "./platform-livesync-service-base"; | ||
|
||
class IOSPlatformLiveSyncService extends PlatformLiveSyncServiceBase { | ||
constructor(_liveSyncData: ILiveSyncData, | ||
protected $devicesService: Mobile.IDevicesService, | ||
protected $mobileHelper: Mobile.IMobileHelper, | ||
protected $logger: ILogger, | ||
protected $options: ICommonOptions, | ||
protected $deviceAppDataFactory: Mobile.IDeviceAppDataFactory, | ||
protected $fs: IFileSystem, | ||
protected $injector: IInjector, | ||
protected $projectFilesManager: IProjectFilesManager, | ||
protected $projectFilesProvider: IProjectFilesProvider, | ||
protected $liveSyncProvider: ILiveSyncProvider) { | ||
super(_liveSyncData, $devicesService, $mobileHelper, $logger, $options, $deviceAppDataFactory, $fs, $injector, $projectFilesManager, $projectFilesProvider, $liveSyncProvider); | ||
} | ||
|
||
public fullSync(postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void> { | ||
return (() => { | ||
let appIdentifier = this.liveSyncData.appIdentifier; | ||
let platform = this.liveSyncData.platform; | ||
let projectFilesPath = this.liveSyncData.projectFilesPath; | ||
let canExecute = this.getCanExecuteAction(platform, appIdentifier); | ||
|
||
let action = (device: Mobile.IDevice): IFuture<void> => { | ||
return (() => { | ||
let deviceAppData = this.$deviceAppDataFactory.create(appIdentifier, this.$mobileHelper.normalizePlatformName(platform), device); | ||
let installed = this.tryInstallApplication(device, deviceAppData).wait(); | ||
let localToDevicePaths = this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, null, this.liveSyncData.excludedProjectDirsAndFiles); | ||
let afterSyncAction: () => IFuture<void>; | ||
|
||
if(installed) { | ||
afterSyncAction = () => device.applicationManager.tryStartApplication(deviceAppData.appIdentifier); | ||
} else { | ||
this.transferFiles(deviceAppData, localToDevicePaths, this.liveSyncData.projectFilesPath, true).wait(); | ||
afterSyncAction = () => this.refreshApplication(deviceAppData, localToDevicePaths); | ||
} | ||
|
||
if (postAction) { | ||
return postAction(deviceAppData, localToDevicePaths); | ||
} | ||
|
||
return afterSyncAction(); | ||
}).future<void>()(); | ||
}; | ||
this.$devicesService.execute(action, canExecute).wait(); | ||
}).future<void>()(); | ||
} | ||
|
||
protected getCanExecuteActionCore(platform: string, appIdentifier: string): (dev: Mobile.IDevice) => boolean { | ||
if (this.$options.emulator) { | ||
return (device: Mobile.IDevice): boolean => this.$devicesService.isiOSSimulator(device); | ||
} else { | ||
let devices = this.$devicesService.getDevicesForPlatform(platform); | ||
let simulator = _.find(devices, d => this.$devicesService.isiOSSimulator(d)); | ||
if (simulator) { | ||
let iOSDevices = _.filter(devices, d => d.deviceInfo.identifier !== simulator.deviceInfo.identifier); | ||
if (iOSDevices && iOSDevices.length) { | ||
let isApplicationInstalledOnSimulator = simulator.applicationManager.isApplicationInstalled(appIdentifier).wait(); | ||
let isApplicationInstalledOnAllDevices = _.intersection.apply(null, iOSDevices.map(device => device.applicationManager.isApplicationInstalled(appIdentifier).wait())); | ||
// In case the application is not installed on both device and simulator, syncs only on device. | ||
if (!isApplicationInstalledOnSimulator && !isApplicationInstalledOnAllDevices) { | ||
return (device: Mobile.IDevice): boolean => this.$devicesService.isiOSDevice(device); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
$injector.register("iosPlatformLiveSyncServiceLocator", {factory: IOSPlatformLiveSyncService}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the device's platform is not Android, this will return true as well and the Android action will be executed. Is this expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, ignore me, I've noticed it's in
PlatformLiveSyncServiceBase