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

0.2.0 Support enumerating, launching, installing to Windows 10 Mobile Emulators #27

Merged
merged 3 commits into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ bin/wptool.exe
bin/wstool.exe
wptool/bin
wptool/obj
wptool/.vs
wptool/wptool.sln
wstool/bin
wstool/obj
test/TestApp/Bin
test/TestApp/obj
.idea
test/TestApp10.0/Bin
test/TestApp10.0/obj
test/TestApp10.0/AppPackages
test/TestApp10.0/Debug
test/TestApp10.0/Release
test/TestApp10.0/Generated Files
.idea
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.2.0 (12/10/2015)
-------------------
* Add custom tooling for Win 10 mobile.
* Support enumerating, launching and installing apps to Win 10 Mobile emulators

0.1.22 (12/4/2015)
-------------------
* Fix: Windows 10 Mobile detection #26
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ windowslib.device.detect(function (err, devices) {
```javascript
var deviceUDID = null; // string or null to pick first device

windowslib.device.install(deviceUDID, 'C:\\path\\to\\zapfile.zap')
windowslib.device.install(deviceUDID, 'C:\\path\\to\\appfile.appx')
.on('installed', function () {
console.log('App successfully installed on device');
})
Expand All @@ -86,7 +86,7 @@ windowslib.emulator.launch(null, function (err, handle) {
```javascript
var udid = null; // string or null to pick an emulator

windowslib.emulator.install(udid, 'C:\\path\\to\\zapfile.zap')
windowslib.emulator.install(udid, 'C:\\path\\to\\appfile.appx')
.on('launched', function (msg) {
console.log('Emulator has launched');
})
Expand Down
18 changes: 18 additions & 0 deletions bin/wp_get_appx_metadata.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$AppPackagePath = $Args[0]

$shell = new-object -com shell.application
$item = get-item $AppPackagePath
$zipFilePath = $item.FullName + ".zip"

$directory = $item.Directory.FullName
Copy-Item $item $zipFilePath
$manifest = @{ "Name" = "AppxManifest.xml" }
$manifest.Path = Join-Path $directory $manifest.Name
$manifest.File = $shell.NameSpace($zipFilePath).Items() | ? { $_.Name -eq $manifest.Name }
$shell.Namespace($directory).CopyHere($manifest.File)
$manifest.Xml = [xml](get-content $manifest.Path)

Remove-Item $zipFilePath
Remove-Item $manifest.Path

$manifest.Xml.Package.Identity.Name
86 changes: 14 additions & 72 deletions lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ function detect(options, callback) {
* Tries to connect to the specified device and will error if there are no devices connected
* or there are more than one connected devices.
*
* @param {String} udid - The UDID of the device to install the app to or null if you want windowslib to pick one.
* @param {String} appPath - The path to the Windows Phone app to install.
* @param {String} udid - The UDID of the device to connect to or null if you want windowslib to pick one.
* @param {Object} [options] - An object containing various settings.
* @param {Boolean} [options.bypassCache=false] - When true, re-detects the environment configuration.
* @param {Function} [callback(err)] - A function to call when the simulator has launched.
Expand All @@ -100,14 +99,11 @@ function connect(udid, options, callback) {
* @param {Object} [options] - An object containing various settings.
* @param {Boolean} [options.bypassCache=false] - When true, re-detects the environment configuration.
* @param {Number} [options.timeout] - Number of milliseconds to wait before timing out. Minimum of 1000 milliseconds.
* @param {String} [options.wpsdk] - The Windows Phone SDK to use for the XAP deploy tool. If not specified, it will autodetect.
* @param {String} [options.wpsdk] - The Windows Phone SDK to use for the deploy tool. If not specified, it will autodetect.
* @param {Function} [callback(err)] - A function to call when the simulator has launched.
*
* ?????????????????????????????????????????????????????????????????? @emits module:device#app-quit
* ?????????????????????????????????????????????????????????????????? @emits module:device#app-started
* @emits module:device#error
* @emits module:device#installed
* ?????????????????????????????????????????????????????????????????? @emits module:device#log
*
* @returns {EventEmitter}
*/
Expand Down Expand Up @@ -186,72 +182,18 @@ function install(udid, appPath, options, callback) {
})
.on('connected', function () {
// device is good to go, install the app!
windowsphone.detect(options, function (err, results) {
if (err) {
emitter.emit('error', err);
return callback(err);
}

var wpsdk = options.wpsdk;
if (!wpsdk) {
// find any version that is supported and has a XAP deploy tool
Object.keys(results.windowsphone).some(function (ver) {
if (results.windowsphone[ver].supported && results.windowsphone[ver].deployCmd) {
wpsdk = ver;
return true;
}
});
}

if (!wpsdk || !results.windowsphone[wpsdk] || !results.windowsphone[wpsdk].deployCmd) {
var ex = new Error(__('Unable to find a valid Windows Phone installation that is supported and has a XAP deploy tool'));
emitter.emit('error', ex);
return callback(ex);
}

var timeout = options.timeout !== void 0 && Math.max(~~options.timeout, 1000), // minimum of 1 second
cmd = results.windowsphone[wpsdk].deployCmd,
args = [
'/installlaunch',
appPath,
'/targetdevice:' + devHandle.index
],
child = spawn(cmd, args),
out = '',
timer = null;

child.stdout.on('data', function (data) {
out += data.toString();
});

child.stderr.on('data', function (data) {
out += data.toString();
});

child.on('close', function (code) {
clearTimeout(timer);

if (code) {
var errmsg = out.trim().split(/\r\n|\n/).shift(),
ex = new Error(/^Error: /.test(errmsg) ? errmsg.substring(7) : __('Failed to install app (code %s)', code));
emitter.emit('error', ex);
callback(ex);
} else {
emitter.emit('installed', devHandle);
callback(null, devHandle);
}
});

if (timeout) {
timer = setTimeout(function () {
// abort the install
child.kill();

var ex = new Error(__('Timed out after %d milliseconds waiting to launch the device.', timeout));
emitter.emit('timeout', ex);
callback(ex);
}, timeout);
}
var timeout = options.timeout !== void 0 && Math.max(~~options.timeout, 1000); // minimum of 1 second
wptool.install(devHandle, appPath, appc.util.mix({timeout: timeout}, options))
.on('error', function (err) {
emitter.emit('error', err);
callback(err);
}).on('launched', function () {
emitter.emit('installed', devHandle);
callback(null, devHandle);
}).on('timeout', function (err) {
err || (err = new Error(__('Timed out after %d milliseconds waiting to launch the device.', timeout)));
emitter.emit('timeout', err);
callback(err);
});
});
});
Expand Down