xdl
Version:
The Expo Development Library
127 lines (122 loc) • 3.83 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.InstallationProxyClient = void 0;
function _debug() {
const data = _interopRequireDefault(require("debug"));
_debug = function () {
return data;
};
return data;
}
function _lockdown() {
const data = require("../protocol/lockdown");
_lockdown = function () {
return data;
};
return data;
}
function _client() {
const data = require("./client");
_client = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2021 Expo, Inc.
* Copyright (c) 2018 Drifty Co.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const debug = (0, _debug().default)('expo:xdl:ios:lib:client:installation_proxy');
/*
* [{ "PercentComplete": 5, "Status": "CreatingStagingDirectory" }]
* ...
* [{ "PercentComplete": 90, "Status": "GeneratingApplicationMap" }]
* [{ "CFBundleIdentifier": "my.company.app" }]
* [{ "Status": "Complete" }]
*/
/*
* [{
* LookupResult: IPLookupResult,
* Status: "Complete"
* }]
*/
function isIPLookupResponse(resp) {
return resp.length && resp[0].LookupResult !== undefined;
}
function isIPInstallPercentCompleteResponse(resp) {
return resp.length && resp[0].PercentComplete !== undefined;
}
function isIPInstallCFBundleIdentifierResponse(resp) {
return resp.length && resp[0].CFBundleIdentifier !== undefined;
}
function isIPInstallCompleteResponse(resp) {
return resp.length && resp[0].Status === 'Complete';
}
class InstallationProxyClient extends _client().ServiceClient {
constructor(socket) {
super(socket, new (_lockdown().LockdownProtocolClient)(socket));
this.socket = socket;
}
async lookupApp(bundleIds, options = {
ReturnAttributes: ['Path', 'Container', 'CFBundleExecutable', 'CFBundleIdentifier'],
ApplicationsType: 'Any'
}) {
debug(`lookupApp, options: ${JSON.stringify(options)}`);
let resp = await this.protocolClient.sendMessage({
Command: 'Lookup',
ClientOptions: {
BundleIDs: bundleIds,
...options
}
});
if (resp && !Array.isArray(resp)) resp = [resp];
if (isIPLookupResponse(resp)) {
return resp[0].LookupResult;
} else {
throw new (_client().ResponseError)(`There was an error looking up app`, resp);
}
}
async installApp(packagePath, bundleId, options = {
ApplicationsType: 'Any',
PackageType: 'Developer'
}, onProgress) {
debug(`installApp, packagePath: ${packagePath}, bundleId: ${bundleId}`);
return this.protocolClient.sendMessage({
Command: 'Install',
PackagePath: packagePath,
ClientOptions: {
CFBundleIdentifier: bundleId,
...options
}
}, (resp, resolve, reject) => {
if (resp && !Array.isArray(resp)) resp = [resp];
if (isIPInstallCompleteResponse(resp)) {
onProgress({
isComplete: true,
progress: 100,
status: resp[0].Status
});
resolve();
} else if (isIPInstallPercentCompleteResponse(resp)) {
onProgress({
isComplete: false,
progress: resp[0].PercentComplete,
status: resp[0].Status
});
debug(`Installation status: ${resp[0].Status}, %${resp[0].PercentComplete}`);
} else if (isIPInstallCFBundleIdentifierResponse(resp)) {
debug(`Installed app: ${resp[0].CFBundleIdentifier}`);
} else {
reject(new (_client().ResponseError)('There was an error installing app: ' + require('util').inspect(resp), resp));
}
});
}
}
exports.InstallationProxyClient = InstallationProxyClient;
//# sourceMappingURL=installation_proxy.js.map
;