Compare commits
No commits in common. "2970738c8920c0d2311c10206c9b6298c98304f3" and "a674e402a01f9773d5323bcba2973cd75b95338b" have entirely different histories.
2970738c89
...
a674e402a0
3 changed files with 9 additions and 29 deletions
|
@ -82,8 +82,7 @@ export async function setupMonaco() {
|
||||||
extraLibs.push({
|
extraLibs.push({
|
||||||
content:
|
content:
|
||||||
'declare const tg: import("@mtcute/web").TelegramClient;\n'
|
'declare const tg: import("@mtcute/web").TelegramClient;\n'
|
||||||
+ 'declare const Long: import("@mtcute/web").Long;\n'
|
+ 'declare const Long: import("@mtcute/web").Long;',
|
||||||
+ 'declare const setMiddlewareOptions: (options: import("@mtcute/web").networkMiddlewares.BasicMiddlewaresOptions) => Promise<void>;',
|
|
||||||
filePath: 'file:///tg.d.ts',
|
filePath: 'file:///tg.d.ts',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,6 @@ export function Runner(props: {
|
||||||
setRunnerLoaded(false)
|
setRunnerLoaded(false)
|
||||||
setConnectionState('offline')
|
setConnectionState('offline')
|
||||||
setDead(false)
|
setDead(false)
|
||||||
setRunning(false)
|
|
||||||
timers.clearTimeout(deadTimer)
|
timers.clearTimeout(deadTimer)
|
||||||
|
|
||||||
const iframe = document.createElement('iframe')
|
const iframe = document.createElement('iframe')
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import type { BaseTelegramClientOptions, ConnectionState } from '@mtcute/web'
|
|
||||||
import { asNonNull } from '@fuman/utils'
|
import { asNonNull } from '@fuman/utils'
|
||||||
import { FileLocation, Long, networkMiddlewares, TelegramClient } from '@mtcute/web'
|
import { FileLocation, Long, TelegramClient } from '@mtcute/web'
|
||||||
import { nanoid } from 'nanoid'
|
import { nanoid } from 'nanoid'
|
||||||
import { swInvokeMethodInner } from '../client-inner.ts'
|
import { swInvokeMethodInner } from '../client-inner.ts'
|
||||||
import { createFileDownload } from '../download/client.ts'
|
import { createFileDownload } from '../download/client.ts'
|
||||||
|
|
||||||
|
type ConnectionState = import('@mtcute/web').ConnectionState
|
||||||
|
type TelegramClientOptions = import('@mtcute/web').TelegramClientOptions
|
||||||
|
|
||||||
const HOST_ORIGIN = import.meta.env.VITE_HOST_ORIGIN
|
const HOST_ORIGIN = import.meta.env.VITE_HOST_ORIGIN
|
||||||
|
|
||||||
declare const chobitsu: any
|
declare const chobitsu: any
|
||||||
|
@ -13,7 +15,6 @@ declare const window: typeof globalThis & {
|
||||||
__currentScript: any
|
__currentScript: any
|
||||||
__handleScriptEnd: (error: any) => void
|
__handleScriptEnd: (error: any) => void
|
||||||
tg: import('@mtcute/web').TelegramClient
|
tg: import('@mtcute/web').TelegramClient
|
||||||
setMiddlewareOptions: (options: networkMiddlewares.BasicMiddlewaresOptions) => Promise<void>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(globalThis, 'Long', { value: Long })
|
Object.defineProperty(globalThis, 'Long', { value: Long })
|
||||||
|
@ -34,29 +35,14 @@ chobitsu.setOnMessage((message: string) => {
|
||||||
|
|
||||||
let lastAccountId: string | undefined
|
let lastAccountId: string | undefined
|
||||||
let lastConnectionState: ConnectionState | undefined
|
let lastConnectionState: ConnectionState | undefined
|
||||||
let lastMiddlewareOptions: networkMiddlewares.BasicMiddlewaresOptions | undefined
|
|
||||||
let currentScriptId: string | undefined
|
let currentScriptId: string | undefined
|
||||||
let logUpdates = false
|
let logUpdates = false
|
||||||
let verboseLogs = false
|
let verboseLogs = false
|
||||||
|
|
||||||
Object.defineProperty(globalThis, 'setMiddlewareOptions', {
|
|
||||||
value: async (options: networkMiddlewares.BasicMiddlewaresOptions) => {
|
|
||||||
if (JSON.stringify(options) === JSON.stringify(lastMiddlewareOptions)) return
|
|
||||||
lastMiddlewareOptions = options
|
|
||||||
if (window.tg) {
|
|
||||||
await window.tg.close()
|
|
||||||
initClient(lastAccountId!, verboseLogs)
|
|
||||||
if (lastConnectionState !== 'offline') {
|
|
||||||
await window.tg.connect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
function initClient(accountId: string, verbose: boolean) {
|
function initClient(accountId: string, verbose: boolean) {
|
||||||
lastAccountId = accountId
|
lastAccountId = accountId
|
||||||
|
|
||||||
const extraConfig: Partial<BaseTelegramClientOptions> = {}
|
let extraConfig: Partial<TelegramClientOptions> | undefined
|
||||||
|
|
||||||
const storedAccounts = localStorage.getItem('repl:accounts')
|
const storedAccounts = localStorage.getItem('repl:accounts')
|
||||||
if (storedAccounts) {
|
if (storedAccounts) {
|
||||||
|
@ -65,13 +51,9 @@ function initClient(accountId: string, verbose: boolean) {
|
||||||
if (!ourAccount) return
|
if (!ourAccount) return
|
||||||
|
|
||||||
if (ourAccount && ourAccount.testMode) {
|
if (ourAccount && ourAccount.testMode) {
|
||||||
extraConfig.testMode = true
|
extraConfig = {
|
||||||
}
|
testMode: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastMiddlewareOptions) {
|
|
||||||
extraConfig.network = {
|
|
||||||
middlewares: networkMiddlewares.basic(lastMiddlewareOptions),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue