forked from jeromeetienne/threex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreex.chromeWebStoreInstall.js
45 lines (39 loc) · 1.34 KB
/
threex.chromeWebStoreInstall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// This THREEx helper makes it easy to handle chrome.webstore.install API.
// * api description http://code.google.com/chrome/webstore/docs/inline_installation.html
// * paul kinlan post on g+ https://plus.google.com/116059998563577101552/posts/c9zYiA9RdC5
//
// # Code
//
/** @namespace */
var THREEx = THREEx || {};
THREEx.ChromeWebStoreInstall = THREEx.ChromeWebStoreInstall || {};
/**
* test if the API is available
* @returns {Boolean} true if the API is available, false otherwise
*/
THREEx.ChromeWebStoreInstall.apiAvailable = function()
{
var available = typeof chrome !== 'undefined' && chrome.webstore && chrome.webstore.install;
return available ? true : false;
}
/**
* Test if the application is already installed
*
* @returns {Boolean} true if the application is installed, false otherwise
*/
THREEx.ChromeWebStoreInstall.isInstalled = function()
{
if( !this.apiAvailable() ) return false;
return chrome.app.isInstalled ? true : false;
}
/**
* Trigger an installation
* @param {String} url of the application (optional)
* @param {Function} callback called if installation succeed
* @param {Function} callback called if installation failed
*/
THREEx.ChromeWebStoreInstall.install = function(url, successCallback, failureCallback)
{
console.assert( this.apiAvailable() )
chrome.webstore.install(url, successCallback, failureCallback);
}