/* 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 "../../receiver_selectors/ReceiverSelector"; 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; availableMediaTypes: ReceiverSelectorMediaType; isLoading: boolean; filePath: string; } class PopupApp extends Component<{}, PopupAppState> { private port: browser.runtime.Port; private win: browser.windows.Window; private defaultMediaType: ReceiverSelectorMediaType; constructor (props: {}) { super(props); this.state = { receivers: [] , mediaType: ReceiverSelectorMediaType.App , availableMediaTypes: ReceiverSelectorMediaType.App , isLoading: false , filePath: null }; // 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.defaultMediaType = message.data.defaultMediaType; this.setState({ receivers: message.data.receivers , mediaType: this.defaultMediaType , availableMediaTypes: message.data.availableMediaTypes }); 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 () { let truncatedFileName: string; if (this.state.filePath) { const filePath = this.state.filePath; const fileName = filePath.substring(filePath.lastIndexOf("/") + 1); truncatedFileName = fileName.length > 12 ? `${fileName.substring(0, 12)}...` : fileName; } return (