Skip to content

Commit

Permalink
Add support for iOS 12.2 (#118)
Browse files Browse the repository at this point in the history
* Add support for iOS 12.2

* Address comments and clean up a little
  • Loading branch information
imurchie authored Mar 15, 2019
1 parent 57c35e0 commit 31739b4
Show file tree
Hide file tree
Showing 13 changed files with 630 additions and 451 deletions.
11 changes: 0 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ env:
- _FORCE_LOGS=1
matrix:
include:
- osx_image: xcode8.3
node_js: "8"
env: COVERALLS=1
- osx_image: xcode8.3
node_js: "10"

- osx_image: xcode9.4
node_js: "8"
- osx_image: xcode9.4
node_js: "10"

- osx_image: xcode10
node_js: "8"
- osx_image: xcode10
Expand Down
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
32 changes: 15 additions & 17 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 All @@ -12,11 +12,11 @@ const WEB_CONTENT_BUNDLE_ID = 'com.apple.WebKit.WebContent';
* dictionary whose keys are understandable
*/
function appInfoFromDict (dict) {
let id = dict.WIRApplicationIdentifierKey;
let isProxy = _.isString(dict.WIRIsApplicationProxyKey)
const id = dict.WIRApplicationIdentifierKey;
const isProxy = _.isString(dict.WIRIsApplicationProxyKey)
? dict.WIRIsApplicationProxyKey.toLowerCase() === 'true'
: dict.WIRIsApplicationProxyKey;
let entry = {
const entry = {
id,
isProxy,
name: dict.WIRApplicationNameKey,
Expand All @@ -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,21 +112,19 @@ 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);

// now we need to determine if we should pick a proxy for this instead
if (appId) {
proxiedAppIds.push(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}'`);
proxiedAppIds.push(key);
}
}
if (proxiedAppIds.length === 0) {
proxiedAppIds = [appId];
}
}
} else {
if (_.has(appDict, bundleId)) {
Expand All @@ -139,7 +137,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 +161,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 +188,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 +198,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].pageArray) {
if (this.appDict[appIdKey].pageArray.resolve) {
// pageDict is a pending promise, so resolve
this.appDict[appIdKey].pageArray.resolve();
} else {
// we have a pre-existing pageDict
if (_.isEqual(cleanPageArray(this.appDict[appIdKey].pageArray), cleanPageArray(pageArray))) {
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].pageArray = 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

0 comments on commit 31739b4

Please sign in to comment.