|
|
@ -6,380 +6,299 @@ |
|
|
|
|
|
|
|
|
|
|
|
import App from './config/app'; |
|
|
|
import App from './config/app'; |
|
|
|
import blurActiveElement from './helpers/dom/blurActiveElement'; |
|
|
|
import blurActiveElement from './helpers/dom/blurActiveElement'; |
|
|
|
import { cancelEvent } from './helpers/dom/cancelEvent'; |
|
|
|
import cancelEvent from './helpers/dom/cancelEvent'; |
|
|
|
import { IS_STICKY_INPUT_BUGGED } from './helpers/dom/fixSafariStickyInputFocusing'; |
|
|
|
import { IS_STICKY_INPUT_BUGGED } from './helpers/dom/fixSafariStickyInputFocusing'; |
|
|
|
import loadFonts from './helpers/dom/loadFonts'; |
|
|
|
import loadFonts from './helpers/dom/loadFonts'; |
|
|
|
import IS_EMOJI_SUPPORTED from './environment/emojiSupport'; |
|
|
|
import IS_EMOJI_SUPPORTED from './environment/emojiSupport'; |
|
|
|
import { IS_MOBILE_SAFARI } from './environment/userAgent'; |
|
|
|
import { IS_ANDROID, IS_APPLE, IS_APPLE_MOBILE, IS_FIREFOX, IS_MOBILE, IS_MOBILE_SAFARI, IS_SAFARI } from './environment/userAgent'; |
|
|
|
import './materialize.scss'; |
|
|
|
import './materialize.scss'; |
|
|
|
import './scss/style.scss'; |
|
|
|
import './scss/style.scss'; |
|
|
|
/* import { computeCheck } from './lib/crypto/srp'; |
|
|
|
import pause from './helpers/schedulers/pause'; |
|
|
|
import { salt1, salt2, g, p, srp_id, secure_random, srp_B, password } from './mock/srp'; */ |
|
|
|
import setWorkerProxy from './helpers/setWorkerProxy'; |
|
|
|
|
|
|
|
import toggleAttributePolyfill from './helpers/dom/toggleAttributePolyfill'; |
|
|
|
//console.log('pineapples are in my head');
|
|
|
|
import rootScope from './lib/rootScope'; |
|
|
|
|
|
|
|
import IS_TOUCH_SUPPORTED from './environment/touchSupport'; |
|
|
|
/* console.time('get storage1'); |
|
|
|
import appStateManager from './lib/appManagers/appStateManager'; |
|
|
|
import * as a from './lib/config'; |
|
|
|
import I18n from './lib/langPack'; |
|
|
|
import * as b from './lib/mtproto/mtproto_config'; |
|
|
|
import './helpers/peerIdPolyfill'; |
|
|
|
import * as c from './helpers/userAgent'; |
|
|
|
import './lib/polyfill'; |
|
|
|
import * as d from './lib/mtproto/mtprotoworker'; |
|
|
|
|
|
|
|
import * as e from './lib/polyfill'; |
|
|
|
document.addEventListener('DOMContentLoaded', async() => { |
|
|
|
import * as f from './lib/storage'; |
|
|
|
toggleAttributePolyfill(); |
|
|
|
a && b && c && d && e && f; |
|
|
|
|
|
|
|
console.timeEnd('get storage1'); */ |
|
|
|
// We listen to the resize event (https://css-tricks.com/the-trick-to-viewport-units-on-mobile/)
|
|
|
|
|
|
|
|
const w = window.visualViewport || window; // * handle iOS keyboard
|
|
|
|
/* Promise.all([ |
|
|
|
let setViewportVH = false/* , hasFocus = false */; |
|
|
|
import('./components/pageIm'), |
|
|
|
let lastVH: number; |
|
|
|
import('./components/pageSignIn'), |
|
|
|
const setVH = () => { |
|
|
|
import('./components/misc'), |
|
|
|
const vh = (setViewportVH && !rootScope.isOverlayActive ? (w as VisualViewport).height || (w as Window).innerHeight : window.innerHeight) * 0.01; |
|
|
|
import('./lib/storage') |
|
|
|
if(lastVH === vh) { |
|
|
|
]).then(imports => { |
|
|
|
return; |
|
|
|
let [pageIm, pageSignIn, misc, AppStorage] = imports; */ |
|
|
|
} else if(IS_TOUCH_SUPPORTED && lastVH < vh && (vh - lastVH) > 1) { |
|
|
|
|
|
|
|
blurActiveElement(); // (Android) fix blurring inputs when keyboard is being closed (e.g. closing keyboard by back arrow and touching a bubble)
|
|
|
|
document.addEventListener('DOMContentLoaded', async() => { |
|
|
|
|
|
|
|
//let socket = new Socket(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!Element.prototype.toggleAttribute) { |
|
|
|
|
|
|
|
Element.prototype.toggleAttribute = function(name, force) { |
|
|
|
|
|
|
|
if(force !== void 0) force = !!force; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.hasAttribute(name)) { |
|
|
|
|
|
|
|
if(force) return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.removeAttribute(name); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(force === false) return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setAttribute(name, ""); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// We listen to the resize event (https://css-tricks.com/the-trick-to-viewport-units-on-mobile/)
|
|
|
|
lastVH = vh; |
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
const w = window.visualViewport || window; // * handle iOS keyboard
|
|
|
|
|
|
|
|
let setViewportVH = false/* , hasFocus = false */; |
|
|
|
|
|
|
|
let lastVH: number; |
|
|
|
|
|
|
|
const setVH = () => { |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
const vh = (setViewportVH && !rootScope.default.isOverlayActive ? w.height || w.innerHeight : window.innerHeight) * 0.01; |
|
|
|
|
|
|
|
if(lastVH === vh) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} else if(touchSupport.IS_TOUCH_SUPPORTED && lastVH < vh && (vh - lastVH) > 1) { |
|
|
|
|
|
|
|
blurActiveElement(); // (Android) fix blurring inputs when keyboard is being closed (e.g. closing keyboard by back arrow and touching a bubble)
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastVH = vh; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//const vh = document.documentElement.scrollHeight * 0.01;
|
|
|
|
//const vh = document.documentElement.scrollHeight * 0.01;
|
|
|
|
document.documentElement.style.setProperty('--vh', `${vh}px`); |
|
|
|
document.documentElement.style.setProperty('--vh', `${vh}px`); |
|
|
|
|
|
|
|
|
|
|
|
//console.log('setVH', vh, setViewportVH ? w : window);
|
|
|
|
//console.log('setVH', vh, setViewportVH ? w : window);
|
|
|
|
|
|
|
|
|
|
|
|
/* if(setViewportVH && userAgent.isSafari && touchSupport.isTouchSupported && document.activeElement && (document.activeElement as HTMLElement).blur) { |
|
|
|
/* if(setViewportVH && userAgent.isSafari && touchSupport.isTouchSupported && document.activeElement && (document.activeElement as HTMLElement).blur) { |
|
|
|
const rect = document.activeElement.getBoundingClientRect(); |
|
|
|
const rect = document.activeElement.getBoundingClientRect(); |
|
|
|
if(rect.top < 0 || rect.bottom >= (w as any).height) { |
|
|
|
if(rect.top < 0 || rect.bottom >= (w as any).height) { |
|
|
|
fastSmoothScroll(findUpClassName(document.activeElement, 'scrollable-y') || window as any, document.activeElement as HTMLElement, 'center', 4, undefined, FocusDirection.Static); |
|
|
|
fastSmoothScroll(findUpClassName(document.activeElement, 'scrollable-y') || window as any, document.activeElement as HTMLElement, 'center', 4, undefined, FocusDirection.Static); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setWorkerProxy(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const [_, touchSupport, userAgent, _rootScope, _appStateManager, _I18n, __/* , ___ */] = await Promise.all([
|
|
|
|
|
|
|
|
// import('./lib/polyfill'),
|
|
|
|
|
|
|
|
// import('./environment/touchSupport'),
|
|
|
|
|
|
|
|
// import('./environment/userAgent'),
|
|
|
|
|
|
|
|
// import('./lib/rootScope'),
|
|
|
|
|
|
|
|
// import('./lib/appManagers/appStateManager'),
|
|
|
|
|
|
|
|
// import('./lib/langPack'),
|
|
|
|
|
|
|
|
// import('./helpers/peerIdPolyfill'),
|
|
|
|
|
|
|
|
// // import('./helpers/cacheFunctionPolyfill')
|
|
|
|
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* const {IS_TOUCH_SUPPORTED} = touchSupport; |
|
|
|
|
|
|
|
const {IS_FIREFOX, IS_MOBILE, IS_APPLE, IS_SAFARI, IS_APPLE_MOBILE, IS_ANDROID} = userAgent; |
|
|
|
|
|
|
|
const rootScope = _rootScope.default; |
|
|
|
|
|
|
|
const appStateManager = _appStateManager.default; |
|
|
|
|
|
|
|
const I18n = _I18n.default; */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', setVH); |
|
|
|
|
|
|
|
setVH(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(IS_STICKY_INPUT_BUGGED) { |
|
|
|
|
|
|
|
const toggleResizeMode = () => { |
|
|
|
|
|
|
|
setViewportVH = tabId === 1 && IS_STICKY_INPUT_BUGGED && !rootScope.isOverlayActive; |
|
|
|
|
|
|
|
setVH(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(w !== window) { |
|
|
|
|
|
|
|
if(setViewportVH) { |
|
|
|
|
|
|
|
window.removeEventListener('resize', setVH); |
|
|
|
|
|
|
|
w.addEventListener('resize', setVH); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
w.removeEventListener('resize', setVH); |
|
|
|
|
|
|
|
window.addEventListener('resize', setVH); |
|
|
|
} |
|
|
|
} |
|
|
|
} */ |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// * hook worker constructor to set search parameters (test, debug, etc)
|
|
|
|
let tabId: number; |
|
|
|
const workerHandler = { |
|
|
|
rootScope.addEventListener('im_tab_change', (id) => { |
|
|
|
construct(target: any, args: any) { |
|
|
|
const wasTabId = tabId !== undefined; |
|
|
|
//console.log(target, args);
|
|
|
|
tabId = id; |
|
|
|
const url = args[0] + location.search; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new target(url); |
|
|
|
if(wasTabId || tabId === 1) { |
|
|
|
|
|
|
|
toggleResizeMode(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const workerProxy = new Proxy(Worker, workerHandler); |
|
|
|
rootScope.addEventListener('overlay_toggle', () => { |
|
|
|
Worker = workerProxy; |
|
|
|
toggleResizeMode(); |
|
|
|
|
|
|
|
}); |
|
|
|
const [_, touchSupport, userAgent, rootScope, appStateManager, I18n, __/* , ___ */] = await Promise.all([ |
|
|
|
} |
|
|
|
import('./lib/polyfill'), |
|
|
|
|
|
|
|
import('./environment/touchSupport'), |
|
|
|
|
|
|
|
import('./environment/userAgent'), |
|
|
|
|
|
|
|
import('./lib/rootScope'), |
|
|
|
|
|
|
|
import('./lib/appManagers/appStateManager'), |
|
|
|
|
|
|
|
import('./lib/langPack'), |
|
|
|
|
|
|
|
import('./helpers/peerIdPolyfill'), |
|
|
|
|
|
|
|
// import('./helpers/cacheFunctionPolyfill')
|
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.timeEnd('get storage');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', setVH); |
|
|
|
|
|
|
|
setVH(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(new Uint8Array([255, 200, 145]).hex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(IS_STICKY_INPUT_BUGGED) { |
|
|
|
|
|
|
|
const toggleResizeMode = () => { |
|
|
|
|
|
|
|
setViewportVH = tabId === 1 && IS_STICKY_INPUT_BUGGED && !rootScope.default.isOverlayActive; |
|
|
|
|
|
|
|
setVH(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(w !== window) { |
|
|
|
|
|
|
|
if(setViewportVH) { |
|
|
|
|
|
|
|
window.removeEventListener('resize', setVH); |
|
|
|
|
|
|
|
w.addEventListener('resize', setVH); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
w.removeEventListener('resize', setVH); |
|
|
|
|
|
|
|
window.addEventListener('resize', setVH); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let tabId: number; |
|
|
|
|
|
|
|
rootScope.default.addEventListener('im_tab_change', (id) => { |
|
|
|
|
|
|
|
const wasTabId = tabId !== undefined; |
|
|
|
|
|
|
|
tabId = id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(wasTabId || tabId === 1) { |
|
|
|
|
|
|
|
toggleResizeMode(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rootScope.default.addEventListener('overlay_toggle', () => { |
|
|
|
|
|
|
|
toggleResizeMode(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(userAgent.IS_FIREFOX && !IS_EMOJI_SUPPORTED) { |
|
|
|
|
|
|
|
document.addEventListener('dragstart', (e) => { |
|
|
|
|
|
|
|
const target = e.target as HTMLElement; |
|
|
|
|
|
|
|
if(target.tagName === 'IMG' && target.classList.contains('emoji')) { |
|
|
|
|
|
|
|
cancelEvent(e); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// prevent firefox image dragging
|
|
|
|
if(IS_FIREFOX && !IS_EMOJI_SUPPORTED) { |
|
|
|
document.addEventListener('dragstart', (e) => { |
|
|
|
document.addEventListener('dragstart', (e) => { |
|
|
|
if((e.target as HTMLElement)?.tagName === "IMG") { |
|
|
|
const target = e.target as HTMLElement; |
|
|
|
e.preventDefault(); |
|
|
|
if(target.tagName === 'IMG' && target.classList.contains('emoji')) { |
|
|
|
|
|
|
|
cancelEvent(e); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(userAgent.IS_FIREFOX) { |
|
|
|
// prevent firefox image dragging
|
|
|
|
document.documentElement.classList.add('is-firefox'); |
|
|
|
document.addEventListener('dragstart', (e) => { |
|
|
|
|
|
|
|
if((e.target as HTMLElement)?.tagName === "IMG") { |
|
|
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if(userAgent.IS_MOBILE) { |
|
|
|
if(IS_FIREFOX) { |
|
|
|
document.documentElement.classList.add('is-mobile'); |
|
|
|
document.documentElement.classList.add('is-firefox'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(userAgent.IS_APPLE) { |
|
|
|
|
|
|
|
if(userAgent.IS_SAFARI) { |
|
|
|
|
|
|
|
document.documentElement.classList.add('is-safari'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// document.documentElement.classList.add('emoji-supported');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(userAgent.IS_APPLE_MOBILE) { |
|
|
|
|
|
|
|
document.documentElement.classList.add('is-ios'); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
document.documentElement.classList.add('is-mac'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if(userAgent.IS_ANDROID) { |
|
|
|
|
|
|
|
document.documentElement.classList.add('is-android'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* document.addEventListener('focusin', (e) => { |
|
|
|
if(IS_MOBILE) { |
|
|
|
hasFocus = true; |
|
|
|
document.documentElement.classList.add('is-mobile'); |
|
|
|
focusTime = Date.now(); |
|
|
|
} |
|
|
|
}, {passive: true}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('focusout', () => { |
|
|
|
if(IS_APPLE) { |
|
|
|
hasFocus = false; |
|
|
|
if(IS_SAFARI) { |
|
|
|
}, {passive: true}); */ |
|
|
|
document.documentElement.classList.add('is-safari'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// document.documentElement.classList.add('emoji-supported');
|
|
|
|
|
|
|
|
|
|
|
|
if(!touchSupport.IS_TOUCH_SUPPORTED) { |
|
|
|
if(IS_APPLE_MOBILE) { |
|
|
|
document.documentElement.classList.add('no-touch'); |
|
|
|
document.documentElement.classList.add('is-ios'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
document.documentElement.classList.add('is-touch'); |
|
|
|
document.documentElement.classList.add('is-mac'); |
|
|
|
/* document.addEventListener('touchmove', (event: any) => { |
|
|
|
|
|
|
|
event = event.originalEvent || event; |
|
|
|
|
|
|
|
if(event.scale && event.scale !== 1) { |
|
|
|
|
|
|
|
event.preventDefault(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, {capture: true, passive: false}); */ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if(IS_ANDROID) { |
|
|
|
|
|
|
|
document.documentElement.classList.add('is-android'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* document.addEventListener('focusin', (e) => { |
|
|
|
|
|
|
|
hasFocus = true; |
|
|
|
|
|
|
|
focusTime = Date.now(); |
|
|
|
|
|
|
|
}, {passive: true}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('focusout', () => { |
|
|
|
|
|
|
|
hasFocus = false; |
|
|
|
|
|
|
|
}, {passive: true}); */ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!IS_TOUCH_SUPPORTED) { |
|
|
|
|
|
|
|
document.documentElement.classList.add('no-touch'); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
document.documentElement.classList.add('is-touch'); |
|
|
|
|
|
|
|
/* document.addEventListener('touchmove', (event: any) => { |
|
|
|
|
|
|
|
event = event.originalEvent || event; |
|
|
|
|
|
|
|
if(event.scale && event.scale !== 1) { |
|
|
|
|
|
|
|
event.preventDefault(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, {capture: true, passive: false}); */ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* if(config.isServiceWorkerSupported) { |
|
|
|
let perf = performance.now(); |
|
|
|
await navigator.serviceWorker.ready; |
|
|
|
|
|
|
|
navigator.serviceWorker.controller ? true : await new Promise((resolve, reject) => { |
|
|
|
|
|
|
|
navigator.serviceWorker.addEventListener('controllerchange', resolve); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.time('get storage');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const perf = performance.now(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//import('./vendor/dateFormat');
|
|
|
|
const langPromise = I18n.getCacheLangPack(); |
|
|
|
|
|
|
|
|
|
|
|
const langPromise = I18n.default.getCacheLangPack(); |
|
|
|
const [state, langPack] = await Promise.all([ |
|
|
|
|
|
|
|
appStateManager.getState(), |
|
|
|
|
|
|
|
langPromise |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
I18n.setTimeFormat(state.settings.timeFormat); |
|
|
|
|
|
|
|
|
|
|
|
const [state, langPack] = await Promise.all([ |
|
|
|
rootScope.setThemeListener(); |
|
|
|
appStateManager.default.getState(), |
|
|
|
|
|
|
|
langPromise |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
//I18n.getCacheLangPack();
|
|
|
|
|
|
|
|
//console.log('got auth:', auth);
|
|
|
|
|
|
|
|
//console.timeEnd('get storage');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I18n.default.setTimeFormat(state.settings.timeFormat); |
|
|
|
if(langPack.appVersion !== App.langPackVersion) { |
|
|
|
|
|
|
|
I18n.getLangPack(langPack.lang_code); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rootScope.default.setThemeListener(); |
|
|
|
/** |
|
|
|
|
|
|
|
* won't fire if font is loaded too fast |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function fadeInWhenFontsReady(elem: HTMLElement, promise: Promise<any>) { |
|
|
|
|
|
|
|
elem.style.opacity = '0'; |
|
|
|
|
|
|
|
|
|
|
|
if(langPack.appVersion !== App.langPackVersion) { |
|
|
|
promise.then(() => { |
|
|
|
I18n.default.getLangPack(langPack.lang_code); |
|
|
|
window.requestAnimationFrame(() => { |
|
|
|
} |
|
|
|
elem.style.opacity = ''; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
console.log('got state, time:', performance.now() - perf); |
|
|
|
* won't fire if font is loaded too fast |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function fadeInWhenFontsReady(elem: HTMLElement, promise: Promise<any>) { |
|
|
|
|
|
|
|
elem.style.opacity = '0'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
promise.then(() => { |
|
|
|
const authState = state.authState; |
|
|
|
window.requestAnimationFrame(() => { |
|
|
|
if(authState._ !== 'authStateSignedIn'/* || 1 === 1 */) { |
|
|
|
elem.style.opacity = ''; |
|
|
|
console.log('Will mount auth page:', authState._, Date.now() / 1000); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('got state, time:', performance.now() - perf); |
|
|
|
const el = document.getElementById('auth-pages'); |
|
|
|
|
|
|
|
let scrollable: HTMLElement; |
|
|
|
|
|
|
|
if(el) { |
|
|
|
|
|
|
|
scrollable = el.querySelector('.scrollable') as HTMLElement; |
|
|
|
|
|
|
|
if((!IS_TOUCH_SUPPORTED || IS_MOBILE_SAFARI)) { |
|
|
|
|
|
|
|
scrollable.classList.add('no-scrollbar'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const authState = state.authState; |
|
|
|
// * don't remove this line
|
|
|
|
if(authState._ !== 'authStateSignedIn'/* || 1 === 1 */) { |
|
|
|
scrollable.style.opacity = '0'; |
|
|
|
console.log('Will mount auth page:', authState._, Date.now() / 1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const el = document.getElementById('auth-pages'); |
|
|
|
const placeholder = document.createElement('div'); |
|
|
|
let scrollable: HTMLElement; |
|
|
|
placeholder.classList.add('auth-placeholder'); |
|
|
|
if(el) { |
|
|
|
|
|
|
|
scrollable = el.querySelector('.scrollable') as HTMLElement; |
|
|
|
|
|
|
|
if((!touchSupport.IS_TOUCH_SUPPORTED || IS_MOBILE_SAFARI)) { |
|
|
|
|
|
|
|
scrollable.classList.add('no-scrollbar'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// * don't remove this line
|
|
|
|
scrollable.prepend(placeholder); |
|
|
|
scrollable.style.opacity = '0'; |
|
|
|
scrollable.append(placeholder.cloneNode()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const placeholder = document.createElement('div'); |
|
|
|
try { |
|
|
|
placeholder.classList.add('auth-placeholder'); |
|
|
|
await Promise.all([ |
|
|
|
|
|
|
|
import('./lib/mtproto/telegramMeWebManager'), |
|
|
|
|
|
|
|
import('./lib/mtproto/webPushApiManager') |
|
|
|
|
|
|
|
]).then(([meModule, pushModule]) => { |
|
|
|
|
|
|
|
meModule.default.setAuthorized(false); |
|
|
|
|
|
|
|
pushModule.default.forceUnsubscribe(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} catch(err) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
scrollable.prepend(placeholder); |
|
|
|
let pagePromise: Promise<void>; |
|
|
|
scrollable.append(placeholder.cloneNode()); |
|
|
|
//langPromise.then(async() => {
|
|
|
|
|
|
|
|
switch(authState._) { |
|
|
|
|
|
|
|
case 'authStateSignIn': |
|
|
|
|
|
|
|
pagePromise = (await import('./pages/pageSignIn')).default.mount(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'authStateSignQr': |
|
|
|
|
|
|
|
pagePromise = (await import('./pages/pageSignQR')).default.mount(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'authStateAuthCode': |
|
|
|
|
|
|
|
pagePromise = (await import('./pages/pageAuthCode')).default.mount(authState.sentCode); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'authStatePassword': |
|
|
|
|
|
|
|
pagePromise = (await import('./pages/pagePassword')).default.mount(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'authStateSignUp': |
|
|
|
|
|
|
|
pagePromise = (await import('./pages/pageSignUp')).default.mount(authState.authCode); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
if(scrollable) { |
|
|
|
await Promise.all([ |
|
|
|
// wait for text appear
|
|
|
|
import('./lib/mtproto/telegramMeWebManager'), |
|
|
|
if(pagePromise) { |
|
|
|
import('./lib/mtproto/webPushApiManager') |
|
|
|
await pagePromise; |
|
|
|
]).then(([meModule, pushModule]) => { |
|
|
|
|
|
|
|
meModule.default.setAuthorized(false); |
|
|
|
|
|
|
|
pushModule.default.forceUnsubscribe(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} catch(err) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let pagePromise: Promise<void>; |
|
|
|
const promise = 'fonts' in document ? |
|
|
|
//langPromise.then(async() => {
|
|
|
|
Promise.race([ |
|
|
|
switch(authState._) { |
|
|
|
pause(1000), |
|
|
|
case 'authStateSignIn': |
|
|
|
document.fonts.ready |
|
|
|
pagePromise = (await import('./pages/pageSignIn')).default.mount(); |
|
|
|
]) : |
|
|
|
break; |
|
|
|
Promise.resolve(); |
|
|
|
case 'authStateSignQr': |
|
|
|
fadeInWhenFontsReady(scrollable, promise); |
|
|
|
pagePromise = (await import('./pages/pageSignQR')).default.mount(); |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case 'authStateAuthCode': |
|
|
|
|
|
|
|
pagePromise = (await import('./pages/pageAuthCode')).default.mount(authState.sentCode); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'authStatePassword': |
|
|
|
|
|
|
|
pagePromise = (await import('./pages/pagePassword')).default.mount(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'authStateSignUp': |
|
|
|
|
|
|
|
pagePromise = (await import('./pages/pageSignUp')).default.mount(authState.authCode); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(scrollable) { |
|
|
|
|
|
|
|
// wait for text appear
|
|
|
|
|
|
|
|
if(pagePromise) { |
|
|
|
|
|
|
|
await pagePromise; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const promise = 'fonts' in document ? |
|
|
|
|
|
|
|
Promise.race([ |
|
|
|
|
|
|
|
new Promise((resolve) => setTimeout(resolve, 1e3)), |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
document.fonts.ready |
|
|
|
|
|
|
|
]) : |
|
|
|
|
|
|
|
Promise.resolve(); |
|
|
|
|
|
|
|
fadeInWhenFontsReady(scrollable, promise); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* computeCheck(password, { |
|
|
|
/* setTimeout(async() => { |
|
|
|
current_algo: { |
|
|
|
(await import('./pages/pageAuthCode')).default.mount({ |
|
|
|
salt1, |
|
|
|
"_": "auth.sentCode", |
|
|
|
salt2, |
|
|
|
"pFlags": {}, |
|
|
|
p, |
|
|
|
"flags": 6, |
|
|
|
g |
|
|
|
"type": { |
|
|
|
|
|
|
|
"_": "auth.sentCodeTypeSms", |
|
|
|
|
|
|
|
"length": 5 |
|
|
|
}, |
|
|
|
}, |
|
|
|
srp_id, |
|
|
|
"phone_code_hash": "", |
|
|
|
srp_B, |
|
|
|
"next_type": { |
|
|
|
secure_random, |
|
|
|
"_": "auth.codeTypeCall" |
|
|
|
}).then(res => { |
|
|
|
}, |
|
|
|
console.log(res); |
|
|
|
"timeout": 120, |
|
|
|
}); */ |
|
|
|
"phone_number": "" |
|
|
|
|
|
|
|
}); |
|
|
|
/* setTimeout(async() => { |
|
|
|
|
|
|
|
(await import('./pages/pageAuthCode')).default.mount({ |
|
|
|
|
|
|
|
"_": "auth.sentCode", |
|
|
|
|
|
|
|
"pFlags": {}, |
|
|
|
|
|
|
|
"flags": 6, |
|
|
|
|
|
|
|
"type": { |
|
|
|
|
|
|
|
"_": "auth.sentCodeTypeSms", |
|
|
|
|
|
|
|
"length": 5 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"phone_code_hash": "", |
|
|
|
|
|
|
|
"next_type": { |
|
|
|
|
|
|
|
"_": "auth.codeTypeCall" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"timeout": 120, |
|
|
|
|
|
|
|
"phone_number": "" |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, 500); */ |
|
|
|
|
|
|
|
/* setTimeout(async() => { |
|
|
|
|
|
|
|
(await import('./pages/pageSignQR')).default.mount(); |
|
|
|
|
|
|
|
}, 500); */ |
|
|
|
|
|
|
|
/* setTimeout(async() => { |
|
|
|
|
|
|
|
(await import('./pages/pagePassword')).default.mount(); |
|
|
|
|
|
|
|
}, 500); */ |
|
|
|
|
|
|
|
/* setTimeout(async() => { |
|
|
|
|
|
|
|
(await import('./pages/pageSignUp')).default.mount({ |
|
|
|
|
|
|
|
"phone_code_hash": "", |
|
|
|
|
|
|
|
"phone_number": "" |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, 500); */ |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
console.log('Will mount IM page:', Date.now() / 1000); |
|
|
|
|
|
|
|
fadeInWhenFontsReady(document.getElementById('main-columns'), loadFonts()); |
|
|
|
|
|
|
|
(await import('./pages/pageIm')).default.mount(); |
|
|
|
|
|
|
|
//getNearestDc();
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ripple = (await import('./components/ripple')).ripple; |
|
|
|
(await import('./pages/pageSignQR')).default.mount(); |
|
|
|
(Array.from(document.getElementsByClassName('rp')) as HTMLElement[]).forEach(el => ripple(el)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(await import('./pages/pagePassword')).default.mount(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(await import('./pages/pageSignUp')).default.mount({ |
|
|
|
|
|
|
|
"phone_code_hash": "", |
|
|
|
|
|
|
|
"phone_number": "" |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, 500); */ |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
console.log('Will mount IM page:', Date.now() / 1000); |
|
|
|
|
|
|
|
fadeInWhenFontsReady(document.getElementById('main-columns'), loadFonts()); |
|
|
|
|
|
|
|
(await import('./pages/pageIm')).default.mount(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|