Remove updater

This commit is contained in:
hensm
2019-06-25 01:42:02 +01:00
parent 90e289d51a
commit fbd2b1eaa9
6 changed files with 21 additions and 392 deletions

View File

@@ -112,7 +112,6 @@ interface BridgeState {
wasErrorCheckingUpdates: boolean;
checkUpdatesEllipsis: string;
updateStatus: string;
packageType: string;
}
export default class Bridge extends Component<BridgeProps, BridgeState> {
@@ -128,14 +127,12 @@ export default class Bridge extends Component<BridgeProps, BridgeState> {
, 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<BridgeProps, BridgeState> {
{ _("optionsBridgeUpdateAvailable") }
</p>
<div className="bridge__update-options">
{ this.props.platform === "linux" &&
<select className="bridge__update-package-type"
onChange={ this.onPackageTypeChange }
value={ this.state.packageType }>
<option value="" disabled selected>
{ _("optionsBridgeUpdatePackageTypeSelect") }
</option>
<option value="deb">
{ _("optionsBridgeUpdatePackageTypeDeb") }
</option>
<option value="rpm">
{ _("optionsBridgeUpdatePackageTypeRpm") }
</option>
</select> }
<button className="bridge__update-start"
onClick={ this.onUpdate }
disabled={ this.props.platform === "linux"
&& !this.state.packageType }>
onClick={ this.onUpdate }>
{ _("optionsBridgeUpdate") }
</button>
</div>
@@ -264,65 +245,9 @@ export default class Bridge extends Component<BridgeProps, BridgeState> {
.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<BridgeProps, BridgeState> {
this.showUpdateStatus();
}
private onPackageTypeChange (ev: React.ChangeEvent<HTMLSelectElement>) {
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
});
}
}
}

View File

@@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="styles/index.css">
<script src="bundle.js" defer></script>
</head>
<body>
<div id="root"></div>
</body>
</html>

View File

@@ -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) => (
<div className="updater">
<div className="updater__description">
{ props.description }
</div>
<div className="updater__additional-description">
{ props.additionalDescription }
</div>
<progress className="updater__progress"
max={ props.downloadTotal }
value={ props.downloadCurrent }>
</progress>
<button className="updater__install"
onClick={ props.onInstall }
disabled={ props.isDownloading }>
{ _("updaterInstall") }
</button>
<button className="updater__cancel"
onClick={ props.onCancel }
disabled={ !props.isDownloading }>
{ _("updaterCancel") }
</button>
</div>
);
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 (
<Updater description={ this.state.description }
additionalDescription={ this.state.additionalDescription }
downloadTotal={ this.state.downloadTotal }
downloadCurrent={ this.state.downloadCurrent }
isDownloading={ this.state.isDownloading }
onCancel={ this.onCancel }
onInstall={ this.onInstall } />
);
}
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(
<UpdaterApp />
, document.querySelector("#root"));

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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`