Skip to content

Commit 3a38e78

Browse files
rosen-vladimirovDimitar Kerezov
authored andcommitted
Add notify event during LiveSync
1 parent 4dfc040 commit 3a38e78

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

PublicAPI.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -684,28 +684,20 @@ tns.liveSyncService.on("error", data => {
684684
});
685685
```
686686
687-
* fileChanged - raised when a watched file is modified. The event is raised witht he following data:
687+
* notify - raised when LiveSync operation has some data that is important for the user. The event is raised for specific device. The event is raised with the following data:
688688
```TypeScript
689689
{
690690
projectDir: string;
691-
/**
692-
* Device identifiers on which the file will be LiveSynced.
693-
*/
694-
deviceIdentifiers: string[];
691+
deviceIdentifier: string;
695692
applicationIdentifier: string;
696-
modifiedFile: string;
697-
698-
/**
699-
* File System event - "add", "addDir", "change", "unlink", "unlinkDir".
700-
*/
701-
event: string;
693+
notification: string;
702694
}
703695
```
704696
705697
Example:
706698
```JavaScript
707-
tns.liveSyncService.on("fileChanged", data => {
708-
console.log(`Detected file changed: ${data.modifiedFile} in ${data.projectDir}. Will start LiveSync operation on ${data.deviceIdentifiers.join(", ")}.`);
699+
tns.liveSyncService.on("notify", data => {
700+
console.log(`Notification: ${notification} for LiveSync operation on ${data.deviceIdentifier} for ${data.projectDir}. `);
709701
});
710702
```
711703

lib/services/livesync/livesync-service.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const LiveSyncEvents = {
88
liveSyncStopped: "liveSyncStopped",
99
liveSyncError: "error",
1010
liveSyncExecuted: "liveSyncExecuted",
11-
liveSyncStarted: "liveSyncStarted"
11+
liveSyncStarted: "liveSyncStarted",
12+
liveSyncNotification: "notify"
1213
};
1314

1415
// TODO: emit events for "successfull livesync", "stoppedLivesync",
@@ -98,7 +99,20 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
9899

99100
protected async refreshApplication(projectData: IProjectData, liveSyncResultInfo: ILiveSyncResultInfo): Promise<void> {
100101
const platformLiveSyncService = this.getLiveSyncService(liveSyncResultInfo.deviceAppData.platform);
101-
await platformLiveSyncService.refreshApplication(projectData, liveSyncResultInfo);
102+
try {
103+
// TODO: Assure we are able to self-restart iOS apps on Windows.
104+
await platformLiveSyncService.refreshApplication(projectData, liveSyncResultInfo);
105+
} catch (err) {
106+
this.$logger.info(`Error while trying to start application ${projectData.projectId} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}. Error is: ${err}`);
107+
const msg = `Unable to start application ${projectData.projectId} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}. Try starting it manually.`;
108+
this.$logger.warn(msg);
109+
this.emit(LiveSyncEvents.liveSyncNotification, {
110+
projectDir: projectData.projectDir,
111+
applicationIdentifier: projectData.projectId,
112+
deviceIdentifier: liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier,
113+
notification: msg
114+
});
115+
}
102116

103117
this.emit(LiveSyncEvents.liveSyncExecuted, {
104118
projectDir: projectData.projectDir,
@@ -187,12 +201,12 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
187201

188202
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor);
189203

190-
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({
191-
projectData, device,
192-
syncAllFiles: liveSyncData.watchAllFiles,
193-
useLiveEdit: liveSyncData.useLiveEdit,
194-
watch: !liveSyncData.skipWatcher
195-
});
204+
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({
205+
projectData, device,
206+
syncAllFiles: liveSyncData.watchAllFiles,
207+
useLiveEdit: liveSyncData.useLiveEdit,
208+
watch: !liveSyncData.skipWatcher
209+
});
196210
await this.refreshApplication(projectData, liveSyncResultInfo);
197211
} catch (err) {
198212
this.$logger.warn(`Unable to apply changes on device: ${err.deviceIdentifier}. Error is: ${err.message}.`);

0 commit comments

Comments
 (0)