This repository was archived by the owner on Jan 6, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathPodmanInstallation.tsx
More file actions
298 lines (281 loc) · 10.2 KB
/
PodmanInstallation.tsx
File metadata and controls
298 lines (281 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import type { FileDownloadProgress } from '../../../main/downloadFile';
// import { reportEvent } from '../../events/reportEvent';
import { CHANNELS } from '../../../main/messenger';
import type { IpcMessage } from '../../../main/podman/messageFrontEnd';
import Button from '../../Generics/redesign/Button/Button';
import { Icon } from '../../Generics/redesign/Icon/Icon';
import ExternalLink from '../../Generics/redesign/Link/ExternalLink';
import { Message } from '../../Generics/redesign/Message/Message';
import ProgressBar from '../../Generics/redesign/ProgressBar/ProgressBar';
import TimedProgressBar from '../../Generics/redesign/ProgressBar/TimedProgressBar';
import electron from '../../electronGlobal';
import {
useGetIsPodmanInstalledQuery,
useGetIsPodmanRunningQuery,
useGetPodmanDetailsQuery,
} from '../../state/settingsService';
import { bytesToMB } from '../../utils';
import { arePodmanRequirementsMet } from '../AddNodeStepper/podmanRequirements';
import {
captionText,
container,
descriptionFont,
installContentContainer,
installationComplete,
installationContainer,
installationIcon,
installationSteps,
learnMore,
titleFont,
} from './podmanInstallation.css';
import { messageContainer } from './podmanInstallation.css.js';
// 6.5(docker), ? min on 2022 MacbookPro 16inch, baseline
const TOTAL_INSTALL_TIME_SEC = 5 * 60;
export interface PodmanInstallationProps {
/**
* Listen to node config changes
*/
onChange: (newValue: string) => void;
disableSaveButton?: (newValue: boolean) => void;
type?: string;
}
const PodmanInstallation = ({
onChange,
disableSaveButton,
type = '',
}: PodmanInstallationProps) => {
const { t } = useTranslation();
const qIsPodmanInstalled = useGetIsPodmanInstalledQuery();
const isPodmanInstalled = qIsPodmanInstalled?.data;
const qIsPodmanRunning = useGetIsPodmanRunningQuery(null, {
pollingInterval: 15000,
});
const isPodmanRunning = qIsPodmanRunning?.data;
const qPodmanDetails = useGetPodmanDetailsQuery(null, {
pollingInterval: 15000,
});
const podmanDetails = qPodmanDetails?.data;
const [sHasStartedDownload, setHasStartedDownload] = useState<boolean>();
const [sDownloadComplete, setDownloadComplete] = useState<boolean>();
const [sDownloadProgress, setDownloadProgress] = useState<number>(0);
const [sTotalSizeBytes, setTotalSizeBytes] = useState<number>(0);
const [sDownloadedBytes, setDownloadedBytes] = useState<number>(0);
const [
sDidUserGrantPermissionToInstallPodman,
setDidUserGrantPermissionToInstallPodman,
] = useState<boolean>();
const [sInstallComplete, setInstallComplete] = useState<boolean>();
useEffect(() => {
// todoo
if (disableSaveButton) disableSaveButton(true);
// if (disableSaveButton) disableSaveButton(false);
}, []);
console.log('isPodmanRunning: ', isPodmanRunning);
useEffect(() => {
// wait until podman is running and not outdated before confirming 'done'
if (arePodmanRequirementsMet(podmanDetails)) {
onChange('done');
}
}, [isPodmanRunning, podmanDetails, onChange]);
const onClickDownloadAndInstall = async () => {
setHasStartedDownload(true);
if (navigator.userAgent.indexOf('Linux') !== -1) {
setDownloadComplete(true);
}
const installResult = await electron.installPodman();
qIsPodmanInstalled.refetch();
qIsPodmanRunning.refetch();
if (installResult && !installResult.error) {
setInstallComplete(true);
// reportEvent('InstalledPodman');
// notify parent that everything is done
// todo: confirm/check podman version installed?
}
console.log('installPodman finished. Install result: ', installResult);
};
const onClickStartPodman = async () => {
setHasStartedDownload(true);
const startResult = await electron.startPodman();
qIsPodmanRunning.refetch();
console.log('startPodman finished. Start result: ', startResult);
};
const onClickUpdatePodman = async () => {
setHasStartedDownload(true);
if (navigator.userAgent.indexOf('Linux') !== -1) {
setDownloadComplete(true);
}
const updateResult = await electron.updatePodman();
// todo: consolodate these to just use qPodmanDetails
qIsPodmanInstalled.refetch();
qIsPodmanRunning.refetch();
qPodmanDetails.refetch();
if (updateResult && !updateResult.error) {
setInstallComplete(true);
}
console.log('updatePodman finished. Start result: ', updateResult);
};
const podmanMessageListener = (message: FileDownloadProgress[]) => {
// set totalSize & progress
if (message[0]) {
console.log('downloadupdate: ', message[0]);
setTotalSizeBytes(message[0].totalBytes);
setDownloadedBytes(message[0].downloadedBytes);
setDownloadProgress(
(message[0].downloadedBytes / message[0].totalBytes) * 100,
);
// if downloaded = total, then complete?
if (message[0].downloadedBytes === message[0].totalBytes) {
console.log('downloaded = total bytes. download complete');
setDownloadComplete(true);
}
} else {
console.error('received empty podman message');
}
};
const podmanInstallMessageListener = useCallback(
(messageArray: [IpcMessage]) => {
// set totalSize & progress
const message = messageArray[0];
console.log('podmanInstallMessageListener message: ', message);
if (message.messageId === 'isGrantPermission') {
console.log('message: ', message);
// if false, notify user that podman is required and allow them another try
// to grant permissions
setDidUserGrantPermissionToInstallPodman(message?.value as boolean);
} else {
// ignore for now?
}
},
[],
);
useEffect(() => {
// if granted, start install & countdown
// if not granted, show warning
}, [sDidUserGrantPermissionToInstallPodman]);
useEffect(() => {
console.log('PodmanInstallation.tsx: listenForPodmanInstallUpdates .');
electron.ipcRenderer.on(CHANNELS.podman, podmanMessageListener);
electron.ipcRenderer.on(
CHANNELS.podmanInstall,
podmanInstallMessageListener,
);
return () => {
electron.ipcRenderer.removeAllListeners(CHANNELS.podman);
electron.ipcRenderer.removeListener(
CHANNELS.podmanInstall,
podmanInstallMessageListener,
);
};
}, [podmanInstallMessageListener]);
// useEffect(() => {
// return () => {
// qIsPodmanRunning.unsubscribe();
// };
// react-hooks/exhaustive-deps
// }, []);
// listen to podman install messages
return (
<div className={[container, type].join(' ')}>
{type !== 'modal' && (
<div id="podmanInstallationTitle" className={titleFont}>
{t('PodmanInstallation')}
</div>
)}
{podmanDetails?.isOutdated && (
<div className={messageContainer}>
<Message
description={t('CurrentPodman', {
currentPodmanVersion: podmanDetails?.installedVersion,
requiredPodmanVersion: podmanDetails?.minimumVersionRequired,
})}
title={t('RunningOutdatedPodman')}
type="warning"
/>
</div>
)}
<div className={descriptionFont}>{t('podmanPurpose')}</div>
<div className={learnMore}>
<ExternalLink text={t('LearnMorePodman')} url="https://podman.io/" />
</div>
{/* Podman is not installed */}
<div className={installContentContainer}>
{(!isPodmanInstalled || podmanDetails?.isOutdated) && (
<>
{!sDownloadComplete && !sInstallComplete && (
// biome-ignore lint: unecessaryFragment
<>
{!sHasStartedDownload ? (
<div>
<Button
id="downloadAndInstallPodmanBtn"
type="primary"
label={
podmanDetails?.isOutdated
? t('DownloadAndUpdate')
: t('DownloadAndInstall')
}
onClick={() => {
if (isPodmanInstalled && podmanDetails?.isOutdated) {
onClickUpdatePodman();
} else {
onClickDownloadAndInstall();
}
}}
/>
<div className={captionText}>~100MB {t('download')}</div>
</div>
) : (
<ProgressBar
progress={sDownloadProgress}
title={t('DownloadingPodman')}
caption={t('DownloadedSomeMegaBytesOfTotal', {
downloadedBytes: bytesToMB(sDownloadedBytes),
totalBytes: bytesToMB(sTotalSizeBytes),
})}
/>
)}
</>
)}
{sDownloadComplete && !sInstallComplete && (
<TimedProgressBar
totalTimeSeconds={TOTAL_INSTALL_TIME_SEC}
title={t('InstallingPodman')}
/>
)}
</>
)}
{sDownloadComplete && sInstallComplete && (
<div className={installationContainer}>
<div className={installationIcon}>
<Icon iconId="checkcirclefilled" />
</div>
<div className={installationComplete}>
{t('PodmanInstallComplete')}
</div>
<div className={installationSteps}>
{t('PodmanIsInstalled')}{' '}
{!isPodmanRunning ? t('StartPodman') : t('StartNode')}
</div>
</div>
)}
{/* Podman is installed but not running */}
{isPodmanInstalled &&
!isPodmanRunning &&
!podmanDetails?.isOutdated && (
<Button
id="startPodmanBtn"
type="primary"
label={t('StartPodman')}
onClick={onClickStartPodman}
/>
)}
{sDidUserGrantPermissionToInstallPodman === false && (
<p>{t('PodmanIsRequired')}</p>
)}
</div>
</div>
);
};
export default PodmanInstallation;