fix: connect before running a script
This commit is contained in:
parent
46aecc5384
commit
216d62d81e
1 changed files with 11 additions and 0 deletions
|
@ -141,6 +141,16 @@ window.addEventListener('message', async ({ data }) => {
|
||||||
currentScriptId = nanoid()
|
currentScriptId = nanoid()
|
||||||
await swInvokeMethodInner({ event: 'UPLOAD_SCRIPT', name: currentScriptId, files: data.files }, asNonNull(navigator.serviceWorker.controller))
|
await swInvokeMethodInner({ event: 'UPLOAD_SCRIPT', name: currentScriptId, files: data.files }, asNonNull(navigator.serviceWorker.controller))
|
||||||
|
|
||||||
|
if (!window.tg) {
|
||||||
|
// shouldnt happen but just in case
|
||||||
|
console.warn('[mtcute-repl] Telegram client not initialized yet')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastConnectionState === 'offline') {
|
||||||
|
await window.tg.connect()
|
||||||
|
}
|
||||||
|
|
||||||
const el = document.createElement('script')
|
const el = document.createElement('script')
|
||||||
el.type = 'module'
|
el.type = 'module'
|
||||||
let script = `import * as result from "/sw/runtime/script/${currentScriptId}/main.js";`
|
let script = `import * as result from "/sw/runtime/script/${currentScriptId}/main.js";`
|
||||||
|
@ -177,6 +187,7 @@ window.addEventListener('message', async ({ data }) => {
|
||||||
initClient(lastAccountId, data.verboseLogs)
|
initClient(lastAccountId, data.verboseLogs)
|
||||||
}
|
}
|
||||||
window.parent.postMessage({ event: 'CONNECTION_STATE', value: 'offline' }, HOST_ORIGIN)
|
window.parent.postMessage({ event: 'CONNECTION_STATE', value: 'offline' }, HOST_ORIGIN)
|
||||||
|
lastConnectionState = 'offline'
|
||||||
} else if (data.event === 'RECONNECT') {
|
} else if (data.event === 'RECONNECT') {
|
||||||
if (window.tg !== undefined) {
|
if (window.tg !== undefined) {
|
||||||
window.tg.connect()
|
window.tg.connect()
|
||||||
|
|
Loading…
Reference in a new issue