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

9
app/js/init.js

@ -1,4 +1,13 @@
;(function initApplication () { ;(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 = [ var classes = [
Config.Navigator.osX ? 'osx' : 'non_osx', Config.Navigator.osX ? 'osx' : 'non_osx',
Config.Navigator.msie ? 'msie' : 'non_msie', Config.Navigator.msie ? 'msie' : 'non_msie',

1
app/js/lib/push_worker.js

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

2
app/js/lib/tl_utils.js

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

5
app/js/messages_manager.js

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

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

@ -1,13 +1,4 @@
;(function initAutoUpgrade () { ;(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) { window.safeConfirm = function (params, callback) {
if (typeof params === 'string') { if (typeof params === 'string') {
params = {message: params} params = {message: params}
@ -21,7 +12,9 @@
setTimeout(function () {callback(result)}, 10) 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 return
} }
@ -40,7 +33,7 @@
if (navigator.serviceWorker) { if (navigator.serviceWorker) {
// If available, use a Service Worker to handle offlining. // 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') console.log('offline worker registered')
registration.addEventListener('updatefound', function () { registration.addEventListener('updatefound', function () {
var installingWorker = this.installing var installingWorker = this.installing

2
app/js/services.js

@ -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 = {} var inlineResults = {}
return { return {

1
app/manifest.json

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

2
app/service_worker.js

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

67
gulpfile.js

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

8
package.json

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

Loading…
Cancel
Save