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

Commit 72c8470

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Send page reload message to android runtime
1 parent bf356cf commit 72c8470

File tree

3 files changed

+97
-107
lines changed

3 files changed

+97
-107
lines changed

declarations.d.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,30 @@ interface IHtmlHelpService {
289289
interface IUsbLiveSyncServiceBase {
290290
initialize(platform: string): IFuture<string>;
291291
isInitialized: boolean;
292-
sync(platform: string, appIdentifier: string, projectFilesPath: string, excludedProjectDirsAndFiles: string[], watchGlob: any,
293-
platformSpecificLiveSyncServices: IDictionary<any>,
294-
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<boolean>,
295-
notRunningiOSSimulatorAction: () => IFuture<boolean>,
296-
localProjectRootPath?: string,
297-
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
298-
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>,
299-
iOSSimulatorRelativeToProjectBasePathAction?: (projectFile: string) => string,
300-
shouldRestartApplication?: (_localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<boolean>): IFuture<void>;
292+
sync(data: ILiveSyncData): IFuture<void>;
293+
}
294+
295+
interface ILiveSyncData {
296+
platform: string;
297+
appIdentifier: string;
298+
projectFilesPath: string;
299+
excludedProjectDirsAndFiles: string[];
300+
watchGlob: any;
301+
platformSpecificLiveSyncServices: IDictionary<any>;
302+
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<boolean>;
303+
notRunningiOSSimulatorAction: () => IFuture<boolean>;
304+
localProjectRootPath?: string;
305+
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>;
306+
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>;
307+
iOSSimulatorRelativeToProjectBasePathAction?: (projectFile: string) => string;
308+
canExecuteFastLiveSync?: (filePath: string) => boolean;
309+
fastLiveSync?: (filePath: string) => IFuture<void>;
310+
}
311+
312+
interface IPlatformSpecificUsbLiveSyncService {
313+
restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void>;
314+
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
315+
sendPageReloadMessageToDevice?(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
301316
}
302317

303318
interface ISysInfoData {

mobile/ios/ios-proxy-services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class AfcFile implements Mobile.IAfcFile {
3535
let afcFileRef = ref.alloc(ref.types.uint64);
3636
this.open = false;
3737

38-
let result = this.$mobileDevice.afcFileRefOpen(afcConnection, path, modeValue, afcFileRef);
38+
let result = this.$mobileDevice.afcFileRefOpen(this.afcConnection, path, modeValue, afcFileRef);
3939
if (result !== 0) {
4040
this.$errors.fail("Unable to open file reference: '%s' with path '%s", result, path);
4141
}
@@ -168,7 +168,7 @@ export class AfcClient implements Mobile.IAfcClient {
168168
this.deleteFile(devicePath);
169169

170170
let target = this.open(devicePath, "w");
171-
let localFilePathSize = this.$fs.getFileSize(localFilePath).wait();
171+
let localFilePathSize = this.$fs.getFileSize(localFilePath).wait();
172172

173173
reader.on("data", (data: NodeBuffer) => {
174174
target.write(data, data.length);

services/usb-livesync-service-base.ts

Lines changed: 71 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
5555
private $localToDevicePathDataFactory: Mobile.ILocalToDevicePathDataFactory,
5656
protected $logger: ILogger,
5757
protected $options: ICommonOptions,
58-
private $deviceAppDataFactory: Mobile.IDeviceAppDataFactory,
58+
protected $deviceAppDataFactory: Mobile.IDeviceAppDataFactory,
5959
private $fs: IFileSystem,
60-
private $dispatcher: IFutureDispatcher,
60+
protected $dispatcher: IFutureDispatcher,
6161
protected $injector: IInjector,
6262
protected $childProcess: IChildProcess,
6363
protected $iOSEmulatorServices: Mobile.IiOSSimulatorService,
6464
protected $hooksService: IHooksService,
65-
private $hostInfo: IHostInfo) { }
65+
protected $hostInfo: IHostInfo) { }
6666

6767
public initialize(platform: string): IFuture<string> {
6868
return (() => {
@@ -78,72 +78,48 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
7878
return this._initialized;
7979
}
8080

81-
public sync(platform: string, appIdentifier: string, projectFilesPath: string, excludedProjectDirsAndFiles: string[], watchGlob: any,
82-
platformSpecificLiveSyncServices: IDictionary<any>,
83-
notInstalledAppOnDeviceAction: (_device1: Mobile.IDevice) => IFuture<boolean>,
84-
notRunningiOSSimulatorAction: () => IFuture<boolean>,
85-
localProjectRootPath?: string,
86-
beforeLiveSyncAction?: (_device2: Mobile.IDevice, _deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
87-
beforeBatchLiveSyncAction?: (_filePath: string) => IFuture<string>,
88-
iOSSimulatorRelativeToProjectBasePathAction?: (projectFile: string) => string,
89-
shouldRestartApplication?: (_localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<boolean>): IFuture<void> {
81+
public sync(data: ILiveSyncData): IFuture<void> {
9082
return (() => {
91-
let platformLowerCase = platform.toLowerCase();
92-
let synciOSSimulator = this.$hostInfo.isDarwin && platformLowerCase === "ios" && (this.$options.emulator || this.$iOSEmulatorServices.isSimulatorRunning().wait());
83+
let synciOSSimulator = this.shouldSynciOSSimulator(data.platform).wait();
9384

9485
if(synciOSSimulator) {
95-
this.$iOSEmulatorServices.sync(appIdentifier, projectFilesPath, notRunningiOSSimulatorAction).wait();
86+
this.$iOSEmulatorServices.sync(data.appIdentifier, data.projectFilesPath, data.notRunningiOSSimulatorAction).wait();
9687
}
9788

98-
if(!this._initialized && (!this.$options.emulator || platform.toLowerCase() === "android")) {
99-
this.initialize(platform).wait();
89+
if(!this._initialized && (!this.$options.emulator || data.platform.toLowerCase() === "android")) {
90+
this.initialize(data.platform).wait();
10091
}
10192

102-
if(!this.$options.emulator || platform.toLowerCase() === "android") {
103-
let projectFiles = this.$fs.enumerateFilesInDirectorySync(projectFilesPath,
104-
(filePath, stat) => !this.isFileExcluded(path.relative(projectFilesPath, filePath), excludedProjectDirsAndFiles, projectFilesPath),
93+
if(!this.$options.emulator || data.platform.toLowerCase() === "android") {
94+
let projectFiles = this.$fs.enumerateFilesInDirectorySync(data.projectFilesPath,
95+
(filePath, stat) => !this.isFileExcluded(path.relative(data.projectFilesPath, filePath), data.excludedProjectDirsAndFiles, data.projectFilesPath),
10596
{ enumerateDirectories: true }
10697
);
10798

108-
this.syncCore(platform,
109-
projectFiles,
110-
appIdentifier,
111-
localProjectRootPath || projectFilesPath,
112-
platformSpecificLiveSyncServices,
113-
notInstalledAppOnDeviceAction,
114-
beforeLiveSyncAction,
115-
shouldRestartApplication
116-
).wait();
99+
this.syncCore(data, projectFiles).wait();
117100
}
118101

119102
if(this.$options.watch) {
103+
120104
let that = this;
121105
this.$hooksService.executeBeforeHooks('watch').wait();
122-
gaze("**/*", { cwd: watchGlob }, function(err: any, watcher: any) {
106+
107+
gaze("**/*", { cwd: data.watchGlob }, function(err: any, watcher: any) {
123108
this.on('all', (event: string, filePath: string) => {
124109
if(event === "added" || event === "changed") {
125-
if(!that.isFileExcluded(filePath, excludedProjectDirsAndFiles, projectFilesPath)) {
110+
if(!that.isFileExcluded(filePath, data.excludedProjectDirsAndFiles, data.projectFilesPath)) {
111+
let canExecuteFastLiveSync = data.canExecuteFastLiveSync && data.canExecuteFastLiveSync(filePath);
112+
126113
if(synciOSSimulator) {
127-
that.batchSimulatorLiveSync(
128-
appIdentifier,
129-
projectFilesPath,
130-
filePath,
131-
notRunningiOSSimulatorAction,
132-
iOSSimulatorRelativeToProjectBasePathAction
133-
);
114+
that.batchSimulatorLiveSync(data, filePath);
115+
}
116+
117+
if( (!that.$options.emulator || data.platform.toLowerCase() === "android") && !canExecuteFastLiveSync) {
118+
that.batchLiveSync(data, filePath);
134119
}
135120

136-
if(!that.$options.emulator || platform.toLowerCase() === "android") {
137-
that.batchLiveSync(
138-
platform,
139-
filePath,
140-
appIdentifier,
141-
localProjectRootPath || projectFilesPath,
142-
platformSpecificLiveSyncServices,
143-
notInstalledAppOnDeviceAction,
144-
beforeLiveSyncAction,
145-
beforeBatchLiveSyncAction
146-
);
121+
if (canExecuteFastLiveSync) {
122+
data.fastLiveSync(filePath);
147123
}
148124
}
149125
}
@@ -155,45 +131,61 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
155131
}).future<void>()();
156132
}
157133

158-
private syncCore(platform: string, projectFiles: string[], appIdentifier: string, projectFilesPath: string,
159-
platformSpecificLiveSyncServices: IDictionary<any>,
160-
notInstalledAppOnDeviceAction: (_device1: Mobile.IDevice) => IFuture<boolean>,
161-
beforeLiveSyncAction?: (_device2: Mobile.IDevice, _deviceAppData1: Mobile.IDeviceAppData) => IFuture<void>,
162-
shouldRestartApplication?: (_localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<boolean>): IFuture<void> {
134+
protected shouldSynciOSSimulator(platform: string): IFuture<boolean> {
163135
return (() => {
164-
platform = platform ? this.$mobileHelper.normalizePlatformName(platform) : this.$devicesService.platform;
165-
let deviceAppData = this.$deviceAppDataFactory.create(appIdentifier, platform);
166-
let localToDevicePaths = _(projectFiles)
167-
.map(projectFile => this.getProjectFileInfo(projectFile))
168-
.filter(projectFileInfo => projectFileInfo.shouldIncludeFile)
169-
.map(projectFileInfo => this.$localToDevicePathDataFactory.create(projectFileInfo.fileName, projectFilesPath, projectFileInfo.onDeviceName, deviceAppData.deviceProjectRootPath))
170-
.value();
136+
return this.$hostInfo.isDarwin && platform.toLowerCase() === "ios" && (this.$options.emulator || this.$iOSEmulatorServices.isSimulatorRunning().wait());
137+
}).future<boolean>()();
138+
}
139+
140+
protected createLocalToDevicePaths(platform: string, appIdentifier: string, projectFilesPath: string, projectFiles: string[]): Mobile.ILocalToDevicePathData[] {
141+
let deviceAppData = this.$deviceAppDataFactory.create(appIdentifier, this.$mobileHelper.normalizePlatformName(platform));
142+
let localToDevicePaths = _(projectFiles)
143+
.map(projectFile => this.getProjectFileInfo(projectFile))
144+
.filter(projectFileInfo => projectFileInfo.shouldIncludeFile)
145+
.map(projectFileInfo => this.$localToDevicePathDataFactory.create(projectFileInfo.fileName, projectFilesPath, projectFileInfo.onDeviceName, deviceAppData.deviceProjectRootPath))
146+
.value();
147+
148+
return localToDevicePaths;
149+
}
150+
151+
protected transferFiles(device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> {
152+
return (() => {
153+
this.$logger.info("Transferring project files...");
154+
device.fileSystem.transferFiles(deviceAppData.appIdentifier, localToDevicePaths).wait();
155+
this.$logger.info("Successfully transferred all project files.");
156+
}).future<void>()();
157+
}
158+
159+
private syncCore(data: ILiveSyncData, projectFiles: string[]): IFuture<void> {
160+
return (() => {
161+
let platform = data.platform ? this.$mobileHelper.normalizePlatformName(data.platform) : this.$devicesService.platform;
162+
let deviceAppData = this.$deviceAppDataFactory.create(data.appIdentifier, this.$mobileHelper.normalizePlatformName(data.platform));
163+
let localToDevicePaths = this.createLocalToDevicePaths(data.platform, data.appIdentifier, data.localProjectRootPath || data.projectFilesPath, projectFiles);
164+
165+
console.log(localToDevicePaths[0]);
171166

172167
let action = (device: Mobile.IDevice) => {
173168
return (() => {
174169
if(deviceAppData.isLiveSyncSupported(device).wait()) {
175170

176-
if(beforeLiveSyncAction) {
177-
beforeLiveSyncAction(device, deviceAppData).wait();
171+
if(data.beforeLiveSyncAction) {
172+
data.beforeLiveSyncAction(device, deviceAppData).wait();
178173
}
179174

180175
let applications = device.applicationManager.getInstalledApplications().wait();
181176
if(!_.contains(applications, deviceAppData.appIdentifier)) {
182177
this.$logger.warn(`The application with id "${deviceAppData.appIdentifier}" is not installed on the device yet.`);
183-
if (!notInstalledAppOnDeviceAction(device).wait()) {
178+
if (!data.notInstalledAppOnDeviceAction(device).wait()) {
184179
return;
185180
}
186181
}
187182

188-
this.$logger.info("Transferring project files...");
189-
device.fileSystem.transferFiles(deviceAppData.appIdentifier, localToDevicePaths).wait();
190-
this.$logger.info("Successfully transferred all project files.");
183+
this.transferFiles(device, deviceAppData, localToDevicePaths).wait();
184+
185+
this.$logger.info("Applying changes...");
186+
let platformSpecificLiveSyncService = this.resolvePlatformSpecificLiveSyncService(platform, device, data.platformSpecificLiveSyncServices);
187+
platformSpecificLiveSyncService.restartApplication(deviceAppData, localToDevicePaths).wait();
191188

192-
if (shouldRestartApplication && shouldRestartApplication(localToDevicePaths).wait()) {
193-
this.$logger.info("Applying changes...");
194-
let platformSpecificLiveSyncService = this.resolvePlatformSpecificLiveSyncService(platform, device, platformSpecificLiveSyncServices);
195-
platformSpecificLiveSyncService.restartApplication(deviceAppData, localToDevicePaths).wait();
196-
}
197189
this.$logger.info(`Successfully synced application ${deviceAppData.appIdentifier}.`);
198190
}
199191
}).future<void>()();
@@ -205,46 +197,29 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
205197

206198
private batch: SyncBatch = null;
207199

208-
private batchLiveSync(platform: string, filePath: string, appIdentifier: string, projectFilesPath: string,
209-
platformSpecificLiveSyncServices: IDictionary<any>,
210-
notInstalledAppOnDeviceAction: (_device: Mobile.IDevice) => IFuture<boolean>,
211-
beforeLiveSyncAction?: (_device1: Mobile.IDevice, _deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
212-
beforeBatchLiveSyncAction?: (_filePath: string) => IFuture<string>) : void {
200+
private batchLiveSync(data: ILiveSyncData, filePath: string) : void {
213201
if (!this.batch || !this.batch.syncPending) {
214202
this.batch = new SyncBatch(
215203
this.$logger, this.$dispatcher, (filesToSync) => {
216-
this.preparePlatformForSync(platform);
217-
this.syncCore(
218-
platform,
219-
filesToSync,
220-
appIdentifier,
221-
projectFilesPath,
222-
platformSpecificLiveSyncServices,
223-
notInstalledAppOnDeviceAction,
224-
beforeLiveSyncAction
225-
).wait();
204+
this.preparePlatformForSync(data.platform);
205+
this.syncCore(data, filesToSync).wait();
226206
}
227207
);
228208
}
229209

230210
this.$dispatcher.dispatch( () => (() => {
231-
let fileToSync = beforeBatchLiveSyncAction ? beforeBatchLiveSyncAction(filePath).wait() : filePath;
211+
let fileToSync = data.beforeBatchLiveSyncAction ? data.beforeBatchLiveSyncAction(filePath).wait() : filePath;
232212
if(fileToSync) {
233213
this.batch.addFile(fileToSync);
234214
}
235215
}).future<void>()());
236216
}
237217

238-
private batchSimulatorLiveSync(
239-
appIdentifier: string,
240-
projectFilesPath: string,
241-
filePath: string,
242-
notRunningiOSSimulatorAction: () => IFuture<boolean>,
243-
iOSSimulatorRelativeToProjectBasePathAction:(projectFile: string) => string): void {
218+
private batchSimulatorLiveSync(data: ILiveSyncData, filePath: string): void {
244219
if (!this.batch || !this.batch.syncPending) {
245220
this.batch = new SyncBatch(
246221
this.$logger, this.$dispatcher, (filesToSync) => {
247-
this.$iOSEmulatorServices.syncFiles(appIdentifier, projectFilesPath, filesToSync, notRunningiOSSimulatorAction, iOSSimulatorRelativeToProjectBasePathAction);
222+
this.$iOSEmulatorServices.syncFiles(data.appIdentifier, data.projectFilesPath, filesToSync, data.notRunningiOSSimulatorAction, data.iOSSimulatorRelativeToProjectBasePathAction);
248223
}
249224
);
250225
}
@@ -288,7 +263,7 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
288263
return undefined;
289264
}
290265

291-
private resolvePlatformSpecificLiveSyncService(platform: string, device: Mobile.IDevice, platformSpecificLiveSyncServices: IDictionary<any>): IPlatformSpecificLiveSyncService {
266+
protected resolvePlatformSpecificLiveSyncService(platform: string, device: Mobile.IDevice, platformSpecificLiveSyncServices: IDictionary<any>): IPlatformSpecificUsbLiveSyncService {
292267
return this.$injector.resolve(platformSpecificLiveSyncServices[platform.toLowerCase()], {_device: device});
293268
}
294269
}

0 commit comments

Comments
 (0)