Skip to content

Universal Windows Platform (uwp) samples using JXcore

Notifications You must be signed in to change notification settings

karaxuna/jxcore-uwp-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

Universal Windows Platform (UWP) samples using JXcore

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.

Build

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

UWP API call examples

First you have to define which namespace you need (Windows in this case):

var uwp = jxcore.uwp;
uwp.projectNamespace("Windows");

Battery status:

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.');
}

Localized date

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);

Reading/writing file in known windows folders, like pictures, documents, videos etc.

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.

Input devices:

// 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.

About

Universal Windows Platform (uwp) samples using JXcore

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published