Lock Screen: Fix page reload on iOS (#2898)
This commit is contained in:
parent
2bdc5774ab
commit
bd21dc05f7
@ -21,7 +21,7 @@ type RequestStates = {
|
||||
const HEALTH_CHECK_TIMEOUT = 150;
|
||||
const HEALTH_CHECK_MIN_DELAY = 5 * 1000; // 5 sec
|
||||
|
||||
let worker: Worker;
|
||||
let worker: Worker | undefined;
|
||||
const requestStates = new Map<string, RequestStates>();
|
||||
const requestStatesByCallback = new Map<AnyToVoidFunction, RequestStates>();
|
||||
const savedLocalDb: LocalDb = {
|
||||
@ -55,7 +55,11 @@ export function initApiOnMasterTab(initialArgs: ApiInitialArgs) {
|
||||
});
|
||||
}
|
||||
|
||||
let updateCallback: OnApiUpdate;
|
||||
|
||||
export function initApi(onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs) {
|
||||
updateCallback = onUpdate;
|
||||
|
||||
if (!isMasterTab) {
|
||||
initApiOnMasterTab(initialArgs);
|
||||
return Promise.resolve();
|
||||
@ -212,14 +216,14 @@ export function cancelApiProgress(progressCallback: ApiOnProgress) {
|
||||
}
|
||||
|
||||
export function cancelApiProgressMaster(messageId: string) {
|
||||
worker.postMessage({
|
||||
worker?.postMessage({
|
||||
type: 'cancelProgress',
|
||||
messageId,
|
||||
});
|
||||
}
|
||||
|
||||
function subscribeToWorker(onUpdate: OnApiUpdate) {
|
||||
worker.addEventListener('message', ({ data }: WorkerMessageEvent) => {
|
||||
worker?.addEventListener('message', ({ data }: WorkerMessageEvent) => {
|
||||
if (data.type === 'update') {
|
||||
onUpdate(data.update);
|
||||
} else if (data.type === 'methodResponse') {
|
||||
@ -330,7 +334,7 @@ function makeRequest(message: OriginRequest) {
|
||||
}
|
||||
});
|
||||
|
||||
worker.postMessage(payload);
|
||||
worker?.postMessage(payload);
|
||||
|
||||
return promise;
|
||||
}
|
||||
@ -360,7 +364,9 @@ async function ensureWorkerPing() {
|
||||
console.error(err);
|
||||
|
||||
if (Date.now() - startedAt >= HEALTH_CHECK_MIN_DELAY) {
|
||||
window.location.reload();
|
||||
worker?.terminate();
|
||||
worker = undefined;
|
||||
updateCallback({ '@type': 'requestInitApi' });
|
||||
}
|
||||
} finally {
|
||||
isResolved = true;
|
||||
|
||||
@ -609,6 +609,10 @@ export type ApiUpdateMessageTranslations = {
|
||||
toLanguageCode: string;
|
||||
};
|
||||
|
||||
export type ApiRequestInitApi = {
|
||||
'@type': 'requestInitApi';
|
||||
};
|
||||
|
||||
export type ApiUpdate = (
|
||||
ApiUpdateReady | ApiUpdateSession | ApiUpdateWebAuthTokenFailed | ApiUpdateRequestUserUpdate |
|
||||
ApiUpdateAuthorizationState | ApiUpdateAuthorizationError | ApiUpdateConnectionState | ApiUpdateCurrentUser |
|
||||
@ -634,7 +638,8 @@ export type ApiUpdate = (
|
||||
ApiUpdatePhoneCall | ApiUpdatePhoneCallSignalingData | ApiUpdatePhoneCallMediaState |
|
||||
ApiUpdatePhoneCallConnectionState | ApiUpdateBotMenuButton | ApiUpdateTranscribedAudio | ApiUpdateUserEmojiStatus |
|
||||
ApiUpdateMessageExtendedMedia | ApiUpdateConfig | ApiUpdateTopicNotifyExceptions | ApiUpdatePinnedTopic |
|
||||
ApiUpdatePinnedTopicsOrder | ApiUpdateTopic | ApiUpdateTopics | ApiUpdateRecentEmojiStatuses
|
||||
ApiUpdatePinnedTopicsOrder | ApiUpdateTopic | ApiUpdateTopics | ApiUpdateRecentEmojiStatuses |
|
||||
ApiRequestInitApi
|
||||
);
|
||||
|
||||
export type OnApiUpdate = (update: ApiUpdate) => void;
|
||||
|
||||
@ -57,6 +57,10 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
onUpdateCurrentUser(global, update);
|
||||
break;
|
||||
|
||||
case 'requestInitApi':
|
||||
actions.initApi();
|
||||
break;
|
||||
|
||||
case 'error': {
|
||||
if (update.error.message === 'SESSION_REVOKED') {
|
||||
actions.signOut({ forceInitApi: true });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user