Browse Source

Added push worker

master
Igor Zhukov 9 years ago
parent
commit
3a283f5494
  1. 6
      app/index.html
  2. 9
      app/js/init.js
  3. 1
      app/js/lib/push_worker.js
  4. 2
      app/js/lib/tl_utils.js
  5. 5
      app/js/messages_manager.js
  6. 15
      app/js/offline_manager.js
  7. 2
      app/js/services.js
  8. 1
      app/manifest.json
  9. 2
      app/service_worker.js
  10. 67
      gulpfile.js
  11. 8
      package.json

6
app/index.html

@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
<link rel="stylesheet" href="css/app.css"/>
<!-- endbuild -->
<link rel="manifest" href="manifest.json"/>
<style>
html {
display: none;
@ -55,8 +57,9 @@ @@ -55,8 +57,9 @@
<script type="text/javascript" src="vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="js/lib/config.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="vendor/jquery.nanoscroller/nanoscroller.js"></script>
<script type="text/javascript" src="js/offline_manager.js"></script>
<script type="text/javascript" src="vendor/jquery.nanoscroller/nanoscroller.js"></script>
<script type="text/javascript" src="vendor/angular/angular.js"></script>
<script type="text/javascript" src="vendor/angular/angular-route.js"></script>
<script type="text/javascript" src="vendor/angular/angular-animate.js"></script>
@ -89,7 +92,6 @@ @@ -89,7 +92,6 @@
<script type="text/javascript" src="js/controllers.js"></script>
<script type="text/javascript" src="js/filters.js"></script>
<script type="text/javascript" src="js/messages_manager.js"></script>
<script type="text/javascript" src="js/offline-manager.js"></script>
<!--PRODUCTION_ONLY_BEGIN
<script type="text/javascript" src="js/templates.js"></script>

9
app/js/init.js

@ -1,4 +1,13 @@ @@ -1,4 +1,13 @@
;(function initApplication () {
// Prevent click-jacking
try {
if (window == window.top || window.chrome && chrome.app && chrome.app.window) {
document.documentElement.style.display = 'block'
} else {
top.location = self.location
}
} catch (e) {console.error('CJ protection', e) }
var classes = [
Config.Navigator.osX ? 'osx' : 'non_osx',
Config.Navigator.msie ? 'msie' : 'non_msie',

1
app/js/lib/push_worker.js

@ -0,0 +1 @@ @@ -0,0 +1 @@
console.log('push worker')

2
app/js/lib/tl_utils.js

@ -444,7 +444,7 @@ TLDeserialization.prototype.fetchBytes = function (field) { @@ -444,7 +444,7 @@ TLDeserialization.prototype.fetchBytes = function (field) {
var len = this.byteView[this.offset++]
if (len == 254) {
var len = this.byteView[this.offset++] |
len = this.byteView[this.offset++] |
(this.byteView[this.offset++] << 8) |
(this.byteView[this.offset++] << 16)
}

5
app/js/messages_manager.js

@ -494,7 +494,7 @@ angular.module('myApp.services') @@ -494,7 +494,7 @@ angular.module('myApp.services')
var reqPeerID = peerID
if (migratedToFrom[peerID]) {
isMigrated = true
if (maxID && maxID < fullMsgIDModulus) {
if (maxID && maxID < AppMessagesIDsManager.fullMsgIDModulus) {
reqPeerID = migratedToFrom[peerID]
}
}
@ -3151,7 +3151,8 @@ angular.module('myApp.services') @@ -3151,7 +3151,8 @@ angular.module('myApp.services')
getFullMessageID: getFullMessageID,
getMessageIDInfo: getMessageIDInfo,
getMessageLocalID: getMessageLocalID,
splitMessageIDsByChannels: splitMessageIDsByChannels
splitMessageIDsByChannels: splitMessageIDsByChannels,
fullMsgIDModulus: fullMsgIDModulus
}
function getFullMessageID (msgID, channelID) {

15
app/js/offline-manager.js → app/js/offline_manager.js

@ -1,13 +1,4 @@ @@ -1,13 +1,4 @@
;(function initAutoUpgrade () {
// Prevent click-jacking
try {
if (window == window.top || window.chrome && chrome.app && chrome.app.window) {
document.documentElement.style.display = 'block'
} else {
top.location = self.location
}
} catch (e) {console.error('CJ protection', e) }
window.safeConfirm = function (params, callback) {
if (typeof params === 'string') {
params = {message: params}
@ -21,7 +12,9 @@ @@ -21,7 +12,9 @@
setTimeout(function () {callback(result)}, 10)
}
if ((!navigator.serviceWorker && !window.applicationCache) || Config.Modes.packed || !window.addEventListener) {
if ((!navigator.serviceWorker && !window.applicationCache) ||
Config.Modes.packed ||
!window.addEventListener) {
return
}
@ -40,7 +33,7 @@ @@ -40,7 +33,7 @@
if (navigator.serviceWorker) {
// If available, use a Service Worker to handle offlining.
navigator.serviceWorker.register('offline-worker.js').then(function (registration) {
navigator.serviceWorker.register('service_worker.js').then(function (registration) {
console.log('offline worker registered')
registration.addEventListener('updatefound', function () {
var installingWorker = this.installing

2
app/js/services.js

@ -2393,7 +2393,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2393,7 +2393,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
})
.service('AppInlineBotsManager', function (qSync, $q, $rootScope, toaster, Storage, ErrorService, MtpApiManager, AppMessagesManager, AppDocsManager, AppPhotosManager, RichTextProcessor, AppUsersManager, AppPeersManager, PeersSelectService, GeoLocationManager) {
.service('AppInlineBotsManager', function (qSync, $q, $rootScope, toaster, Storage, ErrorService, MtpApiManager, AppMessagesManager, AppMessagesIDsManager, AppDocsManager, AppPhotosManager, RichTextProcessor, AppUsersManager, AppPeersManager, PeersSelectService, GeoLocationManager) {
var inlineResults = {}
return {

1
app/manifest.json

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
"unlimitedStorage",
"fullscreen"
],
"gcm_sender_id": "122867383838",
"icons": {
"16": "img/icons/icon16.png",
"32": "img/icons/icon32.png",

2
app/service_worker.js

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
// 111
importScripts('js/lib/push_worker.js')

67
gulpfile.js

@ -1,17 +1,12 @@ @@ -1,17 +1,12 @@
var packageJson = require('./package.json')
var gulp = require('gulp')
var $ = require('gulp-load-plugins')({lazy: false})
var es = require('event-stream')
var pj = require('./package.json')
var $ = require('gulp-load-plugins')()
var path = require('path')
var http = require('http')
var livereload = require('gulp-livereload')
var st = require('st')
var less = require('gulp-less')
var del = require('del')
var runSequence = require('run-sequence')
var oghliner = require('oghliner')
var gulpServiceWorker = require('gulp-serviceworker')
var standard = require('gulp-standard')
// The generated file is being created at src
// so it can be fetched by usemin.
@ -44,7 +39,7 @@ gulp.task('imagemin', function () { @@ -44,7 +39,7 @@ gulp.task('imagemin', function () {
gulp.task('less', function () {
gulp.src('app/less/*.less')
.pipe(less({
.pipe($.less({
paths: [path.join(__dirname, 'less', 'includes')]
}))
.pipe(gulp.dest('app/css'))
@ -52,8 +47,8 @@ gulp.task('less', function () { @@ -52,8 +47,8 @@ gulp.task('less', function () {
gulp.task('standard', function () {
gulp.src(['app/**/*.js', '!app/vendor/**/*', 'gulpfile.js'])
.pipe(standard())
.pipe(standard.reporter('default', {
.pipe($.standard())
.pipe($.standard.reporter('default', {
breakOnError: true
}))
})
@ -96,7 +91,7 @@ gulp.task('copy-locales', function () { @@ -96,7 +91,7 @@ gulp.task('copy-locales', function () {
var langpackSrc = []
var ngSrc = []
pj.locales.forEach(function (locale) {
packageJson.locales.forEach(function (locale) {
langpackSrc.push('app/js/locales/' + locale + '.json')
ngSrc.push('app/vendor/angular/i18n/angular-locale_' + locale + '.js')
})
@ -110,7 +105,7 @@ gulp.task('copy-locales', function () { @@ -110,7 +105,7 @@ gulp.task('copy-locales', function () {
gulp.task('compress-dist', ['build'], function () {
return gulp.src('**/*', {cwd: path.join(process.cwd(), '/dist')})
.pipe($.zip('webogram_v' + pj.version + '.zip'))
.pipe($.zip('webogram_v' + packageJson.version + '.zip'))
.pipe(gulp.dest('releases'))
})
@ -118,21 +113,21 @@ gulp.task('cleanup-dist', ['compress-dist'], function () { @@ -118,21 +113,21 @@ gulp.task('cleanup-dist', ['compress-dist'], function () {
return del(['releases/**/*', '!releases/*.zip'])
})
gulp.task('update-version-manifests', function () {
gulp.task('bump-version-manifests', function () {
return gulp.src(['app/manifest.webapp', 'app/manifest.json'])
.pipe($.replace(/"version": ".*",/, '"version": "' + pj.version + '",'))
.pipe($.replace(/"version": ".*",/, '"version": "' + packageJson.version + '",'))
.pipe(gulp.dest('app'))
})
gulp.task('update-version-config', function () {
gulp.task('bump-version-config', function () {
return gulp.src('app/js/lib/config.js')
.pipe($.replace(/version: '.*?'/, "version: '" + pj.version + "'"))
.pipe($.replace(/version: '.*?'/, "version: '" + packageJson.version + "'"))
.pipe(gulp.dest('app/js/lib'))
})
gulp.task('update-version-comments', function () {
gulp.task('bump-version-comments', function () {
return gulp.src('app/**/*.js')
.pipe($.replace(/Webogram v[0-9.]*/, 'Webogram v' + pj.version))
.pipe($.replace(/Webogram v[0-9.]*/, 'Webogram v' + packageJson.version))
.pipe(gulp.dest('app'))
})
@ -171,11 +166,20 @@ var fileGlobs = [ @@ -171,11 +166,20 @@ var fileGlobs = [
'!dist/js/background.js'
]
gulp.task('generate-service-worker', ['build'], function () {
return gulp.src(fileGlobs)
.pipe(gulpServiceWorker({
rootDir: 'dist/'
}))
function writeServiceWorkerFile (rootDir, handleFetch, callback) {
var config = {
cacheId: packageJson.name,
handleFetch: handleFetch,
logger: $.util.log,
staticFileGlobs: fileGlobs,
stripPrefix: rootDir + '/',
verbose: true
}
swPrecache.write(path.join(rootDir, 'service_worker.js'), config, callback)
}
gulp.task('generate-service-worker', ['build'], function (callback) {
writeServiceWorkerFile('dist', true, callback)
})
gulp.task('add-appcache-manifest', ['build'], function () {
@ -226,16 +230,16 @@ gulp.task('package-dev', function () { @@ -226,16 +230,16 @@ gulp.task('package-dev', function () {
gulp.task('watchcss', function () {
gulp.src('app/css/*.css')
.pipe(livereload())
.pipe($.livereload())
})
gulp.task('watchhtml', function () {
gulp.src('app/partials/**/*.html')
.pipe(livereload())
.pipe($.livereload())
})
gulp.task('watch', ['server', 'less'], function () {
livereload.listen({ basePath: 'app' })
$.livereload.listen({ basePath: 'app' })
gulp.watch('app/css/*.css', ['watchcss'])
gulp.watch('app/less/**/*.less', ['less'])
gulp.watch('app/partials/**/*.html', ['watchhtml'])
@ -251,8 +255,8 @@ gulp.task('clean', function () { @@ -251,8 +255,8 @@ gulp.task('clean', function () {
return del(['dist/*', 'app/js/templates.js', 'app/css/*', '!dist/.git'])
})
gulp.task('bump', ['update-version-manifests', 'update-version-config'], function () {
gulp.start('update-version-comments')
gulp.task('bump', ['bump-version-manifests', 'bump-version-config'], function () {
gulp.start('bump-version-comments')
})
gulp.task('build', ['clean'], function (callback) {
@ -268,10 +272,9 @@ gulp.task('package', ['cleanup-dist']) @@ -268,10 +272,9 @@ gulp.task('package', ['cleanup-dist'])
gulp.task('offline', ['add-appcache-manifest', 'generate-service-worker'])
gulp.task('deploy', ['offline'], function () {
return oghliner.deploy({
rootDir: 'dist/'
})
gulp.task('deploy', function () {
return gulp.src('./dist/**/*')
.pipe($.ghPages())
})
gulp.task('default', ['build'])

8
package.json

@ -46,10 +46,11 @@ @@ -46,10 +46,11 @@
"gulp": "^3.9.0",
"gulp-angular-templatecache": "^1.1.0",
"gulp-concat": "^2.1.7",
"gulp-gh-pages": "^0.5.4",
"gulp-grep-stream": "0.0.2",
"gulp-imagemin": "^2.3.0",
"gulp-less": "^3.0.5",
"gulp-livereload": "^3.0.2",
"gulp-livereload": "^3.8.1",
"gulp-load-plugins": "^0.4.0",
"gulp-manifest": "0.0.3",
"gulp-minify-css": "^0.3.12",
@ -61,11 +62,12 @@ @@ -61,11 +62,12 @@
"gulp-standard": "^7.0.1",
"gulp-uglify": "^1.0.2",
"gulp-usemin": "^0.3.11",
"gulp-util": "^3.0.7",
"gulp-zip": "^0.1.2",
"http": "0.0.0",
"oghliner": "^1.0.1",
"run-sequence": "^1.0.2",
"st": "^0.5.2"
"st": "^0.5.2",
"sw-precache": "^3.2.0"
},
"standard": {
"globals": [

Loading…
Cancel
Save