From a740015dff0da55f603d792c2aaafdf3ca5478ca Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 3 Jun 2014 15:08:26 +0400 Subject: [PATCH] Moved global vars to config --- app/js/app.js | 14 +++--------- app/js/controllers.js | 5 +++-- app/js/directives.js | 8 +++---- app/js/lib/config.js | 38 +++++++++++++++++++++++++++++++- app/js/lib/mtproto.js | 22 +++++++++--------- app/js/services.js | 2 +- app/partials/settings_modal.html | 2 +- gulpfile.js | 14 ++++-------- 8 files changed, 64 insertions(+), 41 deletions(-) diff --git a/app/js/app.js b/app/js/app.js index 875e89e3..ad79f198 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -7,17 +7,9 @@ 'use strict'; -window._testMode = location.search.indexOf('test=1') > 0; -window._debugMode = location.search.indexOf('debug=1') > 0; -window._osX = (navigator.platform || '').toLowerCase().indexOf('mac') != -1 || - (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'); +$(document.body) + .addClass(Config.Navigator.osX ? 'osx' : 'non_osx') + .addClass(Config.Navigator.retina ? 'is_2x' : 'is_1x'); $(window).on('load', function () { setTimeout(function () { diff --git a/app/js/controllers.js b/app/js/controllers.js index 991944be..ec3df507 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -130,8 +130,8 @@ angular.module('myApp.controllers', []) MtpApiManager.invokeApi('auth.sendCode', { phone_number: $scope.credentials.phone_full, sms_type: 0, - api_id: 2496, - api_hash: '8da85b0d5bfe62527e5b244c209159c3' + api_id: Config.App.id, + api_hash: Config.App.hash }, options).then(function (sentCode) { $scope.progress.enabled = false; @@ -1411,6 +1411,7 @@ angular.module('myApp.controllers', []) $scope.profile = {}; $scope.photo = {}; + $scope.version = Config.App.version; MtpApiManager.getUserID().then(function (id) { $scope.profile = AppUsersManager.getUser(id); diff --git a/app/js/directives.js b/app/js/directives.js index cff020f9..cce90e6e 100644 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -540,7 +540,7 @@ angular.module('myApp.directives', ['myApp.filters']) $(richTextarea).on('DOMNodeInserted', onPastedImageEvent); } - if (!window._mobile) { + if (!Config.Navigator.mobile) { $scope.$on('ui_peer_change', focusField); $scope.$on('ui_history_focus', 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(); } @@ -1020,7 +1020,7 @@ angular.module('myApp.directives', ['myApp.filters']) .directive('myFocused', function(){ return { link: function($scope, element, attrs) { - if (window._mobile) { + if (Config.Navigator.mobile) { return false; } setTimeout(function () { @@ -1034,7 +1034,7 @@ angular.module('myApp.directives', ['myApp.filters']) return { link: function($scope, element, attrs) { $scope.$on(attrs.myFocusOn, function () { - if (window._mobile) { + if (Config.Navigator.mobile) { return false; } onContentLoaded(function () { diff --git a/app/js/lib/config.js b/app/js/lib/config.js index 7da753c4..6fe45154 100644 --- a/app/js/lib/config.js +++ b/app/js/lib/config.js @@ -1,6 +1,42 @@ +/*! + * Webogram v0.1.2 - messaging web application for MTProto + * https://github.com/zhukov/webogram + * Copyright (C) 2014 Igor Zhukov + * https://github.com/zhukov/webogram/blob/master/LICENSE + */ + + Config = window.Config || {}; -Config.Schema = Config.Schema || {}; +/* + + IMPORTANT NOTICE + ================ + + Do not publish your Webogram fork with my app credentials (below), or your application may be blocked. + You can get your own api_id, api_hash at https://my.telegram.org, see manual at https://core.telegram.org/api/obtaining_api_id. + +*/ + +Config.App = { + id: 2496, + hash: '8da85b0d5bfe62527e5b244c209159c3', + version: '0.1.2' +}; + +Config.Modes = { + test: location.search.indexOf('test=1') > 0, + debug: location.search.indexOf('debug=1') > 0 +}; + +Config.Navigator = { + osX: (navigator.platform || '').toLowerCase().indexOf('mac') != -1 || + (navigator.userAgent || '').toLowerCase().indexOf('mac') != -1, + retina: window.devicePixelRatio > 1, + mobile: $(window).height() < 600 +}; + +Config.Schema = Config.Schema || {}; Config.Schema.MTProto = {"constructors":[{"id":"481674261","predicate":"vector","params":[],"type":"Vector t"},{"id":"85337187","predicate":"resPQ","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"pq","type":"bytes"},{"name":"server_public_key_fingerprints","type":"Vector"}],"type":"ResPQ"},{"id":"-2083955988","predicate":"p_q_inner_data","params":[{"name":"pq","type":"bytes"},{"name":"p","type":"bytes"},{"name":"q","type":"bytes"},{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce","type":"int256"}],"type":"P_Q_inner_data"},{"id":"2043348061","predicate":"server_DH_params_fail","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce_hash","type":"int128"}],"type":"Server_DH_Params"},{"id":"-790100132","predicate":"server_DH_params_ok","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"encrypted_answer","type":"bytes"}],"type":"Server_DH_Params"},{"id":"-1249309254","predicate":"server_DH_inner_data","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"g","type":"int"},{"name":"dh_prime","type":"bytes"},{"name":"g_a","type":"bytes"},{"name":"server_time","type":"int"}],"type":"Server_DH_inner_data"},{"id":"1715713620","predicate":"client_DH_inner_data","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"retry_id","type":"long"},{"name":"g_b","type":"bytes"}],"type":"Client_DH_Inner_Data"},{"id":"1003222836","predicate":"dh_gen_ok","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce_hash1","type":"int128"}],"type":"Set_client_DH_params_answer"},{"id":"1188831161","predicate":"dh_gen_retry","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce_hash2","type":"int128"}],"type":"Set_client_DH_params_answer"},{"id":"-1499615742","predicate":"dh_gen_fail","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"new_nonce_hash3","type":"int128"}],"type":"Set_client_DH_params_answer"},{"id":"-212046591","predicate":"rpc_result","params":[{"name":"req_msg_id","type":"long"},{"name":"result","type":"Object"}],"type":"RpcResult"},{"id":"558156313","predicate":"rpc_error","params":[{"name":"error_code","type":"int"},{"name":"error_message","type":"string"}],"type":"RpcError"},{"id":"1579864942","predicate":"rpc_answer_unknown","params":[],"type":"RpcDropAnswer"},{"id":"-847714938","predicate":"rpc_answer_dropped_running","params":[],"type":"RpcDropAnswer"},{"id":"-1539647305","predicate":"rpc_answer_dropped","params":[{"name":"msg_id","type":"long"},{"name":"seq_no","type":"int"},{"name":"bytes","type":"int"}],"type":"RpcDropAnswer"},{"id":"155834844","predicate":"future_salt","params":[{"name":"valid_since","type":"int"},{"name":"valid_until","type":"int"},{"name":"salt","type":"long"}],"type":"FutureSalt"},{"id":"-1370486635","predicate":"future_salts","params":[{"name":"req_msg_id","type":"long"},{"name":"now","type":"int"},{"name":"salts","type":"vector"}],"type":"FutureSalts"},{"id":"880243653","predicate":"pong","params":[{"name":"msg_id","type":"long"},{"name":"ping_id","type":"long"}],"type":"Pong"},{"id":"-501201412","predicate":"destroy_session_ok","params":[{"name":"session_id","type":"long"}],"type":"DestroySessionRes"},{"id":"1658015945","predicate":"destroy_session_none","params":[{"name":"session_id","type":"long"}],"type":"DestroySessionRes"},{"id":"-1631450872","predicate":"new_session_created","params":[{"name":"first_msg_id","type":"long"},{"name":"unique_id","type":"long"},{"name":"server_salt","type":"long"}],"type":"NewSession"},{"id":"1945237724","predicate":"msg_container","params":[{"name":"messages","type":"vector<%Message>"}],"type":"MessageContainer"},{"id":"1538843921","predicate":"message","params":[{"name":"msg_id","type":"long"},{"name":"seqno","type":"int"},{"name":"bytes","type":"int"},{"name":"body","type":"Object"}],"type":"Message"},{"id":"-530561358","predicate":"msg_copy","params":[{"name":"orig_message","type":"Message"}],"type":"MessageCopy"},{"id":"812830625","predicate":"gzip_packed","params":[{"name":"packed_data","type":"bytes"}],"type":"Object"},{"id":"1658238041","predicate":"msgs_ack","params":[{"name":"msg_ids","type":"Vector"}],"type":"MsgsAck"},{"id":"-1477445615","predicate":"bad_msg_notification","params":[{"name":"bad_msg_id","type":"long"},{"name":"bad_msg_seqno","type":"int"},{"name":"error_code","type":"int"}],"type":"BadMsgNotification"},{"id":"-307542917","predicate":"bad_server_salt","params":[{"name":"bad_msg_id","type":"long"},{"name":"bad_msg_seqno","type":"int"},{"name":"error_code","type":"int"},{"name":"new_server_salt","type":"long"}],"type":"BadMsgNotification"},{"id":"2105940488","predicate":"msg_resend_req","params":[{"name":"msg_ids","type":"Vector"}],"type":"MsgResendReq"},{"id":"-630588590","predicate":"msgs_state_req","params":[{"name":"msg_ids","type":"Vector"}],"type":"MsgsStateReq"},{"id":"81704317","predicate":"msgs_state_info","params":[{"name":"req_msg_id","type":"long"},{"name":"info","type":"bytes"}],"type":"MsgsStateInfo"},{"id":"-1933520591","predicate":"msgs_all_info","params":[{"name":"msg_ids","type":"Vector"},{"name":"info","type":"bytes"}],"type":"MsgsAllInfo"},{"id":"661470918","predicate":"msg_detailed_info","params":[{"name":"msg_id","type":"long"},{"name":"answer_msg_id","type":"long"},{"name":"bytes","type":"int"},{"name":"status","type":"int"}],"type":"MsgDetailedInfo"},{"id":"-2137147681","predicate":"msg_new_detailed_info","params":[{"name":"answer_msg_id","type":"long"},{"name":"bytes","type":"int"},{"name":"status","type":"int"}],"type":"MsgDetailedInfo"}],"methods":[{"id":"1615239032","method":"req_pq","params":[{"name":"nonce","type":"int128"}],"type":"ResPQ"},{"id":"-686627650","method":"req_DH_params","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"p","type":"bytes"},{"name":"q","type":"bytes"},{"name":"public_key_fingerprint","type":"long"},{"name":"encrypted_data","type":"bytes"}],"type":"Server_DH_Params"},{"id":"-184262881","method":"set_client_DH_params","params":[{"name":"nonce","type":"int128"},{"name":"server_nonce","type":"int128"},{"name":"encrypted_data","type":"bytes"}],"type":"Set_client_DH_params_answer"},{"id":"1491380032","method":"rpc_drop_answer","params":[{"name":"req_msg_id","type":"long"}],"type":"RpcDropAnswer"},{"id":"-1188971260","method":"get_future_salts","params":[{"name":"num","type":"int"}],"type":"FutureSalts"},{"id":"2059302892","method":"ping","params":[{"name":"ping_id","type":"long"}],"type":"Pong"},{"id":"-213746804","method":"ping_delay_disconnect","params":[{"name":"ping_id","type":"long"},{"name":"disconnect_delay","type":"int"}],"type":"Pong"},{"id":"-414113498","method":"destroy_session","params":[{"name":"session_id","type":"long"}],"type":"DestroySessionRes"},{"id":"-1835453025","method":"http_wait","params":[{"name":"max_delay","type":"int"},{"name":"wait_after","type":"int"},{"name":"max_wait","type":"int"}],"type":"HttpWait"}]}; diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index 5eadf9b9..80f5aa40 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -442,7 +442,7 @@ function TLSerialization (options) { 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; return this; } @@ -726,7 +726,7 @@ function TLDeserialization (buffer, options) { this.intView = new Uint32Array(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; return this; } @@ -1003,7 +1003,7 @@ TLDeserialization.prototype.fetchEnd = function () { if (typeof angular != 'undefined') angular.module('mtproto.services', ['myApp.services']). factory('MtpDcConfigurator', function () { - var dcOptions = window._testMode + var dcOptions = Config.Modes.test ? [ {id: 1, host: '173.240.5.253', port: 80}, {id: 2, host: '149.154.167.40', port: 80}, @@ -1753,7 +1753,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato body: serializer.getBytes() }; - if (window._debugMode) { + if (Config.Modes.debug) { console.log(dT(), 'MT call', method, params, messageID, seqNo); } @@ -1774,7 +1774,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato body: serializer.getBytes() }; - if (window._debugMode) { + if (Config.Modes.debug) { console.log(dT(), 'MT message', object, messageID, seqNo); } @@ -1787,10 +1787,10 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato if (!this.connectionInited) { serializer.storeInt(0x2b9b08fa, 'invokeWithLayer14'); 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.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'); } @@ -1810,7 +1810,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato isAPI: true }; - if (window._debugMode) { + if (Config.Modes.debug) { console.log(dT(), 'Api call', method, params, messageID, seqNo, options); } else { console.log(dT(), 'Api call', method, messageID, seqNo); @@ -2075,7 +2075,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato this.sentMessages[message.msg_id] = containerSentMessage; - if (window._debugMode) { + if (Config.Modes.debug) { console.log(dT(), 'Container', innerMessages, message.msg_id, message.seq_no); } } else { @@ -2091,7 +2091,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato this.sendEncryptedRequest(message).then(function (result) { self.toggleOffline(false); self.parseResponse(result.data).then(function (response) { - if (window._debugMode) { + if (Config.Modes.debug) { console.log(dT(), 'Server response', self.dcID, response); } @@ -2483,7 +2483,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato } } else { if (deferred) { - if (window._debugMode) { + if (Config.Modes.debug) { console.log(dT(), 'Rpc response', message.result); } else { console.log(dT(), 'Rpc response', message.result._); diff --git a/app/js/services.js b/app/js/services.js index 24ed284c..abd20bca 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -12,7 +12,7 @@ angular.module('myApp.services', []) .service('AppConfigManager', function ($q) { - var testPrefix = window._testMode ? 't_' : ''; + var testPrefix = Config.Modes.test ? 't_' : ''; var cache = {}; var useCs = !!(window.chrome && chrome.storage && chrome.storage.local); var useLs = !useCs && !!window.localStorage; diff --git a/app/partials/settings_modal.html b/app/partials/settings_modal.html index 1895932f..6d58140d 100644 --- a/app/partials/settings_modal.html +++ b/app/partials/settings_modal.html @@ -102,7 +102,7 @@ diff --git a/gulpfile.js b/gulpfile.js index df02f00b..6d8fe6e3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -84,15 +84,9 @@ gulp.task('update-version-manifests', function() { .pipe(gulp.dest('app')); }); -gulp.task('update-version-settings', function() { - return gulp.src('app/partials/settings_modal.html') - .pipe($.replace(/\bv[\d\.]+\b/, 'v' + 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\'')) +gulp.task('update-version-config', function() { + return gulp.src('app/js/lib/config.js') + .pipe($.replace(/version: '.*?'/, 'version: \'' + pj.version + '\'')) .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()); }); -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'); });