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);
|
||||
}
|
||||
|
||||
rootScope.dispatchEvent('language_change');
|
||||
rootScope.dispatchEvent('language_change', langPack.lang_code);
|
||||
|
||||
const elements = Array.from(document.querySelectorAll(`.i18n`)) as HTMLElement[];
|
||||
elements.forEach(element => {
|
||||
|
@ -57,7 +57,7 @@ function isCorrectResponse(response: Response) {
|
||||
async function requestCache(event: FetchEvent) {
|
||||
try {
|
||||
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)) {
|
||||
return file;
|
||||
|
@ -131,10 +131,11 @@ const onMessage = async(e: any) => {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'setLanguage':
|
||||
case 'startAll':
|
||||
case 'stopAll': {
|
||||
// @ts-ignore
|
||||
networkerFactory[task.task].apply(networkerFactory);
|
||||
networkerFactory[task.task].apply(networkerFactory, task.args);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,10 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
||||
}
|
||||
});
|
||||
|
||||
rootScope.addEventListener('language_change', (language) => {
|
||||
this.performTaskWorkerVoid('setLanguage', language);
|
||||
});
|
||||
|
||||
/// #if !MTPROTO_SW
|
||||
this.registerWorker();
|
||||
/// #endif
|
||||
@ -310,12 +314,7 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
||||
}
|
||||
}
|
||||
|
||||
public performTaskWorker<T>(task: string, ...args: any[]) {
|
||||
this.debug && this.log.debug('start', task, args);
|
||||
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
this.awaiting[this.taskId] = {resolve, reject, taskName: task};
|
||||
|
||||
public performTaskWorkerVoid(task: string, ...args: any[]) {
|
||||
const params = {
|
||||
task,
|
||||
taskId: this.taskId,
|
||||
@ -326,6 +325,14 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
||||
this.releasePending();
|
||||
|
||||
this.taskId++;
|
||||
}
|
||||
|
||||
public performTaskWorker<T>(task: string, ...args: any[]) {
|
||||
this.debug && this.log.debug('start', task, args);
|
||||
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
this.awaiting[this.taskId] = {resolve, reject, taskName: task};
|
||||
this.performTaskWorkerVoid(task, ...args);
|
||||
});
|
||||
}
|
||||
|
||||
@ -504,15 +511,15 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
||||
}
|
||||
|
||||
public toggleStorage(enabled: boolean) {
|
||||
return this.performTaskWorker('toggleStorage', enabled);
|
||||
return this.performTaskWorkerVoid('toggleStorage', enabled);
|
||||
}
|
||||
|
||||
public stopAll() {
|
||||
return this.performTaskWorker('stopAll');
|
||||
return this.performTaskWorkerVoid('stopAll');
|
||||
}
|
||||
|
||||
public startAll() {
|
||||
return this.performTaskWorker('startAll');
|
||||
return this.performTaskWorkerVoid('startAll');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ import CryptoWorker from '../crypto/cryptoworker';
|
||||
import sessionStorage from '../sessionStorage';
|
||||
import Schema from './schema';
|
||||
import timeManager from './timeManager';
|
||||
import NetworkerFactory from './networkerFactory';
|
||||
import networkerFactory from './networkerFactory';
|
||||
import { logger, LogTypes } from '../logger';
|
||||
import { InvokeApiOptions } from '../../types';
|
||||
import { longToBytes } from '../crypto/crypto_utils';
|
||||
@ -79,7 +79,7 @@ let invokeAfterMsgConstructor: number;
|
||||
export default class MTPNetworker {
|
||||
private authKeyUint8: Uint8Array;
|
||||
|
||||
private isFileNetworker: boolean;
|
||||
public isFileNetworker: boolean;
|
||||
private isFileUpload: boolean;
|
||||
private isFileDownload: boolean;
|
||||
|
||||
@ -92,7 +92,7 @@ export default class MTPNetworker {
|
||||
private pendingMessages: {[msgId: string]: number} = {};
|
||||
private pendingAcks: Array<string> = [];
|
||||
private pendingResends: Array<string> = [];
|
||||
private connectionInited = false;
|
||||
public connectionInited = false;
|
||||
|
||||
private nextReqTimeout: number;
|
||||
private nextReq: number = 0;
|
||||
@ -307,7 +307,7 @@ export default class MTPNetworker {
|
||||
serializer.storeString(App.version + (App.isMainDomain ? ' ' + App.suffix : ''), 'app_version');
|
||||
serializer.storeString(navigator.language || 'en', 'system_lang_code');
|
||||
serializer.storeString(App.langPack, 'lang_pack');
|
||||
serializer.storeString(navigator.language || 'en', 'lang_code');
|
||||
serializer.storeString(networkerFactory.language, 'lang_code');
|
||||
//serializer.storeInt(0x0, 'proxy');
|
||||
/* serializer.storeMethod('initConnection', {
|
||||
'flags': 0,
|
||||
@ -698,8 +698,8 @@ export default class MTPNetworker {
|
||||
this.isOnline = online;
|
||||
|
||||
if(willChange) {
|
||||
if(NetworkerFactory.onConnectionStatusChange) {
|
||||
NetworkerFactory.onConnectionStatusChange({
|
||||
if(networkerFactory.onConnectionStatusChange) {
|
||||
networkerFactory.onConnectionStatusChange({
|
||||
_: 'networkerStatus',
|
||||
online: this.isOnline,
|
||||
dcId: this.dcId,
|
||||
@ -792,7 +792,7 @@ export default class MTPNetworker {
|
||||
}
|
||||
|
||||
public isStopped() {
|
||||
return NetworkerFactory.akStopped && !this.isFileNetworker;
|
||||
return networkerFactory.akStopped && !this.isFileNetworker;
|
||||
}
|
||||
|
||||
private performScheduledRequest() {
|
||||
@ -1544,8 +1544,8 @@ export default class MTPNetworker {
|
||||
this.applyServerSalt(message.server_salt);
|
||||
|
||||
sessionStorage.get('dc').then((baseDcId) => {
|
||||
if(baseDcId === this.dcId && !this.isFileNetworker && NetworkerFactory.updatesProcessor) {
|
||||
NetworkerFactory.updatesProcessor(message);
|
||||
if(baseDcId === this.dcId && !this.isFileNetworker && networkerFactory.updatesProcessor) {
|
||||
networkerFactory.updatesProcessor(message);
|
||||
}
|
||||
});
|
||||
break;
|
||||
@ -1649,8 +1649,8 @@ export default class MTPNetworker {
|
||||
this.log.debug('Update', message);
|
||||
} */
|
||||
|
||||
if(NetworkerFactory.updatesProcessor !== null) {
|
||||
NetworkerFactory.updatesProcessor(message);
|
||||
if(networkerFactory.updatesProcessor !== null) {
|
||||
networkerFactory.updatesProcessor(message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -12,9 +12,12 @@
|
||||
import MTPNetworker from "./networker";
|
||||
import { ConnectionStatusChange, InvokeApiOptions } from "../../types";
|
||||
import MTTransport from "./transports/transport";
|
||||
import App from "../../config/app";
|
||||
import { MOUNT_CLASS_TO } from "../../config/debug";
|
||||
|
||||
export class NetworkerFactory {
|
||||
private networkers: MTPNetworker[] = [];
|
||||
public language = navigator.language || App.langPackCode;
|
||||
public updatesProcessor: (obj: any) => void = null;
|
||||
public onConnectionStatusChange: (info: ConnectionStatusChange) => void = null;
|
||||
public akStopped = false;
|
||||
@ -46,6 +49,17 @@ export class NetworkerFactory {
|
||||
public stopAll() {
|
||||
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_peer_type_settings': {key: Exclude<NotifyPeer['_'], 'notifyPeer'>, settings: PeerNotifySettings},
|
||||
|
||||
'language_change': void,
|
||||
'language_change': string,
|
||||
|
||||
'theme_change': void,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user