Skip to content

Instantly share code, notes, and snippets.

View seksenov's full-sized avatar

Kiril Seksenov seksenov

  • Salesforce
  • Seattle
View GitHub Profile
@seksenov
seksenov / cortana.html
Last active May 28, 2022 21:51
Cortana integration from a hosted web app on Windows. To do this you'll need a meta tag in your html page pointint to an xml voice command definition file on your server. You'll also need to handle the Cortana activation event in your JavaScript.
<!DOCTYPE html>
<html>
<head>
<title>Cortana Example</title>
<!--Cortana meta tag pointing to VCD file on the server-->
<meta name="msapplication-cortanavcd" content="https://mysite.com/vcd.xml"/>
</head>
<body>
</body>
function setAppBarColors(brandColorHex, brandColorInactiveHex) {
// Detect if the Windows namespace exists in the global object
if (typeof Windows !== 'undefined') {
var brandColor = hexStrToRGBA(brandColorHex);
var brandColorInactive = hexStrToRGBA(brandColorInactiveHex);
// Get a reference to the App Title Bar
var appTitleBar = Windows.UI.ViewManagement.ApplicationView.getForCurrentView().titleBar;
var black = hexStrToRGBA('#000');
var white = hexStrToRGBA('#FFF');
Platform and invoked when a user utters them to Cortana. Here’s the VCD file used in the sample:
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="MediaSample">
<CommandPrefix>Contoso Video</CommandPrefix>
<Example>Contoso video play elephants</Example>
<Command Name="play">
<Example>play {message} using media sample</Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase">please play {streamSubject}</ListenFor>
<Feedback>playing {streamSubject} with Stream Demo</Feedback>
@seksenov
seksenov / windowsNotification.js
Last active October 21, 2016 08:34
JavaScript function that displays a toast notification in Universal Windows Apps. For Web Apps, Hosted Web Apps and WebView with Windows Runtume Access.
function showToast () {
if(typeof Windows !== undefined) {
var notifications = Windows.UI.Notifications;
var template = notifications.ToastTemplateType.toastImageAndText01;
var toastXml = notifications.ToastNotificationManager.getTemplateContent(template);
var toastTextElements = toastXml.getElementsByTagName("text");
toastTextElements[0].appendChild(toastXml.createTextNode("Toast from Codepen"));
var toastImageElements = toastXml.getElementsByTagName("image");
toastImageElements[0].setAttribute("src", "http://assets.codepen.io/assets/social/facebook-default.png");
toastImageElements[0].setAttribute("alt", "red graphic");
function updateTile(message, imgUrl, imgAlt) {
// Namespace: Windows.UI.Notifications
if (typeof Windows !== 'undefined'&&
typeof Windows.UI !== 'undefined' &&
typeof Windows.UI.Notifications !== 'undefined') {
var notifications = Windows.UI.Notifications,
tile = notifications.TileTemplateType.tileSquare150x150PeekImageAndText01,
tileContent = notifications.TileUpdateManager.getTemplateContent(tile),
tileText = tileContent.getElementsByTagName('text'),
@seksenov
seksenov / changeAppTitleBarColors.js
Created December 10, 2015 23:51 — forked from Gr8Gatsby/changeAppTitleBarColors.js
This Gist shows how to set the application titlebar colors. There is a helper function that accepts an HTML hexString and converts it to an RGBA color object for Windows.
/*
This function expects two hexStrings and relies on hexStrToRGBA to convert
to a JSON object that represents RGBA for the underlying Windows API to
understand.
Examples of valid values:
setAppBarColors('#FFFFFF','#000000');
setAppBarColors('#FFF','#000');
setAppBarColors('FFFFFF','000000');
setAppBarColors('FFF','000');
var appView = Windows.UI.ViewManagement.ApplicationView.getForCurrentView();
// toggle the desiredBoundsMode between useVisible (10% black border) and useCoreWindow (entire screen)
appView.setDesiredBoundsMode(appView.desiredBoundsMode === Windows.UI.ViewManagement.ApplicationViewBoundsMode.useCoreWindow ?
Windows.UI.ViewManagement.ApplicationViewBoundsMode.useVisible :
Windows.UI.ViewManagement.ApplicationViewBoundsMode.useCoreWindow);
function showToast () {
console.log("yo");
var notifications = Windows.UI.Notifications,
templateType = notifications.ToastTemplateType.toastImageAndText02,
templateContent = notifications.ToastNotificationManager.getTemplateContent(templateType),
toastMessage = templateContent.getElementsByTagName('text'),
toastImage = templateContent.getElementsByTagName('image'),
toastElement = templateContent.selectSingleNode('/toast');
console.log("here");
if (typeof Windows !== 'undefined') {
// Subscribe to the Windows Activation Event
Windows.UI.WebUI.WebUIApplication.addEventListener("activated", function (args) {
var activation = Windows.ApplicationModel.Activation;
// Check to see if the app was activated by a voice command
if (args.kind === activation.ActivationKind.voiceCommand) {
var speechRecognitionResult = args.result;
var textSpoken = speechRecognitionResult.text;
// Determine the command type {play} defined in vcd
if (speechRecognitionResult.rulePath[0] === "play") {