|
| 1 | +import {getWindowClients} from '../../helpers/context'; |
| 2 | +import {IS_BETA} from '../../config/debug'; |
| 3 | + |
| 4 | +import {logger, LogTypes} from '../logger'; |
| 5 | + |
| 6 | + |
| 7 | +const logMtprotoBug = logger('SW-mtproto-bug', LogTypes.Debug); |
| 8 | + |
| 9 | +type Args = { |
| 10 | + connectedWindows: Map<string, WindowClient>; |
| 11 | + onWindowConnected: (source: WindowClient) => void; |
| 12 | +}; |
| 13 | + |
| 14 | +export function watchMtprotoOnDev({connectedWindows, onWindowConnected}: Args) { |
| 15 | + if(IS_BETA) setInterval(() => { |
| 16 | + logMtprotoBug.debug('checking'); |
| 17 | + |
| 18 | + if(!connectedWindows.size) { |
| 19 | + getWindowClients().then((windowClients) => { |
| 20 | + logMtprotoBug.debug(`got ${windowClients.length} windows`); |
| 21 | + |
| 22 | + windowClients.forEach((windowClient) => { |
| 23 | + onWindowConnected(windowClient); |
| 24 | + }); |
| 25 | + }); |
| 26 | + } else { |
| 27 | + logMtprotoBug.debug('has-windows'); |
| 28 | + } |
| 29 | + |
| 30 | + // const timeout = self.setTimeout(() => { |
| 31 | + // if(!connectedWindows.size) return; |
| 32 | + |
| 33 | + // logMtprotoBug.debug('triggered'); |
| 34 | + |
| 35 | + // if(_mtprotoMessagePort) serviceMessagePort.detachPort(_mtprotoMessagePort); |
| 36 | + // else serviceMessagePort.cancelAllTasks(); |
| 37 | + // logMtprotoBug.debug('cleared port ', _mtprotoMessagePort ? 'attached' : 'all'); |
| 38 | + |
| 39 | + // const it = connectedWindows.values().next(); |
| 40 | + // if(!it.done) { |
| 41 | + // sendMessagePort(it.value); |
| 42 | + // logMtprotoBug.debug('updated port'); |
| 43 | + // } |
| 44 | + // }, 0.5e3); |
| 45 | + |
| 46 | + // serviceMessagePort.invoke('pingMtProtoWorker', undefined).catch(noop).finally(() => { |
| 47 | + // self.clearTimeout(timeout); |
| 48 | + // }); |
| 49 | + }, 2e3); |
| 50 | +} |
0 commit comments