Pass langPack code in initConnection
This commit is contained in:
parent
d2d140598a
commit
39d296edeb
@ -217,7 +217,7 @@ namespace I18n {
|
|||||||
strings.set(string.key as LangPackKey, string);
|
strings.set(string.key as LangPackKey, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
rootScope.dispatchEvent('language_change');
|
rootScope.dispatchEvent('language_change', langPack.lang_code);
|
||||||
|
|
||||||
const elements = Array.from(document.querySelectorAll(`.i18n`)) as HTMLElement[];
|
const elements = Array.from(document.querySelectorAll(`.i18n`)) as HTMLElement[];
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
|
@ -57,7 +57,7 @@ function isCorrectResponse(response: Response) {
|
|||||||
async function requestCache(event: FetchEvent) {
|
async function requestCache(event: FetchEvent) {
|
||||||
try {
|
try {
|
||||||
const cache = await ctx.caches.open('cachedAssets');
|
const cache = await ctx.caches.open('cachedAssets');
|
||||||
const file = await cache.match(event.request);
|
const file = await cache.match(event.request, {ignoreVary: true});
|
||||||
|
|
||||||
if(file && isCorrectResponse(file)) {
|
if(file && isCorrectResponse(file)) {
|
||||||
return file;
|
return file;
|
||||||
|
@ -131,10 +131,11 @@ const onMessage = async(e: any) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'setLanguage':
|
||||||
case 'startAll':
|
case 'startAll':
|
||||||
case 'stopAll': {
|
case 'stopAll': {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
networkerFactory[task.task].apply(networkerFactory);
|
networkerFactory[task.task].apply(networkerFactory, task.args);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,6 +179,10 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rootScope.addEventListener('language_change', (language) => {
|
||||||
|
this.performTaskWorkerVoid('setLanguage', language);
|
||||||
|
});
|
||||||
|
|
||||||
/// #if !MTPROTO_SW
|
/// #if !MTPROTO_SW
|
||||||
this.registerWorker();
|
this.registerWorker();
|
||||||
/// #endif
|
/// #endif
|
||||||
@ -310,22 +314,25 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public performTaskWorkerVoid(task: string, ...args: any[]) {
|
||||||
|
const params = {
|
||||||
|
task,
|
||||||
|
taskId: this.taskId,
|
||||||
|
args
|
||||||
|
};
|
||||||
|
|
||||||
|
this.pending.push(params);
|
||||||
|
this.releasePending();
|
||||||
|
|
||||||
|
this.taskId++;
|
||||||
|
}
|
||||||
|
|
||||||
public performTaskWorker<T>(task: string, ...args: any[]) {
|
public performTaskWorker<T>(task: string, ...args: any[]) {
|
||||||
this.debug && this.log.debug('start', task, args);
|
this.debug && this.log.debug('start', task, args);
|
||||||
|
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
this.awaiting[this.taskId] = {resolve, reject, taskName: task};
|
this.awaiting[this.taskId] = {resolve, reject, taskName: task};
|
||||||
|
this.performTaskWorkerVoid(task, ...args);
|
||||||
const params = {
|
|
||||||
task,
|
|
||||||
taskId: this.taskId,
|
|
||||||
args
|
|
||||||
};
|
|
||||||
|
|
||||||
this.pending.push(params);
|
|
||||||
this.releasePending();
|
|
||||||
|
|
||||||
this.taskId++;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,15 +511,15 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public toggleStorage(enabled: boolean) {
|
public toggleStorage(enabled: boolean) {
|
||||||
return this.performTaskWorker('toggleStorage', enabled);
|
return this.performTaskWorkerVoid('toggleStorage', enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public stopAll() {
|
public stopAll() {
|
||||||
return this.performTaskWorker('stopAll');
|
return this.performTaskWorkerVoid('stopAll');
|
||||||
}
|
}
|
||||||
|
|
||||||
public startAll() {
|
public startAll() {
|
||||||
return this.performTaskWorker('startAll');
|
return this.performTaskWorkerVoid('startAll');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import CryptoWorker from '../crypto/cryptoworker';
|
|||||||
import sessionStorage from '../sessionStorage';
|
import sessionStorage from '../sessionStorage';
|
||||||
import Schema from './schema';
|
import Schema from './schema';
|
||||||
import timeManager from './timeManager';
|
import timeManager from './timeManager';
|
||||||
import NetworkerFactory from './networkerFactory';
|
import networkerFactory from './networkerFactory';
|
||||||
import { logger, LogTypes } from '../logger';
|
import { logger, LogTypes } from '../logger';
|
||||||
import { InvokeApiOptions } from '../../types';
|
import { InvokeApiOptions } from '../../types';
|
||||||
import { longToBytes } from '../crypto/crypto_utils';
|
import { longToBytes } from '../crypto/crypto_utils';
|
||||||
@ -79,7 +79,7 @@ let invokeAfterMsgConstructor: number;
|
|||||||
export default class MTPNetworker {
|
export default class MTPNetworker {
|
||||||
private authKeyUint8: Uint8Array;
|
private authKeyUint8: Uint8Array;
|
||||||
|
|
||||||
private isFileNetworker: boolean;
|
public isFileNetworker: boolean;
|
||||||
private isFileUpload: boolean;
|
private isFileUpload: boolean;
|
||||||
private isFileDownload: boolean;
|
private isFileDownload: boolean;
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ export default class MTPNetworker {
|
|||||||
private pendingMessages: {[msgId: string]: number} = {};
|
private pendingMessages: {[msgId: string]: number} = {};
|
||||||
private pendingAcks: Array<string> = [];
|
private pendingAcks: Array<string> = [];
|
||||||
private pendingResends: Array<string> = [];
|
private pendingResends: Array<string> = [];
|
||||||
private connectionInited = false;
|
public connectionInited = false;
|
||||||
|
|
||||||
private nextReqTimeout: number;
|
private nextReqTimeout: number;
|
||||||
private nextReq: number = 0;
|
private nextReq: number = 0;
|
||||||
@ -288,7 +288,7 @@ export default class MTPNetworker {
|
|||||||
|
|
||||||
if(!this.connectionInited) { // this will call once for each new session
|
if(!this.connectionInited) { // this will call once for each new session
|
||||||
///////this.log('Wrap api call !this.connectionInited');
|
///////this.log('Wrap api call !this.connectionInited');
|
||||||
|
|
||||||
const invokeWithLayer = Schema.API.methods.find(m => m.method === 'invokeWithLayer');
|
const invokeWithLayer = Schema.API.methods.find(m => m.method === 'invokeWithLayer');
|
||||||
if(!invokeWithLayer) throw new Error('no invokeWithLayer!');
|
if(!invokeWithLayer) throw new Error('no invokeWithLayer!');
|
||||||
serializer.storeInt(+invokeWithLayer.id >>> 0, 'invokeWithLayer');
|
serializer.storeInt(+invokeWithLayer.id >>> 0, 'invokeWithLayer');
|
||||||
@ -307,7 +307,7 @@ export default class MTPNetworker {
|
|||||||
serializer.storeString(App.version + (App.isMainDomain ? ' ' + App.suffix : ''), 'app_version');
|
serializer.storeString(App.version + (App.isMainDomain ? ' ' + App.suffix : ''), 'app_version');
|
||||||
serializer.storeString(navigator.language || 'en', 'system_lang_code');
|
serializer.storeString(navigator.language || 'en', 'system_lang_code');
|
||||||
serializer.storeString(App.langPack, 'lang_pack');
|
serializer.storeString(App.langPack, 'lang_pack');
|
||||||
serializer.storeString(navigator.language || 'en', 'lang_code');
|
serializer.storeString(networkerFactory.language, 'lang_code');
|
||||||
//serializer.storeInt(0x0, 'proxy');
|
//serializer.storeInt(0x0, 'proxy');
|
||||||
/* serializer.storeMethod('initConnection', {
|
/* serializer.storeMethod('initConnection', {
|
||||||
'flags': 0,
|
'flags': 0,
|
||||||
@ -698,8 +698,8 @@ export default class MTPNetworker {
|
|||||||
this.isOnline = online;
|
this.isOnline = online;
|
||||||
|
|
||||||
if(willChange) {
|
if(willChange) {
|
||||||
if(NetworkerFactory.onConnectionStatusChange) {
|
if(networkerFactory.onConnectionStatusChange) {
|
||||||
NetworkerFactory.onConnectionStatusChange({
|
networkerFactory.onConnectionStatusChange({
|
||||||
_: 'networkerStatus',
|
_: 'networkerStatus',
|
||||||
online: this.isOnline,
|
online: this.isOnline,
|
||||||
dcId: this.dcId,
|
dcId: this.dcId,
|
||||||
@ -792,7 +792,7 @@ export default class MTPNetworker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public isStopped() {
|
public isStopped() {
|
||||||
return NetworkerFactory.akStopped && !this.isFileNetworker;
|
return networkerFactory.akStopped && !this.isFileNetworker;
|
||||||
}
|
}
|
||||||
|
|
||||||
private performScheduledRequest() {
|
private performScheduledRequest() {
|
||||||
@ -1544,8 +1544,8 @@ export default class MTPNetworker {
|
|||||||
this.applyServerSalt(message.server_salt);
|
this.applyServerSalt(message.server_salt);
|
||||||
|
|
||||||
sessionStorage.get('dc').then((baseDcId) => {
|
sessionStorage.get('dc').then((baseDcId) => {
|
||||||
if(baseDcId === this.dcId && !this.isFileNetworker && NetworkerFactory.updatesProcessor) {
|
if(baseDcId === this.dcId && !this.isFileNetworker && networkerFactory.updatesProcessor) {
|
||||||
NetworkerFactory.updatesProcessor(message);
|
networkerFactory.updatesProcessor(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -1649,8 +1649,8 @@ export default class MTPNetworker {
|
|||||||
this.log.debug('Update', message);
|
this.log.debug('Update', message);
|
||||||
} */
|
} */
|
||||||
|
|
||||||
if(NetworkerFactory.updatesProcessor !== null) {
|
if(networkerFactory.updatesProcessor !== null) {
|
||||||
NetworkerFactory.updatesProcessor(message);
|
networkerFactory.updatesProcessor(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,12 @@
|
|||||||
import MTPNetworker from "./networker";
|
import MTPNetworker from "./networker";
|
||||||
import { ConnectionStatusChange, InvokeApiOptions } from "../../types";
|
import { ConnectionStatusChange, InvokeApiOptions } from "../../types";
|
||||||
import MTTransport from "./transports/transport";
|
import MTTransport from "./transports/transport";
|
||||||
|
import App from "../../config/app";
|
||||||
|
import { MOUNT_CLASS_TO } from "../../config/debug";
|
||||||
|
|
||||||
export class NetworkerFactory {
|
export class NetworkerFactory {
|
||||||
private networkers: MTPNetworker[] = [];
|
private networkers: MTPNetworker[] = [];
|
||||||
|
public language = navigator.language || App.langPackCode;
|
||||||
public updatesProcessor: (obj: any) => void = null;
|
public updatesProcessor: (obj: any) => void = null;
|
||||||
public onConnectionStatusChange: (info: ConnectionStatusChange) => void = null;
|
public onConnectionStatusChange: (info: ConnectionStatusChange) => void = null;
|
||||||
public akStopped = false;
|
public akStopped = false;
|
||||||
@ -46,6 +49,17 @@ export class NetworkerFactory {
|
|||||||
public stopAll() {
|
public stopAll() {
|
||||||
this.akStopped = true;
|
this.akStopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setLanguage(langCode: string) {
|
||||||
|
this.language = langCode;
|
||||||
|
for(const networker of this.networkers) {
|
||||||
|
if(!networker.isFileNetworker) {
|
||||||
|
networker.connectionInited = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new NetworkerFactory();
|
const networkerFactory = new NetworkerFactory();
|
||||||
|
MOUNT_CLASS_TO && (MOUNT_CLASS_TO.networkerFactory = networkerFactory);
|
||||||
|
export default networkerFactory;
|
||||||
|
@ -109,7 +109,7 @@ export type BroadcastEvents = {
|
|||||||
'notify_settings': Update.updateNotifySettings,
|
'notify_settings': Update.updateNotifySettings,
|
||||||
'notify_peer_type_settings': {key: Exclude<NotifyPeer['_'], 'notifyPeer'>, settings: PeerNotifySettings},
|
'notify_peer_type_settings': {key: Exclude<NotifyPeer['_'], 'notifyPeer'>, settings: PeerNotifySettings},
|
||||||
|
|
||||||
'language_change': void,
|
'language_change': string,
|
||||||
|
|
||||||
'theme_change': void,
|
'theme_change': void,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user