Skip to content

Commit 9d84085

Browse files
authored
Add delete confirmation and and restore option to canceled downloads (#1531)
* Close file handlers after usage Fixing deprected warnings in stdout * Add delete confirmation and and restore option to canceled downloads
1 parent 7fd15c7 commit 9d84085

File tree

7 files changed

+58
-23
lines changed

7 files changed

+58
-23
lines changed

scripts/createDeploy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const createDeployFiles = async () => {
7777
if (err) {
7878
reject();
7979
}
80+
destination.close();
8081
resolve();
8182
});
8283
});

src/app/desktop/utils/downloader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ const downloadFileInstance = async (fileName, url, sha1, legacyPath) => {
103103

104104
data.on('end', () => {
105105
wStream.end();
106+
wStream.close();
106107
if (legacyPath) {
107108
wStreamLegacy.end();
109+
wStreamLegacy.close();
108110
}
109111
resolve();
110112
});
@@ -148,6 +150,7 @@ export const downloadFile = async (fileName, url, onProgress) => {
148150
return new Promise((resolve, reject) => {
149151
data.on('end', () => {
150152
out.end();
153+
out.close();
151154
resolve();
152155
});
153156

src/common/modals/InstanceDeleteConfirmation.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ const InstanceDeleteConfirmation = ({ instanceName }) => {
6767
>
6868
No, Abort
6969
</Button>
70-
<Button onClick={deleteInstance} loading={loading}>
70+
<Button
71+
danger
72+
type="primary"
73+
onClick={deleteInstance}
74+
loading={loading}
75+
>
7176
Yes, Delete
7277
</Button>
7378
</div>

src/common/modals/InstanceDownloadFailed.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
removeDownloadFromQueue,
99
updateInstanceConfig
1010
} from '../reducers/actions';
11-
import { closeModal } from '../reducers/modals/actions';
11+
import { openModal, closeModal } from '../reducers/modals/actions';
1212
import { _getInstancesPath, _getTempPath } from '../utils/selectors';
1313
import { rollBackInstanceZip } from '../utils';
1414

@@ -28,7 +28,15 @@ const InstanceDownloadFailed = ({
2828
? `${instanceName.substring(0, 20)}...`
2929
: instanceName;
3030

31-
const cancelDownload = async () => {
31+
const deleteDownload = async () => {
32+
await dispatch(removeDownloadFromQueue(instanceName, true));
33+
34+
dispatch(closeModal());
35+
await new Promise(resolve => setTimeout(resolve, 1000));
36+
dispatch(openModal('InstanceDeleteConfirmation', { instanceName }));
37+
};
38+
39+
const restoreDownload = async () => {
3240
await dispatch(removeDownloadFromQueue(instanceName, true));
3341
setLoading(true);
3442
await new Promise(resolve => setTimeout(resolve, 1000));
@@ -87,11 +95,21 @@ const InstanceDownloadFailed = ({
8795
<Button
8896
variant="contained"
8997
color="primary"
90-
onClick={cancelDownload}
91-
loading={loading}
98+
onClick={deleteDownload}
99+
disabled={loading}
92100
>
93-
Cancel Download
101+
Delete Instance
94102
</Button>
103+
{isUpdate && (
104+
<Button
105+
variant="contained"
106+
color="primary"
107+
onClick={restoreDownload}
108+
loading={loading}
109+
>
110+
Restore instance
111+
</Button>
112+
)}
95113
<Button danger type="primary" onClick={retry} disabled={loading}>
96114
Retry Download
97115
</Button>

src/common/modals/OptedOutModsList.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,19 @@ const OptedOutModsList = ({
202202
title="Opted out mods list"
203203
>
204204
<Container>
205-
<div
206-
css={`
207-
text-align: left;
208-
margin-bottom: 2rem;
209-
`}
210-
>
211-
Hey oh! It looks like some developers opted out from showing their
212-
mods on third-party launchers. We can still attempt to download them
213-
automatically. Please click continue and wait for all downloads to
214-
finish. Please don&apos;t click anything inside the browser.
215-
</div>
205+
{!cloudflareBlock && (
206+
<div
207+
css={`
208+
text-align: left;
209+
margin-bottom: 2rem;
210+
`}
211+
>
212+
Hey oh! It looks like some developers opted out from showing their
213+
mods on third-party launchers. We can still attempt to download them
214+
automatically. Please click continue and wait for all downloads to
215+
finish. Please don&apos;t click anything inside the browser.
216+
</div>
217+
)}
216218
<ModsContainer>
217219
{optedOutMods &&
218220
optedOutMods.map(mod => {
@@ -231,7 +233,6 @@ const OptedOutModsList = ({
231233
{cloudflareBlock && (
232234
<p
233235
css={`
234-
width: 90%;
235236
margin: 20px auto 0 auto;
236237
`}
237238
>
@@ -254,7 +255,9 @@ const OptedOutModsList = ({
254255
<Button
255256
danger
256257
type="text"
257-
disabled={downloading || loadedMods.length !== 0}
258+
disabled={
259+
(missingMods.length > 0 && !cloudflareBlock) || downloading
260+
}
258261
onClick={() => {
259262
dispatch(closeModal());
260263
setTimeout(
@@ -290,6 +293,7 @@ const OptedOutModsList = ({
290293
mods: optedOutMods,
291294
instancePath
292295
});
296+
setDownloading(false);
293297
}}
294298
css={`
295299
background-color: ${props => props.theme.palette.colors.green};

src/common/reducers/actions.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ export function updateInstanceConfig(
10681068
if (readBuff.every(v => v === 0)) {
10691069
throw new Error('Corrupted file');
10701070
}
1071+
newFile.close();
10711072
await fs.rename(tempP, p);
10721073
};
10731074

@@ -2232,6 +2233,7 @@ export function downloadInstance(instanceName) {
22322233

22332234
await dispatch(removeDownloadFromQueue(instanceName));
22342235
dispatch(addNextInstanceToCurrentDownload());
2236+
await remove(tempInstancePath);
22352237
} catch (err) {
22362238
console.error(err);
22372239
// Show error modal and decide what to do
@@ -2243,8 +2245,6 @@ export function downloadInstance(instanceName) {
22432245
isUpdate
22442246
})
22452247
);
2246-
} finally {
2247-
await remove(tempInstancePath);
22482248
}
22492249
};
22502250
}
@@ -2704,12 +2704,15 @@ export const startListener = () => {
27042704
!changesTracker[completePath].completed &&
27052705
(event.action === 2 || event.action === 0 || event.action === 1)
27062706
) {
2707+
let filehandle;
27072708
try {
27082709
await new Promise(resolve => setTimeout(resolve, 300));
2709-
await fs.open(completePath, 'r+');
2710+
filehandle = await fs.open(completePath, 'r+');
27102711
changesTracker[completePath].completed = true;
27112712
} catch {
27122713
// Do nothing, simply not completed..
2714+
} finally {
2715+
await filehandle?.close();
27132716
}
27142717
}
27152718
})
@@ -3762,6 +3765,7 @@ export const checkForPortableUpdates = () => {
37623765
if (err) {
37633766
reject(err);
37643767
}
3768+
destination.close();
37653769
resolve();
37663770
});
37673771
});

src/common/utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export const makeInstanceRestorePoint = async (
232232
await access(newInstancePath);
233233
await remove(newInstancePath);
234234
} catch (e) {
235-
console.warn(e);
235+
console.log('Expected ENOENT:', e);
236236
}
237237
await makeDir(newInstancePath);
238238
try {

0 commit comments

Comments
 (0)