Skip to content
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

Add support for iOS 12.2 #118

Merged
merged 2 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/atoms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
const atomsCache = {};

async function getAtoms (atomName) {
let atomFileName = __filename.indexOf('build/lib/atoms') !== -1 ?
const atomFileName = __filename.includes('build/lib/atoms') ?
path.resolve(__dirname, '..', '..', 'atoms', `${atomName}.js`) :
path.resolve(__dirname, '..', 'atoms', `${atomName}.js`);

Expand Down
23 changes: 12 additions & 11 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import log from './logger';
import getAtom from './atoms';
import _ from 'lodash';
import assert from 'assert';
import Promise from 'bluebird';
import B from 'bluebird';


const WEB_CONTENT_BUNDLE_ID = 'com.apple.WebKit.WebContent';
Expand Down Expand Up @@ -39,7 +39,7 @@ function pageArrayFromDict (pageDict) {
return [pageDict];
}
let newPageArray = [];
for (let dict of _.values(pageDict)) {
for (const dict of _.values(pageDict)) {
// count only WIRTypeWeb pages and ignore all others (WIRTypeJavaScript etc)
if (_.isUndefined(dict.WIRTypeKey) || dict.WIRTypeKey === 'WIRTypeWeb') {
newPageArray.push({
Expand All @@ -60,7 +60,7 @@ function pageArrayFromDict (pageDict) {
function getDebuggerAppKey (bundleId, platformVersion, appDict) {
let appId;
if (parseFloat(platformVersion) >= 8) {
for (let [key, data] of _.toPairs(appDict)) {
for (const [key, data] of _.toPairs(appDict)) {
if (data.bundleId === bundleId) {
appId = key;
break;
Expand All @@ -70,7 +70,7 @@ function getDebuggerAppKey (bundleId, platformVersion, appDict) {
if (appId) {
log.debug(`Found app id key '${appId}' for bundle '${bundleId}'`);
let proxiedAppIds = [];
for (let [key, data] of _.toPairs(appDict)) {
for (const [key, data] of _.toPairs(appDict)) {
if (data.isProxy && data.hostId === appId) {
log.debug(`Found separate bundleId '${data.bundleId}' ` +
`acting as proxy for '${bundleId}', with app id '${key}'`);
Expand All @@ -94,7 +94,7 @@ function getDebuggerAppKey (bundleId, platformVersion, appDict) {

function appIdForBundle (bundleId, appDict) {
let appId;
for (let [key, data] of _.toPairs(appDict)) {
for (const [key, data] of _.toPairs(appDict)) {
if (data.bundleId === bundleId) {
appId = key;
break;
Expand All @@ -112,12 +112,13 @@ function appIdForBundle (bundleId, appDict) {
function getPossibleDebuggerAppKeys (bundleId, platformVersion, appDict) {
let proxiedAppIds = [];
if (parseFloat(platformVersion) >= 8) {
let appId = appIdForBundle(bundleId, appDict);
const appId = appIdForBundle(bundleId, appDict);
proxiedAppIds.push(appId);
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved

// now we need to determine if we should pick a proxy for this instead
if (appId) {
log.debug(`Found app id key '${appId}' for bundle '${bundleId}'`);
for (let [key, data] of _.toPairs(appDict)) {
for (const [key, data] of _.toPairs(appDict)) {
if (data.isProxy && data.hostId === appId) {
log.debug(`Found separate bundleId '${data.bundleId}' ` +
`acting as proxy for '${bundleId}', with app id '${key}'`);
Expand All @@ -139,7 +140,7 @@ function getPossibleDebuggerAppKeys (bundleId, platformVersion, appDict) {

function checkParams (params) {
let errors = [];
for (let [param, value] of _.toPairs(params)) {
for (const [param, value] of _.toPairs(params)) {
try {
assert.ok(value);
} catch (err) {
Expand All @@ -163,7 +164,7 @@ async function getScriptForAtom (atom, args, frames, asyncCallBack = null) {
let script;
if (frames.length > 0) {
script = atomSrc;
for (let frame of frames) {
for (const frame of frames) {
script = await wrapScriptForFrame(script, frame);
}
} else {
Expand All @@ -190,7 +191,7 @@ function simpleStringify (value) {
// we get back objects sometimes with string versions of functions
// which muddy the logs
let cleanValue = _.clone(value);
for (let property of ['ceil', 'clone', 'floor', 'round', 'scale', 'toString']) {
for (const property of ['ceil', 'clone', 'floor', 'round', 'scale', 'toString']) {
delete cleanValue[property];
}
return JSON.stringify(cleanValue);
Expand All @@ -200,7 +201,7 @@ function deferredPromise () {
// http://bluebirdjs.com/docs/api/deferred-migration.html
let resolve;
let reject;
let promise = new Promise((res, rej) => { // eslint-disable-line promise/param-names
const promise = new B((res, rej) => { // eslint-disable-line promise/param-names
resolve = res;
reject = rej;
});
Expand Down
46 changes: 40 additions & 6 deletions lib/message-handlers.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
import log from './logger';
import { RemoteDebugger } from './remote-debugger';
import { pageArrayFromDict, getDebuggerAppKey, simpleStringify } from './helpers';
import _ from 'lodash';


/*
* Generic callbacks used throughout the lifecycle of the Remote Debugger.
* These will be added to the prototype.
*/


/**
* Remove the `isKey` property from the page array, since it does not affect
* equality
*/
function cleanPageArray (arr) {
return _.map(arr, (el) => _.pick(el, 'id', 'title', 'url'));
}

function onPageChange (appIdKey, pageDict) {
const pageArray = pageArrayFromDict(pageDict);

// save the page dict for this app
if (this.appDict[appIdKey]) {
if (this.appDict[appIdKey].pageDict && this.appDict[appIdKey].pageDict.resolve) {
// pageDict is a promise, so resolve
this.appDict[appIdKey].pageDict.resolve(pageDict);
if (this.appDict[appIdKey].pageDict) {
if (this.appDict[appIdKey].pageDict.resolve) {
// pageDict is a promise, so resolve
this.appDict[appIdKey].pageDict.resolve(pageArray);
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
} else {
// we have a pre-existing pageDict
if (_.isEqual(cleanPageArray(this.appDict[appIdKey].pageDict), cleanPageArray(pageArray))) {
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
log.debug(`Received page change notice for app '${appIdKey}' ` +
`but the listing has not changed. Ignoring.`);
return;
}
}
}
// keep track of the page dictionary
this.appDict[appIdKey].pageDict = pageArrayFromDict(pageDict);
this.appDict[appIdKey].pageDict = pageArray;
}

// only act if this is the correct app
Expand All @@ -25,10 +47,12 @@ function onPageChange (appIdKey, pageDict) {
return;
}



log.debug(`Page changed: ${simpleStringify(pageDict)}`);
this.emit(RemoteDebugger.EVENT_PAGE_CHANGE, {
appIdKey: appIdKey.replace('PID:', ''),
pageArray: pageArrayFromDict(pageDict)
pageArray,
});
}

Expand Down Expand Up @@ -64,7 +88,7 @@ function onAppDisconnect (dict) {

function onAppUpdate (dict) {
let appIdKey = dict.WIRApplicationIdentifierKey;
log.debug(`Notified that application '${appIdKey}' has been updated.`);
log.debug(`Notified that application '${appIdKey}' has been updated`);

this.updateAppsWithDict(dict);
}
Expand All @@ -73,12 +97,22 @@ function onReportDriverList (dict) {
log.debug(`Notified of connected drivers: ${JSON.stringify(dict.WIRDriverDictionaryKey)}.`);
}

function onTargetCreated (app, targetInfo) {
log.debug(`Target created: ${app} ${JSON.stringify(targetInfo)}`);
}

function onTargetDestroyed (app, targetInfo) {
log.debug(`Target destroyed: ${app} ${JSON.stringify(targetInfo)}`);
}

const messageHandlers = {
onPageChange,
onAppConnect,
onAppDisconnect,
onAppUpdate,
onReportDriverList,
onTargetCreated,
onTargetDestroyed,
};

export default messageHandlers;
Loading