Telegram Web, preconfigured for usage in I2P.
http://web.telegram.i2p/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.6 KiB
86 lines
2.6 KiB
9 years ago
|
;(function initAutoUpgrade () {
|
||
9 years ago
|
window.safeConfirm = function (params, callback) {
|
||
|
if (typeof params === 'string') {
|
||
9 years ago
|
params = {message: params}
|
||
9 years ago
|
}
|
||
|
var result = false
|
||
|
try {
|
||
9 years ago
|
result = confirm(params.message)
|
||
9 years ago
|
} catch (e) {
|
||
9 years ago
|
result = true
|
||
9 years ago
|
}
|
||
9 years ago
|
setTimeout(function () {callback(result)}, 10)
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
if ((!navigator.serviceWorker && !window.applicationCache) ||
|
||
|
Config.Modes.packed ||
|
||
|
!window.addEventListener) {
|
||
9 years ago
|
return
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
var declined = false
|
||
|
function updateFound () {
|
||
9 years ago
|
if (!declined) {
|
||
|
safeConfirm({type: 'WEBOGRAM_UPDATED_RELOAD', message: 'A new version of Webogram is downloaded. Launch it?'}, function (result) {
|
||
|
if (result) {
|
||
9 years ago
|
window.location.reload()
|
||
9 years ago
|
} else {
|
||
9 years ago
|
declined = true
|
||
9 years ago
|
}
|
||
9 years ago
|
})
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
if (navigator.serviceWorker) {
|
||
|
// If available, use a Service Worker to handle offlining.
|
||
8 years ago
|
navigator.serviceWorker.register('service_worker.js').then(function (registration) {
|
||
9 years ago
|
console.log('offline worker registered')
|
||
|
registration.addEventListener('updatefound', function () {
|
||
|
var installingWorker = this.installing
|
||
9 years ago
|
|
||
|
// Wait for the new service worker to be installed before prompting to update.
|
||
9 years ago
|
installingWorker.addEventListener('statechange', function () {
|
||
9 years ago
|
switch (installingWorker.state) {
|
||
|
case 'installed':
|
||
|
// Only show the prompt if there is currently a controller so it is not
|
||
|
// shown on first load.
|
||
|
if (navigator.serviceWorker.controller) {
|
||
9 years ago
|
updateFound()
|
||
9 years ago
|
}
|
||
9 years ago
|
break
|
||
9 years ago
|
|
||
|
case 'redundant':
|
||
9 years ago
|
console.error('The installing service worker became redundant.')
|
||
|
break
|
||
9 years ago
|
}
|
||
9 years ago
|
})
|
||
|
})
|
||
|
})
|
||
9 years ago
|
} else {
|
||
|
// Otherwise, use AppCache.
|
||
9 years ago
|
var appCache = window.applicationCache
|
||
|
var updateTimeout = false
|
||
|
var scheduleUpdate = function (delay) {
|
||
|
clearTimeout(updateTimeout)
|
||
|
updateTimeout = setTimeout(function () {
|
||
|
try {
|
||
|
appCache.update()
|
||
|
} catch (ex) {
|
||
|
console.log('appCache.update: ' + ex)
|
||
|
}
|
||
|
}, delay || 300000)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
scheduleUpdate(3000)
|
||
9 years ago
|
window.addEventListener('load', function () {
|
||
|
appCache.addEventListener('updateready', function () {
|
||
|
if (appCache.status == appCache.UPDATEREADY) {
|
||
9 years ago
|
updateFound()
|
||
9 years ago
|
}
|
||
9 years ago
|
}, false)
|
||
|
appCache.addEventListener('noupdate', function () {scheduleUpdate()}, false)
|
||
|
appCache.addEventListener('error', function () {scheduleUpdate()}, false)
|
||
|
})
|
||
9 years ago
|
}
|
||
9 years ago
|
})()
|