зеркало из https://github.com/mozilla/betachannel.git
Detect when apps are already installed. Fixes Issue#47
This commit is contained in:
Родитель
9e4bc46a14
Коммит
3af2b21976
|
@ -36,7 +36,7 @@
|
||||||
<p>Try this on your FirefoxOS device.</p>
|
<p>Try this on your FirefoxOS device.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button data-package-manifest-url="{{version.manifest_url}}" disabled class="install">Install</button>
|
<button data-package-manifest-url="{{version.manifest_url}}" disabled class="install hidden">Install</button>
|
||||||
<h3>Description</h3>
|
<h3>Description</h3>
|
||||||
<p class="app-description">{{version.shortDescription}}</p>
|
<p class="app-description">{{version.shortDescription}}</p>
|
||||||
|
|
||||||
|
|
|
@ -65,16 +65,16 @@ h3 {
|
||||||
|
|
||||||
.version { line-height: 2em; }
|
.version { line-height: 2em; }
|
||||||
|
|
||||||
button.install {
|
button.install, button.launch {
|
||||||
color: #FFF;
|
color: #FFF;
|
||||||
background-color: #42cafe;
|
background-color: #42cafe;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
button.install:hover {
|
button.install:hover, button.launch:hover {
|
||||||
color: #FFF;
|
color: #FFF;
|
||||||
background-color: #67e0fd;
|
background-color: #67e0fd;
|
||||||
}
|
}
|
||||||
button.install:active {
|
button.install:active, button.launch:active {
|
||||||
color: #CBCBCB;
|
color: #CBCBCB;
|
||||||
background-color: #559dbd;
|
background-color: #559dbd;
|
||||||
}
|
}
|
||||||
|
@ -83,4 +83,10 @@ button.install:active {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tinyurl { font-family: monospace; font-size: 1.25em; font-weight: 600; }
|
.tinyurl { font-family: monospace; font-size: 1.25em; font-weight: 600; }
|
||||||
|
|
||||||
|
#needs-mozapps {
|
||||||
|
background-color: #f54b3c;
|
||||||
|
color: #000;
|
||||||
|
padding: 1em;
|
||||||
|
}
|
|
@ -76,4 +76,4 @@ strong {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,47 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
var installedApps = {};
|
||||||
|
|
||||||
var install = document.querySelector('button[data-package-manifest-url]');
|
var install = document.querySelector('button[data-package-manifest-url]');
|
||||||
|
|
||||||
if (install) {
|
if (install) {
|
||||||
if (!navigator.mozApps || !navigator.mozApps.installPackage) {
|
if (!navigator.mozApps || !navigator.mozApps.installPackage || !navigator.mozApps.getInstalled) {
|
||||||
document.getElementById('needs-mozapps').classList.remove('hidden');
|
document.getElementById('needs-mozapps').classList.remove('hidden');
|
||||||
} else {
|
} else {
|
||||||
|
install.classList.remove('hidden');
|
||||||
|
var request = window.navigator.mozApps.getInstalled();
|
||||||
|
request.onerror = function(e) {
|
||||||
|
alert("Error calling getInstalled: " + request.error.name);
|
||||||
|
};
|
||||||
|
request.onsuccess = function(e) {
|
||||||
|
|
||||||
|
for (var i = 0; i < request.result.length; i++) {
|
||||||
|
var manifestURL = request.result[i].manifestURL;
|
||||||
|
installedApps[manifestURL] = request.result[i];
|
||||||
|
$('[data-package-manifest-url="' + manifestURL + '"]')
|
||||||
|
.removeClass('install')
|
||||||
|
.addClass('launch')
|
||||||
|
.text('Launch');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
install.disabled = false;
|
install.disabled = false;
|
||||||
|
|
||||||
install.addEventListener('click', function f(e) {
|
install.addEventListener('click', function f(e) {
|
||||||
var url = install.getAttribute('data-package-manifest-url');
|
var url = install.getAttribute('data-package-manifest-url');
|
||||||
var request = navigator.mozApps.installPackage(url);
|
if ($(install).hasClass('install')) {
|
||||||
request.onsuccess = function() {
|
var request = navigator.mozApps.installPackage(url);
|
||||||
// if (!this.result || !this.result.manifest) {
|
request.onsuccess = function() {
|
||||||
// return alert('Install failed without error');
|
// if (!this.result || !this.result.manifest) {
|
||||||
// }
|
// return alert('Install failed without error');
|
||||||
// TODO replace "install" button with 'installed' widget
|
// }
|
||||||
};
|
// TODO replace "install" button with 'installed' widget
|
||||||
request.onerror = function() {
|
};
|
||||||
alert(this.error.name);
|
request.onerror = function() {
|
||||||
|
alert(this.error.name);
|
||||||
|
}
|
||||||
|
} else if ($(install).hasClass('launch')) {
|
||||||
|
installedApps[url].launch();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче