Telegram Web K with changes to work inside I2P
https://web.telegram.i2p/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
/* |
|
* https://github.com/morethanwords/tweb |
|
* Copyright (C) 2019-2021 Eduard Kuzmenko |
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE |
|
*/ |
|
|
|
import type { TabState } from "../mtproto/mtprotoworker"; |
|
import { MOUNT_CLASS_TO } from "../../config/debug"; |
|
import MTProtoMessagePort from "../mtproto/mtprotoMessagePort"; |
|
|
|
type Tab = { |
|
source: MessageEventSource, |
|
state: TabState |
|
}; |
|
|
|
export class AppTabsManager { |
|
private tabs: Map<Tab['source'], Tab>; |
|
|
|
constructor() { |
|
this.tabs = new Map(); |
|
} |
|
|
|
public start() { |
|
const port = MTProtoMessagePort.getInstance<false>(); |
|
|
|
port.addEventListener('tabState', (state, source) => { |
|
const tab = this.tabs.get(source); |
|
tab.state = state; |
|
}); |
|
} |
|
|
|
public getTabs() { |
|
return [...this.tabs.values()].filter((tab) => !!tab.state); |
|
} |
|
|
|
public addTab(source: MessageEventSource) { |
|
const tab: Tab = { |
|
source, |
|
state: undefined |
|
}; |
|
|
|
this.tabs.set(source, tab); |
|
} |
|
|
|
public deleteTab(source: MessageEventSource) { |
|
this.tabs.delete(source); |
|
} |
|
} |
|
|
|
const appTabsManager = new AppTabsManager(); |
|
MOUNT_CLASS_TO && (MOUNT_CLASS_TO.appTabsManager = appTabsManager); |
|
export default appTabsManager;
|
|
|