Skip to content

Instantly share code, notes, and snippets.

@slorber
Last active February 9, 2020 11:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save slorber/ea1e77f78192eb2832f4ce9fdd5eb7bc to your computer and use it in GitHub Desktop.
Save slorber/ea1e77f78192eb2832f4ce9fdd5eb7bc to your computer and use it in GitHub Desktop.
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
setupShareTarget();
},
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
app.initialize();
function setupShareTarget() {
console.debug("setupShareTarget");
var shareOperation = null;
function shareReady(args) {
console.debug("shareReady");
if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.uri)) {
console.debug("shareOperation");
shareOperation.data.getUriAsync().done(function (uri) {
console.debug("getUriAsync");
});
}
}
WinJS.Application.onactivated = function (args) {
console.debug("onactivated");
if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
console.debug("launch");
args.setPromise(WinJS.UI.processAll());
}
else if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.shareTarget) {
console.debug("share target");
args.setPromise(WinJS.UI.processAll());
shareOperation = args.detail.shareOperation;
WinJS.Application.addEventListener("shareready", shareReady, false);
WinJS.Application.queueEvent({ type: "shareready" });
}
else {
console.debug("else");
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment