Skip to content

Commit 4bc392b

Browse files
fix: implement PR review feedback for offline downloader and dynamic port
1 parent 5ca65d6 commit 4bc392b

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

desktop-app/neutralino.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"applicationId": "com.markdownviewer.desktop",
44
"version": "1.0.0",
55
"defaultMode": "window",
6-
"port": 28915,
6+
"port": 0,
77
"documentRoot": "/resources/",
88
"url": "/",
99
"enableServer": true,

desktop-app/prepare.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,18 @@ function downloadFile(url, destPath, expectedSha384) {
9393

9494
function downloadAndVerify() {
9595
console.log(`Downloading offline dependency: ${path.basename(destPath)}...`);
96-
https.get(url, (res) => {
96+
const req = https.get(url, (res) => {
9797
if (res.statusCode !== 200) {
98+
res.resume(); // Drain response to free up the socket
9899
reject(new Error(`Failed to load ${url} (${res.statusCode})`));
99100
return;
100101
}
101102
const stream = fs.createWriteStream(destPath);
103+
104+
// Handle stream and response errors
105+
stream.on("error", reject);
106+
res.on("error", reject);
107+
102108
res.pipe(stream);
103109
stream.on("finish", () => {
104110
stream.close();
@@ -114,7 +120,8 @@ function downloadFile(url, destPath, expectedSha384) {
114120
reject(err);
115121
});
116122
});
117-
}).on("error", reject);
123+
});
124+
req.on("error", reject);
118125
}
119126
});
120127
}
@@ -143,6 +150,7 @@ async function prepareOfflineDependencies() {
143150

144151
if (!expectedSha384) {
145152
console.warn(`⚠ Warning: CDN dependency is missing an integrity hash: ${url}`);
153+
throw new Error(`CDN dependency is missing an integrity hash: ${url}`);
146154
}
147155

148156
// Determine local filename - sanitize package version tags or query strings

0 commit comments

Comments
 (0)