Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Don't ask user to run in background on restart after clicking upgrade #1596

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions app/components/common/Version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import { getNetworkInfo } from '../../redux/network/selectors';
import { checkUpdates as checkUpdatesIco } from '../../assets/images';
import { AppThDispatch } from '../../types';
import updaterSlice from '../../redux/updater/slice';
import { SECOND } from '../../../shared/constants';
import { Loader } from '../../basicComponents';
import UpdateApplicationWarningModal from '../../screens/modal/UpdateApplicationWarningModal';
import * as SmesherSelectors from '../../redux/smesher/selectors';
import FeedbackButton from './Feedback';

const Container = styled.div`
Expand Down Expand Up @@ -194,6 +198,38 @@ const UpdateStatus = () => {
const isDownloading = useSelector(isUpdateDownloading);
const isDownloaded = useSelector(isUpdateDownloaded);
const error = useSelector(getError);
const isSmeshing = useSelector(SmesherSelectors.isSmeshing);
const [
isOpenUpdateApplicationWarningModal,
setIsOpenUpdateApplicationWarningModal,
] = useState(false);
const [
showUpdateApplicationLoader,
setShowUpdateApplicationLoader,
] = useState(false);

const handleRestartNow = () => {
setIsOpenUpdateApplicationWarningModal(false);
setShowUpdateApplicationLoader(true);
eventsService.installUpdate();

setTimeout(() => {
setShowUpdateApplicationLoader(false);
}, 10 * SECOND);
};

const handleRestart = () => {
if (isSmeshing) {
setIsOpenUpdateApplicationWarningModal(true);
} else {
handleRestartNow();
}
};

const handlePostpone = () => {
setIsOpenUpdateApplicationWarningModal(false);
};

if (!isDownloading && !isDownloaded) return null;

if (progress !== null && !isDownloaded) {
Expand All @@ -207,9 +243,15 @@ const UpdateStatus = () => {
return (
<>
<ProgressChunk>Update is ready to install</ProgressChunk>
<PrimaryAction onClick={() => eventsService.installUpdate()}>
Restart Smapp
</PrimaryAction>
<PrimaryAction onClick={handleRestart}>Restart Smapp</PrimaryAction>
<UpdateApplicationWarningModal
isOpen={isOpenUpdateApplicationWarningModal}
onApprove={handleRestartNow}
onCancel={handlePostpone}
/>
{showUpdateApplicationLoader && (
<Loader size={Loader.sizes.BIG} note="UPDATE IN PROGESS..." />
)}
</>
);
}
Expand Down
67 changes: 67 additions & 0 deletions app/screens/modal/UpdateApplicationWarningModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import styled from 'styled-components';
import Modal from '../../components/common/Modal';
import { Button } from '../../basicComponents';
import { smColors } from '../../vars';

const ButtonsWrapper = styled.div`
display: flex;
flex-direction: row;
justify-content: space-between;
margin: auto 0 15px 0;
padding-top: 30px;
`;

const Message = styled.pre`
font-size: 14px;
line-height: 1.33em;
word-wrap: break-word;
white-space: pre-wrap;
overflow-y: auto;
margin-top: 15px;

ul {
list-style: none;
margin-left: 10px;
}
li {
margin: 10px 0;
}
li:before {
content: '• ';
padding: 5px;
}
`;

const UpdateApplicationWarningModal = ({ isOpen, onApprove, onCancel }) => {
if (!isOpen) return null;

return (
<Modal header="Update SMAPP" height={380}>
<Message>
<p>
To finalize the update, Smapp must be restarted. However, verify your
eligibility for upcoming layer rewards. Powering off the node risks
missing proposal submissions and losing the rewards.
</p>
<ul>
<li>
Click <b style={{ color: smColors.green }}>RESTART NOW</b> to apply
the update immediately.
</li>
<li>
Click <b style={{ color: smColors.purple }}>POSTPONE</b> to delay
the update. The persistent &quot;restart Smapp&quot; button will
remind you about the pending update.
</li>
</ul>
</Message>
<ButtonsWrapper>
<Button onClick={onCancel} isPrimary={false} text="POSTPONE" />
<Button onClick={onApprove} text="RESTART NOW" />
</ButtonsWrapper>
</Modal>
);
};

export default UpdateApplicationWarningModal;
5 changes: 3 additions & 2 deletions desktop/main/createMainWindow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { app, BrowserWindow, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import { app, BrowserWindow, ipcMain, autoUpdater } from 'electron';
import {
BehaviorSubject,
combineLatest,
Expand Down Expand Up @@ -35,6 +34,7 @@ export default () => {
const $quit = new Subject<Electron.IpcMainEvent>();
const $activate = fromAppEvent('activate');
const $secondInstance = fromAppEvent('second-instance');
const $isUpdateInProgress = new BehaviorSubject<boolean>(false);

//
// Subscriptions & Reactions
Expand Down Expand Up @@ -84,5 +84,6 @@ export default () => {
$showWindowOnLoad,
$isWindowReady,
$isSmappActivated: $activate,
$isUpdateInProgress,
};
};
9 changes: 6 additions & 3 deletions desktop/main/promptBeforeClose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const promptBeforeClose = (
mainWindow: BrowserWindow,
managers: Partial<Managers>,
$isAppClosing: BehaviorSubject<boolean>,
$showWindowOnLoad: Subject<boolean>
$showWindowOnLoad: Subject<boolean>,
$isUpdateInProgress: BehaviorSubject<boolean>
) => {
const showPrompt = async () => {
if (!mainWindow) return CloseAppPromptResult.KEEP_SMESHING;
Expand Down Expand Up @@ -64,8 +65,10 @@ const promptBeforeClose = (
};

const handleClosingApp = async (event: Electron.Event) => {
event.preventDefault();
if (!mainWindow) {
// in case of autoUpdater before-quit-for-update event, the event may be undefined
event?.preventDefault();
// if user requested update or no mainWindow, do not show the prompt
if ($isUpdateInProgress.value || !mainWindow) {
await quit();
return;
}
Expand Down
6 changes: 4 additions & 2 deletions desktop/main/reactions/handleCloseApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default (
$managers: Subject<Managers>,
$mainWindow: Subject<BrowserWindow>,
$isAppClosing: BehaviorSubject<boolean>,
$showWindowOnLoad: Subject<boolean>
$showWindowOnLoad: Subject<boolean>,
$isUpdateInProgress: BehaviorSubject<boolean>
) =>
makeSubscription(
$quit.pipe(withLatestFrom($mainWindow, $managers)),
Expand All @@ -22,6 +23,7 @@ export default (
mw,
managers || {},
$isAppClosing,
$showWindowOnLoad
$showWindowOnLoad,
$isUpdateInProgress
)(event).catch((err) => logger.error('promptBeforeClose', err))
);
11 changes: 7 additions & 4 deletions desktop/main/sources/autoUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BrowserWindow } from 'electron';
import { UpdateInfo } from 'electron-updater';
import {
BehaviorSubject,
combineLatest,
filter,
first,
Expand Down Expand Up @@ -40,7 +41,8 @@ const handleAutoUpdates = (
everyMs: number,
$mainWindow: Observable<BrowserWindow>,
$managers: Observable<Managers>,
$currentNetwork: Observable<Network | null>
$currentNetwork: Observable<Network | null>,
$isUpdateInProgress: BehaviorSubject<boolean>
) => {
type DoDownload = boolean;
type Data = [BrowserWindow, Network, DoDownload];
Expand Down Expand Up @@ -136,9 +138,10 @@ const handleAutoUpdates = (
$request.next(true);
}),
// Trigger installation
fromIPC<void>(ipcConsts.AU_REQUEST_INSTALL).subscribe(() =>
installUpdate()
),
fromIPC<void>(ipcConsts.AU_REQUEST_INSTALL).subscribe(() => {
$isUpdateInProgress.next(true);
return installUpdate();
}),
];

return () => subs.forEach((sub) => sub.unsubscribe());
Expand Down
7 changes: 5 additions & 2 deletions desktop/main/startApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const startApp = (): AppStore => {
$isAppClosing,
$showWindowOnLoad,
$isWindowReady,
$isUpdateInProgress,
} = createMainWindow();
// Store
const $storeService = observeStoreService();
Expand Down Expand Up @@ -218,7 +219,8 @@ const startApp = (): AppStore => {
$managers,
$mainWindow,
$isAppClosing,
$showWindowOnLoad
$showWindowOnLoad,
$isUpdateInProgress
),
// Unlock / Create wallet
// Switch network
Expand Down Expand Up @@ -264,7 +266,8 @@ const startApp = (): AppStore => {
CHECK_UPDATES_INTERVAL,
$mainWindow,
$managers,
$currentNetwork
$currentNetwork,
$isUpdateInProgress
),
handleOpenDashboard($mainWindow, $currentNetwork),
sendWarningsToRenderer($warnings, $mainWindow, $isWindowReady),
Expand Down
4 changes: 2 additions & 2 deletions shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export enum ExternalLinks {
}

export const BITS_PER_LABEL = 128;

export const MINUTE = 60 * 1000;
export const SECOND = 1000;
export const MINUTE = 60 * SECOND;

export const HOUR = MINUTE * 60;

Expand Down
Loading