diff --git a/ext/src/ui/options/Bridge.tsx b/ext/src/ui/options/Bridge.tsx index 41ce7b3..b18d381 100644 --- a/ext/src/ui/options/Bridge.tsx +++ b/ext/src/ui/options/Bridge.tsx @@ -112,7 +112,6 @@ interface BridgeState { wasErrorCheckingUpdates: boolean; checkUpdatesEllipsis: string; updateStatus: string; - packageType: string; } export default class Bridge extends Component { @@ -128,14 +127,12 @@ export default class Bridge extends Component { , wasErrorCheckingUpdates: false , checkUpdatesEllipsis: "..." , updateStatus: null - , packageType: null }; this.onCheckUpdates = this.onCheckUpdates.bind(this); this.onCheckUpdatesResponse = this.onCheckUpdatesResponse.bind(this); this.onCheckUpdatesError = this.onCheckUpdatesError.bind(this); this.onUpdate = this.onUpdate.bind(this); - this.onPackageTypeChange = this.onPackageTypeChange.bind(this); } public render () { @@ -156,24 +153,8 @@ export default class Bridge extends Component { { _("optionsBridgeUpdateAvailable") }

- { this.props.platform === "linux" && - }
@@ -264,65 +245,9 @@ export default class Bridge extends Component { .catch(this.onCheckUpdatesError); } - private showUpdateStatus () { - if (this.updateStatusTimeout) { - window.clearTimeout(this.updateStatusTimeout); - } - this.updateStatusTimeout = window.setTimeout(() => { - this.setState({ - updateStatus: null - }); - }, 1500); - } - - private async onUpdate () { - // Current window to base centered position on - const win = await browser.windows.getCurrent(); - const centeredProps = getWindowCenteredProps(win, 400, 150); - - const updaterPopup = await browser.windows.create({ - url: "../updater/index.html" - , type: "popup" - , ...centeredProps - }); - - // Size/position not set correctly on creation (bug?) - await browser.windows.update(updaterPopup.id, { - ...centeredProps - }); - - browser.runtime.onConnect.addListener(port => { - if (port.name === "updater") { - const asset = this.updateData.assets.find((currentAsset: any) => { - const fileExtension = currentAsset.name.match(/.*\.(.*)$/).pop(); - const currentPlatform = (this.props.platform === "linux") - ? this.state.packageType - : this.props.platform; - - switch (fileExtension) { - case "exe": return "win" === currentPlatform; - case "pkg": return "mac" === currentPlatform; - case "deb": return "deb" === currentPlatform; - case "rpm": return "rpm" === currentPlatform; - } - }); - - port.postMessage({ - subject: "updater:/updateData" - , data: asset - }); - - port.onDisconnect.addListener(() => { - browser.windows.remove(updaterPopup.id); - }); - } - }); - } - - private async onCheckUpdatesResponse (res: any) { - const isUpdateAvailable = !this.props.info || semver.lt( - this.props.info.version, res.tag_name); + const isUpdateAvailable = !this.props.info || + semver.lt(this.props.info.version, res.tag_name); if (isUpdateAvailable) { this.updateData = res; @@ -349,9 +274,23 @@ export default class Bridge extends Component { this.showUpdateStatus(); } - private onPackageTypeChange (ev: React.ChangeEvent) { - this.setState({ - packageType: ev.target.value - }); + private showUpdateStatus () { + if (this.updateStatusTimeout) { + window.clearTimeout(this.updateStatusTimeout); + } + this.updateStatusTimeout = window.setTimeout(() => { + this.setState({ + updateStatus: null + }); + }, 1500); + } + + private async onUpdate () { + // Open downloads page + if (this.updateData.html_url) { + browser.tabs.create({ + url: this.updateData.html_url + }); + } } } diff --git a/ext/src/ui/updater/index.html b/ext/src/ui/updater/index.html deleted file mode 100644 index 5e9b10e..0000000 --- a/ext/src/ui/updater/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - -
- - diff --git a/ext/src/ui/updater/index.tsx b/ext/src/ui/updater/index.tsx deleted file mode 100644 index 0f3c2d2..0000000 --- a/ext/src/ui/updater/index.tsx +++ /dev/null @@ -1,247 +0,0 @@ -"use strict"; - -import React, { Component } from "react"; -import ReactDOM from "react-dom"; - -import { getNextEllipsis } from "../../lib/utils"; -import { DownloadDelta, Message } from "../../types"; - -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 UpdaterProps { - description: string; - additionalDescription: string; - downloadTotal: number; - downloadCurrent: number; - isDownloading: boolean; - onCancel (): void; - onInstall (): void; -} - -const Updater = (props: UpdaterProps) => ( -
-
- { props.description } -
-
- { props.additionalDescription } -
- - - - -
-); - - -interface UpdaterAppState { - hasLoaded: boolean; - isDownloading: boolean; - description: string; - additionalDescription: string; - downloadTotal: number; - downloadCurrent: number; -} - -class UpdaterApp extends Component<{}, UpdaterAppState> { - private downloadId: number; - private downloadProgressInterval: number; - private port: browser.runtime.Port; - private frameWidth: number; - private frameHeight: number; - private win: browser.windows.Window; - - constructor (props: {}) { - super(props); - - this.downloadId = null; - this.downloadProgressInterval = null; - - this.onMessage = this.onMessage.bind(this); - this.onDownloadChanged = this.onDownloadChanged.bind(this); - this.updateDownloadProgress = this.updateDownloadProgress.bind(this); - this.onCancel = this.onCancel.bind(this); - this.onInstall = this.onInstall.bind(this); - - this.state = { - hasLoaded: false - , isDownloading: true - , description: _("updaterDescriptionDownloading") - , additionalDescription: _("updaterAdditionalDescriptionDownloading") - , downloadTotal: 0 - , downloadCurrent: 0 - }; - } - - public async componentDidMount () { - this.port = browser.runtime.connect({ - name: "updater" - }); - - this.port.onMessage.addListener(this.onMessage); - browser.downloads.onChanged.addListener(this.onDownloadChanged); - } - - public componentDidUpdate () { - // Size window to content - browser.windows.update(this.win.id, { - width: document.body.clientWidth + this.frameWidth - , height: document.body.clientHeight + this.frameHeight - }); - } - - public render () { - if (!this.state.hasLoaded) { - return; - } - - return ( - - ); - } - - private async onMessage (message: Message) { - switch (message.subject) { - case "updater:/updateData": { - // Only run once - if (this.downloadId) { - return; - } - - this.win = await browser.windows.getCurrent(); - this.frameWidth = this.win.width - window.innerWidth; - this.frameHeight = this.win.height - window.innerHeight; - - // Cleanup - if (this.downloadId) { - browser.downloads.cancel(this.downloadId); - } - if (this.downloadProgressInterval) { - window.clearInterval(this.downloadProgressInterval); - } - - this.downloadId = await browser.downloads.download({ - url: message.data.browser_download_url - , filename: message.data.name - }); - - this.updateDownloadProgress(); - - this.downloadProgressInterval = window.setInterval( - this.updateDownloadProgress, 500); - - this.setState({ - hasLoaded: true - , isDownloading: true - }); - - break; - } - } - } - - private closeWindow () { - window.clearInterval(this.downloadProgressInterval); - browser.downloads.onChanged.removeListener(this.onDownloadChanged); - this.port.onMessage.removeListener(this.onMessage); - this.port.disconnect(); - } - - private onDownloadChanged (downloadItem: DownloadDelta) { - if (downloadItem.id !== this.downloadId) { - return; - } - - if (downloadItem.canResume) { - // Paused - if (downloadItem.canResume.current) { - window.clearInterval(this.downloadProgressInterval); - this.setState({ - isDownloading: false - }); - - // Cancelled - } else { - window.clearInterval(this.downloadProgressInterval); - this.setState({ - isDownloading: false - }); - } - - // Download finished - } else if (downloadItem.state - && downloadItem.state.current === "complete") { - - window.clearInterval(this.downloadProgressInterval); - this.setState({ - isDownloading: false - , downloadTotal: 1 - , downloadCurrent: 1 - , description: _("updaterDescriptionInstallReady") - , additionalDescription: - _("updaterAdditionalDescriptionInstallReady") - }); - } - } - - private async updateDownloadProgress () { - const [ download ] = await browser.downloads.search({ - id: this.downloadId - }); - - this.setState({ - downloadTotal: download.totalBytes - , downloadCurrent: download.bytesReceived - }); - } - - private async onCancel () { - try { - await browser.downloads.cancel(this.downloadId); - this.closeWindow(); - } catch (err) { - // Already cancelled or finished - } - } - - private async onInstall () { - try { - await browser.downloads.open(this.downloadId); - this.closeWindow(); - } catch (err) { - // Cancelled or not finished - } - } -} - -ReactDOM.render( - - , document.querySelector("#root")); diff --git a/ext/src/ui/updater/styles/index.css b/ext/src/ui/updater/styles/index.css deleted file mode 100755 index 0595c86..0000000 --- a/ext/src/ui/updater/styles/index.css +++ /dev/null @@ -1,38 +0,0 @@ -body { - background: -moz-dialog; - color: -moz-dialogtext; - margin: initial; - font: message-box; -} - -.updater { - align-items: center; - display: grid; - gap: 0.75em; - grid-template-rows: min-content min-content 1fr min-content; - grid-template-columns: 1fr min-content min-content; - grid-template-areas: - "description description description" - "additional-description additional-description additional-description" - "progress progress progress" - ". cancel install"; - padding: 0.75em; -} - -.updater__description { - grid-area: description; -} -.updater__additional-description { - font-size: 0.9em; - grid-area: additional-description; - margin-top: -0.75em; -} -.updater__progress { - grid-area: progress; -} -.updater__install { - grid-area: install; -} -.updater__cancel { - grid-area: cancel; -} diff --git a/ext/src/ui/updater/styles/mac.css b/ext/src/ui/updater/styles/mac.css deleted file mode 100755 index e146c75..0000000 --- a/ext/src/ui/updater/styles/mac.css +++ /dev/null @@ -1,13 +0,0 @@ -body { - background: rgb(236, 236, 236); - font: menu; -} - -button, -select { - font: inherit; -} - -button:not([disabled]):hover:active { - color: -moz-mac-buttonactivetext; -} diff --git a/ext/webpack.config.js b/ext/webpack.config.js index b028fec..1cdf068 100755 --- a/ext/webpack.config.js +++ b/ext/webpack.config.js @@ -17,7 +17,6 @@ module.exports = (env) => ({ // UI , "ui/popup/bundle": `${env.includePath}/ui/popup/index.tsx` , "ui/options/bundle": `${env.includePath}/ui/options/index.tsx` - , "ui/updater/bundle": `${env.includePath}/ui/updater/index.tsx` // Sender apps , "senders/mediaCast": `${env.includePath}/senders/mediaCast.ts`