Adaptive Update Dialog
This commit is contained in:
+41
-17
@@ -34,6 +34,7 @@ import { UpdateStatus, UpdateRelease, UpdatePolicyT, intToUpdatePolicyT } from '
|
|||||||
import { PiPedalModelFactory, PiPedalModel } from './PiPedalModel';
|
import { PiPedalModelFactory, PiPedalModel } from './PiPedalModel';
|
||||||
import Select from '@mui/material/Select';
|
import Select from '@mui/material/Select';
|
||||||
import MenuItem from '@mui/material/MenuItem';
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
|
import ResizeResponsiveComponent from './ResizeResponsiveComponent';
|
||||||
|
|
||||||
|
|
||||||
const UPDATE_CHECK_DELAY = 86400000; // one day in ms.
|
const UPDATE_CHECK_DELAY = 86400000; // one day in ms.
|
||||||
@@ -47,12 +48,12 @@ export interface UpdateDialogProps {
|
|||||||
|
|
||||||
export interface UpdateDialogState {
|
export interface UpdateDialogState {
|
||||||
updateStatus: UpdateStatus;
|
updateStatus: UpdateStatus;
|
||||||
compactLandscape: boolean;
|
compactWidth: boolean;
|
||||||
alertDialogOpen: boolean;
|
alertDialogOpen: boolean;
|
||||||
alertDialogMessage: string;
|
alertDialogMessage: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class UpdateDialog extends React.Component<UpdateDialogProps, UpdateDialogState> {
|
export default class UpdateDialog extends ResizeResponsiveComponent<UpdateDialogProps, UpdateDialogState> {
|
||||||
private model: PiPedalModel;
|
private model: PiPedalModel;
|
||||||
|
|
||||||
constructor(props: UpdateDialogProps) {
|
constructor(props: UpdateDialogProps) {
|
||||||
@@ -61,12 +62,13 @@ export default class UpdateDialog extends React.Component<UpdateDialogProps, Upd
|
|||||||
let updateStatus = this.model.updateStatus.get();
|
let updateStatus = this.model.updateStatus.get();
|
||||||
this.state = {
|
this.state = {
|
||||||
updateStatus: updateStatus,
|
updateStatus: updateStatus,
|
||||||
compactLandscape: false,
|
compactWidth: this.isCompactWidth(),
|
||||||
alertDialogOpen: false,
|
alertDialogOpen: false,
|
||||||
alertDialogMessage: ""
|
alertDialogMessage: ""
|
||||||
};
|
};
|
||||||
this.onUpdateStatusChanged = this.onUpdateStatusChanged.bind(this);
|
this.onUpdateStatusChanged = this.onUpdateStatusChanged.bind(this);
|
||||||
}
|
}
|
||||||
|
isCompactWidth() { return this.windowSize.width < 420; }
|
||||||
|
|
||||||
onUpdateStatusChanged(newValue: UpdateStatus) {
|
onUpdateStatusChanged(newValue: UpdateStatus) {
|
||||||
if (!newValue.equals(this.state.updateStatus)) {
|
if (!newValue.equals(this.state.updateStatus)) {
|
||||||
@@ -77,15 +79,22 @@ export default class UpdateDialog extends React.Component<UpdateDialogProps, Upd
|
|||||||
private mounted: boolean = false;
|
private mounted: boolean = false;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
super.componentDidMount();
|
||||||
this.mounted = true;
|
this.mounted = true;
|
||||||
this.model.updateStatus.addOnChangedHandler(this.onUpdateStatusChanged);
|
this.model.updateStatus.addOnChangedHandler(this.onUpdateStatusChanged);
|
||||||
}
|
}
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
super.componentWillUnmount();
|
||||||
this.model.updateStatus.removeOnChangedHandler(this.onUpdateStatusChanged);
|
this.model.updateStatus.removeOnChangedHandler(this.onUpdateStatusChanged);
|
||||||
this.mounted = false;
|
this.mounted = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
onWindowSizeChanged(width: number, height: number): void {
|
||||||
|
super.onWindowSizeChanged(width, height);
|
||||||
|
if (this.isCompactWidth() !== this.state.compactWidth) {
|
||||||
|
this.setState({ compactWidth: this.isCompactWidth() });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private handleOK() {
|
private handleOK() {
|
||||||
this.model.showUpdateDialog(false);
|
this.model.showUpdateDialog(false);
|
||||||
@@ -152,18 +161,15 @@ export default class UpdateDialog extends React.Component<UpdateDialogProps, Upd
|
|||||||
let updateRelease = updateStatus.getActiveRelease();
|
let updateRelease = updateStatus.getActiveRelease();
|
||||||
let upToDate = this.upToDate();
|
let upToDate = this.upToDate();
|
||||||
let canUpgrade = this.canUpgrade();
|
let canUpgrade = this.canUpgrade();
|
||||||
let compact = this.state.compactLandscape;
|
|
||||||
let showUpgradeVersion = !upToDate && updateStatus.isValid && updateRelease.upgradeVersionDisplayName !== "";
|
let showUpgradeVersion = !upToDate && updateStatus.isValid && updateRelease.upgradeVersionDisplayName !== "";
|
||||||
|
let compactWidth = this.state.compactWidth;
|
||||||
return (
|
return (
|
||||||
<DialogEx tag="update" open={this.props.open} onClose={() => { this.handleClose(); }}
|
<DialogEx tag="update" open={this.props.open} onClose={() => { this.handleClose(); }}
|
||||||
style={{ userSelect: "none" }}
|
style={{ userSelect: "none" }}
|
||||||
>
|
>
|
||||||
{
|
|
||||||
(!compact) &&
|
|
||||||
(
|
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
<div style={{ display: "flex", flexFlow: "row noWrap", alignItems: "center" }} >
|
<div style={{ display: "flex", flexFlow: "row noWrap", alignItems: "center" }} >
|
||||||
<Typography style={{ flexGrow: 1, flexShrink: 1, marginRight: 20 }} noWrap>PiPedal Updates</Typography>
|
<Typography style={{ flexGrow: 1, flexShrink: 1, marginRight: 20 }} noWrap>Updates</Typography>
|
||||||
<Select style={{ opacity: 0.6 }} variant="standard" value={updateStatus.updatePolicy} onChange={(ev) => { this.onPolicySelected(ev.target.value); }}>
|
<Select style={{ opacity: 0.6 }} variant="standard" value={updateStatus.updatePolicy} onChange={(ev) => { this.onPolicySelected(ev.target.value); }}>
|
||||||
<MenuItem value={UpdatePolicyT.ReleaseOnly}>Release only</MenuItem>
|
<MenuItem value={UpdatePolicyT.ReleaseOnly}>Release only</MenuItem>
|
||||||
<MenuItem value={UpdatePolicyT.ReleaseOrBeta}>Release or Beta</MenuItem>
|
<MenuItem value={UpdatePolicyT.ReleaseOrBeta}>Release or Beta</MenuItem>
|
||||||
@@ -173,14 +179,7 @@ export default class UpdateDialog extends React.Component<UpdateDialogProps, Upd
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
)
|
|
||||||
}
|
|
||||||
{
|
|
||||||
(!compact) &&
|
|
||||||
(
|
|
||||||
<Divider />
|
<Divider />
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
{(upToDate) && (
|
{(upToDate) && (
|
||||||
@@ -197,7 +196,28 @@ export default class UpdateDialog extends React.Component<UpdateDialogProps, Upd
|
|||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
(compactWidth) ? (
|
||||||
|
<div>
|
||||||
|
<Typography noWrap variant="body2" color="textSecondary" >
|
||||||
|
Current version:
|
||||||
|
</Typography>
|
||||||
|
<Typography noWrap variant="body2" color="textSecondary" style={{ marginLeft: 16 }} >
|
||||||
|
{updateStatus.currentVersionDisplayName}
|
||||||
|
</Typography>
|
||||||
|
{(showUpgradeVersion) && (
|
||||||
|
<div style={{marginTop: 4}}>
|
||||||
|
<Typography noWrap variant="body2" color="textSecondary" >
|
||||||
|
Update version:
|
||||||
|
</Typography>
|
||||||
|
<Typography noWrap variant="body2" color="textSecondary" >
|
||||||
|
{updateRelease.upgradeVersionDisplayName}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<div style={{ display: "flex", flexFlow: "row noWrap" }}>
|
<div style={{ display: "flex", flexFlow: "row noWrap" }}>
|
||||||
<div>
|
<div>
|
||||||
<Typography noWrap variant="body2" color="textSecondary" >
|
<Typography noWrap variant="body2" color="textSecondary" >
|
||||||
@@ -222,6 +242,10 @@ export default class UpdateDialog extends React.Component<UpdateDialogProps, Upd
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
(updateStatus.errorMessage.length !== 0) &&
|
(updateStatus.errorMessage.length !== 0) &&
|
||||||
(
|
(
|
||||||
@@ -233,7 +257,7 @@ export default class UpdateDialog extends React.Component<UpdateDialogProps, Upd
|
|||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
<Button style={{ marginLeft: 16, marginTop: 12 }} onClick={() => { this.onViewReleaseNotes(); }}>View release notes</Button>
|
<Button style={{ marginLeft: 8, marginTop: 12 }} onClick={() => { this.onViewReleaseNotes(); }}>View release notes</Button>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<Divider />
|
<Divider />
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
|||||||
Reference in New Issue
Block a user