Skip to content

Commit 81c08f0

Browse files
committed
feature: add update modal and not show system prompt
1 parent dbeb4c1 commit 81c08f0

8 files changed

Lines changed: 131 additions & 16 deletions

File tree

app/components/common/Version.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import { getNetworkInfo } from '../../redux/network/selectors';
2121
import { checkUpdates as checkUpdatesIco } from '../../assets/images';
2222
import { AppThDispatch } from '../../types';
2323
import updaterSlice from '../../redux/updater/slice';
24+
import { SECOND } from '../../../shared/constants';
25+
import { Loader } from '../../basicComponents';
26+
import UpdateApplicationWarningModal from '../../screens/modal/UpdateApplicationWarningModal';
2427
import FeedbackButton from './Feedback';
2528

2629
const Container = styled.div`
@@ -194,6 +197,29 @@ const UpdateStatus = () => {
194197
const isDownloading = useSelector(isUpdateDownloading);
195198
const isDownloaded = useSelector(isUpdateDownloaded);
196199
const error = useSelector(getError);
200+
const [
201+
isOpenUpdateApplicationWarningModal,
202+
setIsOpenUpdateApplicationWarningModal,
203+
] = useState(false);
204+
const [
205+
showUpdateApplicationLoader,
206+
setShowUpdateApplicationLoader,
207+
] = useState(false);
208+
209+
const handleRestartNow = () => {
210+
setIsOpenUpdateApplicationWarningModal(false);
211+
setShowUpdateApplicationLoader(true);
212+
eventsService.installUpdate();
213+
214+
setTimeout(() => {
215+
setShowUpdateApplicationLoader(false);
216+
}, 10 * SECOND);
217+
};
218+
219+
const handlePostpone = () => {
220+
setIsOpenUpdateApplicationWarningModal(false);
221+
};
222+
197223
if (!isDownloading && !isDownloaded) return null;
198224

199225
if (progress !== null && !isDownloaded) {
@@ -207,9 +233,19 @@ const UpdateStatus = () => {
207233
return (
208234
<>
209235
<ProgressChunk>Update is ready to install</ProgressChunk>
210-
<PrimaryAction onClick={() => eventsService.installUpdate()}>
236+
<PrimaryAction
237+
onClick={() => setIsOpenUpdateApplicationWarningModal(true)}
238+
>
211239
Restart Smapp
212240
</PrimaryAction>
241+
<UpdateApplicationWarningModal
242+
isOpen={isOpenUpdateApplicationWarningModal}
243+
onApprove={handleRestartNow}
244+
onCancel={handlePostpone}
245+
/>
246+
{showUpdateApplicationLoader && (
247+
<Loader size={Loader.sizes.BIG} note="UPDATE IN PROGESS..." />
248+
)}
213249
</>
214250
);
215251
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
import Modal from '../../components/common/Modal';
4+
import { Button } from '../../basicComponents';
5+
import { smColors } from '../../vars';
6+
7+
const ButtonsWrapper = styled.div`
8+
display: flex;
9+
flex-direction: row;
10+
justify-content: space-between;
11+
margin: auto 0 15px 0;
12+
padding-top: 30px;
13+
`;
14+
15+
const Message = styled.pre`
16+
font-size: 14px;
17+
line-height: 1.33em;
18+
word-wrap: break-word;
19+
white-space: pre-wrap;
20+
overflow-y: auto;
21+
margin-top: 15px;
22+
23+
ul {
24+
list-style: none;
25+
margin-left: 10px;
26+
}
27+
li {
28+
margin: 10px 0;
29+
}
30+
li:before {
31+
content: '• ';
32+
padding: 5px;
33+
}
34+
`;
35+
36+
const UpdateApplicationWarningModal = ({ isOpen, onApprove, onCancel }) => {
37+
if (!isOpen) return null;
38+
39+
return (
40+
<Modal header="Update SMAPP" height={380}>
41+
<Message>
42+
<p>
43+
Restarting now is <b>CRITICAL</b> and may impact your node’s
44+
performance and rewards.
45+
</p>
46+
<ul>
47+
<li>
48+
Click <b style={{ color: smColors.green }}>RESTART NOW</b> to apply
49+
the update immediately. Delaying the update could result in
50+
potential loss of rewards.
51+
</li>
52+
<li>
53+
Click <b style={{ color: smColors.purple }}>POSTPONE</b> to delay
54+
the update. Be aware that postponing may slow down your node’s
55+
performance and future rewards.
56+
</li>
57+
</ul>
58+
</Message>
59+
<ButtonsWrapper>
60+
<Button onClick={onCancel} isPrimary={false} text="POSTPONE" />
61+
<Button onClick={onApprove} text="RESTART NOW" />
62+
</ButtonsWrapper>
63+
</Modal>
64+
);
65+
};
66+
67+
export default UpdateApplicationWarningModal;

desktop/main/createMainWindow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { app, BrowserWindow, ipcMain } from 'electron';
2-
import { autoUpdater } from 'electron-updater';
1+
import { app, BrowserWindow, ipcMain, autoUpdater } from 'electron';
32
import {
43
BehaviorSubject,
54
combineLatest,
@@ -35,6 +34,7 @@ export default () => {
3534
const $quit = new Subject<Electron.IpcMainEvent>();
3635
const $activate = fromAppEvent('activate');
3736
const $secondInstance = fromAppEvent('second-instance');
37+
const $isUpdateInProgress = new BehaviorSubject<boolean>(false);
3838

3939
//
4040
// Subscriptions & Reactions
@@ -84,5 +84,6 @@ export default () => {
8484
$showWindowOnLoad,
8585
$isWindowReady,
8686
$isSmappActivated: $activate,
87+
$isUpdateInProgress,
8788
};
8889
};

desktop/main/promptBeforeClose.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const promptBeforeClose = (
1919
mainWindow: BrowserWindow,
2020
managers: Partial<Managers>,
2121
$isAppClosing: BehaviorSubject<boolean>,
22-
$showWindowOnLoad: Subject<boolean>
22+
$showWindowOnLoad: Subject<boolean>,
23+
$isUpdateInProgress: BehaviorSubject<boolean>
2324
) => {
2425
const showPrompt = async () => {
2526
if (!mainWindow) return CloseAppPromptResult.KEEP_SMESHING;
@@ -64,8 +65,10 @@ const promptBeforeClose = (
6465
};
6566

6667
const handleClosingApp = async (event: Electron.Event) => {
67-
event.preventDefault();
68-
if (!mainWindow) {
68+
// in case of autoUpdater before-quit-for-update event, the event may be undefined
69+
event?.preventDefault();
70+
// if user requested update or no mainWindow, do not show the prompt
71+
if ($isUpdateInProgress.value || !mainWindow) {
6972
await quit();
7073
return;
7174
}

desktop/main/reactions/handleCloseApp.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export default (
1212
$managers: Subject<Managers>,
1313
$mainWindow: Subject<BrowserWindow>,
1414
$isAppClosing: BehaviorSubject<boolean>,
15-
$showWindowOnLoad: Subject<boolean>
15+
$showWindowOnLoad: Subject<boolean>,
16+
$isUpdateInProgress: BehaviorSubject<boolean>
1617
) =>
1718
makeSubscription(
1819
$quit.pipe(withLatestFrom($mainWindow, $managers)),
@@ -22,6 +23,7 @@ export default (
2223
mw,
2324
managers || {},
2425
$isAppClosing,
25-
$showWindowOnLoad
26+
$showWindowOnLoad,
27+
$isUpdateInProgress
2628
)(event).catch((err) => logger.error('promptBeforeClose', err))
2729
);

desktop/main/sources/autoUpdate.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BrowserWindow } from 'electron';
22
import { UpdateInfo } from 'electron-updater';
33
import {
4+
BehaviorSubject,
45
combineLatest,
56
filter,
67
first,
@@ -40,7 +41,8 @@ const handleAutoUpdates = (
4041
everyMs: number,
4142
$mainWindow: Observable<BrowserWindow>,
4243
$managers: Observable<Managers>,
43-
$currentNetwork: Observable<Network | null>
44+
$currentNetwork: Observable<Network | null>,
45+
$isUpdateInProgress: BehaviorSubject<boolean>
4446
) => {
4547
type DoDownload = boolean;
4648
type Data = [BrowserWindow, Network, DoDownload];
@@ -136,9 +138,10 @@ const handleAutoUpdates = (
136138
$request.next(true);
137139
}),
138140
// Trigger installation
139-
fromIPC<void>(ipcConsts.AU_REQUEST_INSTALL).subscribe(() =>
140-
installUpdate()
141-
),
141+
fromIPC<void>(ipcConsts.AU_REQUEST_INSTALL).subscribe(() => {
142+
$isUpdateInProgress.next(true);
143+
return installUpdate();
144+
}),
142145
];
143146

144147
return () => subs.forEach((sub) => sub.unsubscribe());

desktop/main/startApp.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ const startApp = (): AppStore => {
133133
$isAppClosing,
134134
$showWindowOnLoad,
135135
$isWindowReady,
136+
$isUpdateInProgress,
136137
} = createMainWindow();
137138
// Store
138139
const $storeService = observeStoreService();
@@ -218,7 +219,8 @@ const startApp = (): AppStore => {
218219
$managers,
219220
$mainWindow,
220221
$isAppClosing,
221-
$showWindowOnLoad
222+
$showWindowOnLoad,
223+
$isUpdateInProgress
222224
),
223225
// Unlock / Create wallet
224226
// Switch network
@@ -264,7 +266,8 @@ const startApp = (): AppStore => {
264266
CHECK_UPDATES_INTERVAL,
265267
$mainWindow,
266268
$managers,
267-
$currentNetwork
269+
$currentNetwork,
270+
$isUpdateInProgress
268271
),
269272
handleOpenDashboard($mainWindow, $currentNetwork),
270273
sendWarningsToRenderer($warnings, $mainWindow, $isWindowReady),

shared/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export enum ExternalLinks {
4747
}
4848

4949
export const BITS_PER_LABEL = 128;
50-
51-
export const MINUTE = 60 * 1000;
50+
export const SECOND = 1000;
51+
export const MINUTE = 60 * SECOND;
5252

5353
export const HOUR = MINUTE * 60;
5454

0 commit comments

Comments
 (0)