/* tslint:disable:max-line-length */ "use strict"; import React, { Component } from "react"; import ReactDOM from "react-dom"; import { getNextEllipsis } from "../../lib/utils"; import { Message, Receiver } from "../../types"; import { ReceiverSelectorMediaType } from "../../receiverSelectorManager/ReceiverSelectorManager"; const _ = browser.i18n.getMessage; // macOS styles browser.runtime.getPlatformInfo() .then(platformInfo => { if (platformInfo.os === "mac") { const link = document.createElement("link"); link.rel = "stylesheet"; link.href = "styles/mac.css"; document.head.appendChild(link); } }); interface PopupAppState { receivers: Receiver[]; mediaType: ReceiverSelectorMediaType; isLoading: boolean; } class PopupApp extends Component<{}, PopupAppState> { private port: browser.runtime.Port; private win: browser.windows.Window; constructor (props: {}) { super(props); this.state = { receivers: [] , mediaType: ReceiverSelectorMediaType.App , isLoading: false }; // Store window ref browser.windows.getCurrent().then(win => { this.win = win; }); this.onSelectChange = this.onSelectChange.bind(this); this.onCast = this.onCast.bind(this); } public componentDidMount () { this.port = browser.runtime.connect({ name: "popup" }); this.port.onMessage.addListener((message: Message) => { switch (message.subject) { case "popup:/populateReceiverList": { this.setState({ receivers: message.data.receivers , mediaType: message.data.defaultMediaType }); break; } case "popup:/close": { window.close(); break; } } }); } public componentDidUpdate () { setTimeout(() => { // Fit window to content height const frameHeight = window.outerHeight - window.innerHeight; const windowHeight = document.body.clientHeight + frameHeight; browser.windows.update(this.win.id, { height: windowHeight }); }, 1) } public render () { const shareMedia = this.state.mediaType === ReceiverSelectorMediaType.Tab || this.state.mediaType === ReceiverSelectorMediaType.Screen return (