With UWP API you can use Windows specific methods such as detecting devices connected or reading files from special folders etc.
JXcore is fork of nodejs and supports multiple JavaScript engines. If you build it with chakra engine on Windows 10 and Visual Studio 2015, you will be able to use UWP API.
Clone JXcore code from repository:
git clone https://github.com/jxcore/jxcore.git
Build with chakra engine:
vcbuild.bat --engine-chakra
After successfull build, you will have jxcore executable available in Release/jx.exe
.
To run samples, cd to samples directory and run:
<path-to-jxcore>/Release/jx.exe index.js
First you have to define which namespace you need (Windows
in this case):
var uwp = jxcore.uwp;
uwp.projectNamespace("Windows");
var batteryStatus = Windows.System.Power.PowerManager.batteryStatus;
var batteryStatusEnum = Windows.System.Power.BatteryStatus;
if (batteryStatus === batteryStatusEnum.notPresent) {
console.log('The battery or battery controller is not present.');
} else if (batteryStatus === batteryStatusEnum.discharging) {
console.log('The battery is discharging.');
} else if (batteryStatus === batteryStatusEnum.idle) {
console.log('The battery is idle.');
} else if (batteryStatus === batteryStatusEnum.charging) {
console.log('The battery is charging.');
}
var date = new Windows.Globalization.Calendar(['ka-ge']);
var localized = [
date.eraAsString() + ' ' + date.yearAsString(),
date.dayOfWeekAsString(),
date.dayAsString() + ' ' + date.monthAsString()
].join(', ');
console.log('Localized date:', localized);
console.log('Number of days in current month:', date.numberOfDaysInThisMonth);
Windows.Storage.KnownFolders.picturesLibrary.createFileAsync('sample.png',
Windows.Storage.CreationCollisionOption.replaceExisting).done(function () {
// created succesfully
}, function (err) {
// handle error
});
*Methods that end with Async
are asynchronous and return promise.
// check if mouse is present
var mouseCapabilities = new Windows.Devices.Input.MouseCapabilities();
if (!mouseCapabilities.mousePresent) {
console.log('Mouse is present');
} else {
console.log('Mouse is not present');
}
// check if keyboard is present
var keyboardCapabilities = new Windows.Devices.Input.KeyboardCapabilities();
if (!mouseCapabilities.keyboardPresent) {
console.log('Keyboard is present');
} else {
console.log('Keyboard is not present');
}
After completing all the calls you have to call uwp.close()
to release uwp or the process won't finish.
You can find more information about Windows API here.