Browse Source

Moved global vars to config

master
Igor Zhukov 11 years ago
parent
commit
a740015dff
  1. 14
      app/js/app.js
  2. 5
      app/js/controllers.js
  3. 8
      app/js/directives.js
  4. 38
      app/js/lib/config.js
  5. 22
      app/js/lib/mtproto.js
  6. 2
      app/js/services.js
  7. 2
      app/partials/settings_modal.html
  8. 14
      gulpfile.js

14
app/js/app.js

@ -7,17 +7,9 @@
'use strict'; 'use strict';
window._testMode = location.search.indexOf('test=1') > 0; $(document.body)
window._debugMode = location.search.indexOf('debug=1') > 0; .addClass(Config.Navigator.osX ? 'osx' : 'non_osx')
window._osX = (navigator.platform || '').toLowerCase().indexOf('mac') != -1 || .addClass(Config.Navigator.retina ? 'is_2x' : 'is_1x');
(navigator.userAgent || '').toLowerCase().indexOf('mac') != -1;
window._retina = window.devicePixelRatio > 1;
window._mobile = $(window).height() < 600;
if (!window._osX) {
$('body').addClass('non_osx');
}
$('body').addClass(window._retina ? 'is_2x' : 'is_1x');
$(window).on('load', function () { $(window).on('load', function () {
setTimeout(function () { setTimeout(function () {

5
app/js/controllers.js

@ -130,8 +130,8 @@ angular.module('myApp.controllers', [])
MtpApiManager.invokeApi('auth.sendCode', { MtpApiManager.invokeApi('auth.sendCode', {
phone_number: $scope.credentials.phone_full, phone_number: $scope.credentials.phone_full,
sms_type: 0, sms_type: 0,
api_id: 2496, api_id: Config.App.id,
api_hash: '8da85b0d5bfe62527e5b244c209159c3' api_hash: Config.App.hash
}, options).then(function (sentCode) { }, options).then(function (sentCode) {
$scope.progress.enabled = false; $scope.progress.enabled = false;
@ -1411,6 +1411,7 @@ angular.module('myApp.controllers', [])
$scope.profile = {}; $scope.profile = {};
$scope.photo = {}; $scope.photo = {};
$scope.version = Config.App.version;
MtpApiManager.getUserID().then(function (id) { MtpApiManager.getUserID().then(function (id) {
$scope.profile = AppUsersManager.getUser(id); $scope.profile = AppUsersManager.getUser(id);

8
app/js/directives.js

@ -540,7 +540,7 @@ angular.module('myApp.directives', ['myApp.filters'])
$(richTextarea).on('DOMNodeInserted', onPastedImageEvent); $(richTextarea).on('DOMNodeInserted', onPastedImageEvent);
} }
if (!window._mobile) { if (!Config.Navigator.mobile) {
$scope.$on('ui_peer_change', focusField); $scope.$on('ui_peer_change', focusField);
$scope.$on('ui_history_focus', focusField); $scope.$on('ui_history_focus', focusField);
$scope.$on('ui_history_change', focusField); $scope.$on('ui_history_change', focusField);
@ -560,7 +560,7 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
}); });
if (!window._mobile) { if (!Config.Navigator.mobile) {
focusField(); focusField();
} }
@ -1020,7 +1020,7 @@ angular.module('myApp.directives', ['myApp.filters'])
.directive('myFocused', function(){ .directive('myFocused', function(){
return { return {
link: function($scope, element, attrs) { link: function($scope, element, attrs) {
if (window._mobile) { if (Config.Navigator.mobile) {
return false; return false;
} }
setTimeout(function () { setTimeout(function () {
@ -1034,7 +1034,7 @@ angular.module('myApp.directives', ['myApp.filters'])
return { return {
link: function($scope, element, attrs) { link: function($scope, element, attrs) {
$scope.$on(attrs.myFocusOn, function () { $scope.$on(attrs.myFocusOn, function () {
if (window._mobile) { if (Config.Navigator.mobile) {
return false; return false;
} }
onContentLoaded(function () { onContentLoaded(function () {

38
app/js/lib/config.js

File diff suppressed because one or more lines are too long

22
app/js/lib/mtproto.js

@ -442,7 +442,7 @@ function TLSerialization (options) {
this.createBuffer(); this.createBuffer();
// this.debug = options.debug !== undefined ? options.debug : window._debugMode; // this.debug = options.debug !== undefined ? options.debug : Config.Modes.debug;
this.mtproto = options.mtproto || false; this.mtproto = options.mtproto || false;
return this; return this;
} }
@ -726,7 +726,7 @@ function TLDeserialization (buffer, options) {
this.intView = new Uint32Array(this.buffer); this.intView = new Uint32Array(this.buffer);
this.byteView = new Uint8Array(this.buffer); this.byteView = new Uint8Array(this.buffer);
// this.debug = options.debug !== undefined ? options.debug : window._debugMode; // this.debug = options.debug !== undefined ? options.debug : Config.Modes.debug;
this.mtproto = options.mtproto || false; this.mtproto = options.mtproto || false;
return this; return this;
} }
@ -1003,7 +1003,7 @@ TLDeserialization.prototype.fetchEnd = function () {
if (typeof angular != 'undefined') angular.module('mtproto.services', ['myApp.services']). if (typeof angular != 'undefined') angular.module('mtproto.services', ['myApp.services']).
factory('MtpDcConfigurator', function () { factory('MtpDcConfigurator', function () {
var dcOptions = window._testMode var dcOptions = Config.Modes.test
? [ ? [
{id: 1, host: '173.240.5.253', port: 80}, {id: 1, host: '173.240.5.253', port: 80},
{id: 2, host: '149.154.167.40', port: 80}, {id: 2, host: '149.154.167.40', port: 80},
@ -1753,7 +1753,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
body: serializer.getBytes() body: serializer.getBytes()
}; };
if (window._debugMode) { if (Config.Modes.debug) {
console.log(dT(), 'MT call', method, params, messageID, seqNo); console.log(dT(), 'MT call', method, params, messageID, seqNo);
} }
@ -1774,7 +1774,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
body: serializer.getBytes() body: serializer.getBytes()
}; };
if (window._debugMode) { if (Config.Modes.debug) {
console.log(dT(), 'MT message', object, messageID, seqNo); console.log(dT(), 'MT message', object, messageID, seqNo);
} }
@ -1787,10 +1787,10 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
if (!this.connectionInited) { if (!this.connectionInited) {
serializer.storeInt(0x2b9b08fa, 'invokeWithLayer14'); serializer.storeInt(0x2b9b08fa, 'invokeWithLayer14');
serializer.storeInt(0x69796de9, 'initConnection'); serializer.storeInt(0x69796de9, 'initConnection');
serializer.storeInt(2496, 'api_id'); serializer.storeInt(Config.App.id, 'api_id');
serializer.storeString(navigator.userAgent || 'Unknown UserAgent', 'device_model'); serializer.storeString(navigator.userAgent || 'Unknown UserAgent', 'device_model');
serializer.storeString(navigator.platform || 'Unknown Platform', 'system_version'); serializer.storeString(navigator.platform || 'Unknown Platform', 'system_version');
serializer.storeString('0.1.2', 'app_version'); serializer.storeString(Config.App.version, 'app_version');
serializer.storeString(navigator.language || 'en', 'lang_code'); serializer.storeString(navigator.language || 'en', 'lang_code');
} }
@ -1810,7 +1810,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
isAPI: true isAPI: true
}; };
if (window._debugMode) { if (Config.Modes.debug) {
console.log(dT(), 'Api call', method, params, messageID, seqNo, options); console.log(dT(), 'Api call', method, params, messageID, seqNo, options);
} else { } else {
console.log(dT(), 'Api call', method, messageID, seqNo); console.log(dT(), 'Api call', method, messageID, seqNo);
@ -2075,7 +2075,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
this.sentMessages[message.msg_id] = containerSentMessage; this.sentMessages[message.msg_id] = containerSentMessage;
if (window._debugMode) { if (Config.Modes.debug) {
console.log(dT(), 'Container', innerMessages, message.msg_id, message.seq_no); console.log(dT(), 'Container', innerMessages, message.msg_id, message.seq_no);
} }
} else { } else {
@ -2091,7 +2091,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
this.sendEncryptedRequest(message).then(function (result) { this.sendEncryptedRequest(message).then(function (result) {
self.toggleOffline(false); self.toggleOffline(false);
self.parseResponse(result.data).then(function (response) { self.parseResponse(result.data).then(function (response) {
if (window._debugMode) { if (Config.Modes.debug) {
console.log(dT(), 'Server response', self.dcID, response); console.log(dT(), 'Server response', self.dcID, response);
} }
@ -2483,7 +2483,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
} }
} else { } else {
if (deferred) { if (deferred) {
if (window._debugMode) { if (Config.Modes.debug) {
console.log(dT(), 'Rpc response', message.result); console.log(dT(), 'Rpc response', message.result);
} else { } else {
console.log(dT(), 'Rpc response', message.result._); console.log(dT(), 'Rpc response', message.result._);

2
app/js/services.js

@ -12,7 +12,7 @@
angular.module('myApp.services', []) angular.module('myApp.services', [])
.service('AppConfigManager', function ($q) { .service('AppConfigManager', function ($q) {
var testPrefix = window._testMode ? 't_' : ''; var testPrefix = Config.Modes.test ? 't_' : '';
var cache = {}; var cache = {};
var useCs = !!(window.chrome && chrome.storage && chrome.storage.local); var useCs = !!(window.chrome && chrome.storage && chrome.storage.local);
var useLs = !useCs && !!window.localStorage; var useLs = !useCs && !!window.localStorage;

2
app/partials/settings_modal.html

@ -102,7 +102,7 @@
<div class="modal_section"> <div class="modal_section">
<h3 class="modal_section_header">About</h3> <h3 class="modal_section_header">About</h3>
<div class="modal_section_body"> <div class="modal_section_body">
<p><strong>Webogram</strong> v0.1.2, <a href="https://github.com/zhukov/webogram" target="_blank">GitHub</a></p> <p><strong>Webogram</strong> v{{version}}, <a href="https://github.com/zhukov/webogram" target="_blank">GitHub</a></p>
</div> </div>
</div> </div>

14
gulpfile.js

@ -84,15 +84,9 @@ gulp.task('update-version-manifests', function() {
.pipe(gulp.dest('app')); .pipe(gulp.dest('app'));
}); });
gulp.task('update-version-settings', function() { gulp.task('update-version-config', function() {
return gulp.src('app/partials/settings_modal.html') return gulp.src('app/js/lib/config.js')
.pipe($.replace(/\bv[\d\.]+\b/, 'v' + pj.version)) .pipe($.replace(/version: '.*?'/, 'version: \'' + pj.version + '\''))
.pipe(gulp.dest('app/partials'));
});
gulp.task('update-version-mtproto', function() {
return gulp.src('app/js/lib/mtproto.js')
.pipe($.replace(/'.+?', 'app_version'/, '\'' + pj.version + '\', \'app_version\''))
.pipe(gulp.dest('app/js/lib')); .pipe(gulp.dest('app/js/lib'));
}); });
@ -168,7 +162,7 @@ gulp.task('clean', function() {
return gulp.src(['dist/*', 'app/js/templates.js', '!dist/.git']).pipe($.clean()); return gulp.src(['dist/*', 'app/js/templates.js', '!dist/.git']).pipe($.clean());
}); });
gulp.task('bump', ['update-version-manifests', 'update-version-settings', 'update-version-mtproto'], function () { gulp.task('bump', ['update-version-manifests', 'update-version-config'], function () {
gulp.start('update-version-comments'); gulp.start('update-version-comments');
}); });

Loading…
Cancel
Save