Skip to content

Commit 8aa7403

Browse files
author
Giel Cobben
committed
More feedback when downloading updates
1 parent da1267d commit 8aa7403

File tree

3 files changed

+154
-123
lines changed

3 files changed

+154
-123
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ main.js
3939
main.js.map
4040
config.json
4141
*.dmg
42+
*.zip

app/containers/Home.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ export default class Home extends Component {
7676

7777
showNothingFoundDialog() {
7878
const dialog = remote.dialog;
79+
const selectedLanguage = this.state.lang;
7980
const options = {
8081
type: "question",
8182
buttons: ["OK", "Cancel"],
8283
message: "No results found, try English?",
8384
checkboxLabel: "Do not show this message again.",
84-
detail: `Sorry, we didn’t find any [${this.state.lang}] subtitles matching your file. Would you like to try searching for English subtitles?`
85+
detail: `Sorry, we didn’t find any [${selectedLanguage.toUpperCase()}] subtitles matching your file. Would you like to try searching for English subtitles?`
8586
};
8687

8788
dialog.showMessageBox(options, this.dialogCallback);

main.development.js

Lines changed: 151 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,22 @@ app.on("window-all-closed", () => {
3535
* autoUpdater
3636
*/
3737
let firstRun = true;
38+
let downloading = false;
3839
const platform = os.platform() + "_" + os.arch(); // darwin_x64
3940
const updateURL = `https://download.getcaption.co/update/${platform}/${pkg.version}`;
4041

4142
autoUpdater.on("checking-for-update", () => {
4243
console.log("Checking for updates...");
44+
if (downloading) {
45+
const options = {
46+
type: "info",
47+
buttons: ["OK"],
48+
title: "Caption",
49+
message: `Downloading...`,
50+
detail: `Please leave the app open, the new version of Caption is downloading. You'll receive a new dialog when downloading is finished.`
51+
};
52+
dialog.showMessageBox(options);
53+
}
4354
});
4455

4556
autoUpdater.on("update-not-available", () => {
@@ -54,6 +65,7 @@ autoUpdater.on("update-not-available", () => {
5465
dialog.showMessageBox(options);
5566
}
5667
firstRun = false;
68+
downloading = false;
5769
console.log(`You've got the latest version.`);
5870
});
5971

@@ -75,21 +87,21 @@ autoUpdater.on(
7587

7688
quitAndUpdate();
7789
firstRun = false;
90+
downloading = false;
7891
}
7992
);
8093

8194
autoUpdater.on("error", error => {
8295
console.log(error);
8396
firstRun = false;
97+
downloading = false;
8498
});
8599

86100
autoUpdater.on("update-available", () => {
87101
console.log("update available");
88102
firstRun = false;
89-
90-
// setInterval(() => {
91-
// console.log(autoUpdater.status);
92-
// }, 5000);
103+
downloading = true;
104+
buildMenu();
93105
});
94106

95107
try {
@@ -173,121 +185,23 @@ const createMainWindow = () => {
173185
});
174186
};
175187

176-
app.on("ready", async () => {
177-
if (process.env.NODE_ENV !== "development") {
178-
/*
179-
* Let's Move
180-
*/
188+
const buildMenu = () => {
189+
let menuItemUpdater;
181190

182-
Storage.has("moveApp", async (error, value) => {
183-
if (!value) {
184-
try {
185-
const moved = await moveToApplications();
186-
if (!moved) {
187-
Storage.set("moveApp", false);
188-
}
189-
} catch (error) {
190-
console.log(error);
191-
}
192-
} else {
193-
Storage.get("moveApp", async (error, value) => {
194-
if (value) {
195-
try {
196-
const moved = await moveToApplications();
197-
} catch (error) {
198-
console.log(error);
199-
}
200-
} else {
201-
console.log("user choosed to not move the app!");
202-
}
203-
});
191+
if (downloading) {
192+
menuItemUpdater = {
193+
label: "Downloading Updates...",
194+
click() {
195+
autoUpdater.checkForUpdates();
204196
}
205-
});
206-
207-
// Set default property for nothing-found-window
208-
Storage.has("noting-found-window", (error, hasKey) => {
209-
if (error) throw error;
210-
if (!hasKey) {
211-
Storage.set("noting-found-window", true, error => {
212-
if (error) throw error;
213-
nothingFoundWindowValue = true;
214-
});
197+
};
198+
} else {
199+
menuItemUpdater = {
200+
label: "Check for Updates...",
201+
click() {
202+
autoUpdater.checkForUpdates();
215203
}
216-
});
217-
}
218-
219-
app.setAboutPanelOptions({
220-
applicationName: "Caption",
221-
applicationVersion: pkg.version,
222-
copyright: "Made with 💖 by Giel Cobben. \n www.gielcobben.com",
223-
credits: `With the invaluable help of: \n OpenSubtitles.org and Addic7ed.com`,
224-
version: pkg.version
225-
});
226-
227-
await installExtensions();
228-
229-
/*
230-
* MainWindow
231-
*/
232-
createMainWindow();
233-
234-
/*
235-
* IPC's
236-
*/
237-
ipcMain.on("close-main", () => {
238-
mainWindow.close();
239-
app.quit();
240-
});
241-
242-
ipcMain.on("lang-changed", () => {
243-
mainWindow.webContents.send("change-language");
244-
});
245-
246-
/*
247-
* Downloads
248-
*/
249-
mainWindow.webContents.session.on(
250-
"will-download",
251-
(event, item, webContents) => {
252-
item.on("updated", (event, state) => {
253-
if (state === "interrupted") {
254-
console.log("Download is interrupted but can be resumed");
255-
} else if (state === "progressing") {
256-
if (item.isPaused()) {
257-
console.log("Download is paused");
258-
} else {
259-
console.log(`Received bytes: ${item.getReceivedBytes()}`);
260-
}
261-
}
262-
});
263-
264-
item.once("done", (event, state) => {
265-
if (state === "completed") {
266-
console.log("Download successfully");
267-
} else {
268-
console.log(`Download failed: ${state}`);
269-
}
270-
});
271-
}
272-
);
273-
274-
/*
275-
* Development
276-
*/
277-
if (process.env.NODE_ENV === "development") {
278-
mainWindow.openDevTools();
279-
mainWindow.webContents.on("context-menu", (e, props) => {
280-
const { x, y } = props;
281-
282-
Menu.buildFromTemplate([
283-
{
284-
label: "Inspect element",
285-
click() {
286-
mainWindow.inspectElement(x, y);
287-
}
288-
}
289-
]).popup(mainWindow);
290-
});
204+
};
291205
}
292206

293207
/*
@@ -301,12 +215,7 @@ app.on("ready", async () => {
301215
label: "About Caption",
302216
selector: "orderFrontStandardAboutPanel:"
303217
},
304-
{
305-
label: "Check for Updates...",
306-
click() {
307-
autoUpdater.checkForUpdates();
308-
}
309-
},
218+
menuItemUpdater,
310219
{
311220
type: "separator"
312221
},
@@ -511,4 +420,124 @@ app.on("ready", async () => {
511420

512421
menu = Menu.buildFromTemplate(template);
513422
Menu.setApplicationMenu(menu);
423+
};
424+
425+
app.on("ready", async () => {
426+
if (process.env.NODE_ENV !== "development") {
427+
/*
428+
* Let's Move
429+
*/
430+
431+
Storage.has("moveApp", async (error, value) => {
432+
if (!value) {
433+
try {
434+
const moved = await moveToApplications();
435+
if (!moved) {
436+
Storage.set("moveApp", false);
437+
}
438+
} catch (error) {
439+
console.log(error);
440+
}
441+
} else {
442+
Storage.get("moveApp", async (error, value) => {
443+
if (value) {
444+
try {
445+
const moved = await moveToApplications();
446+
} catch (error) {
447+
console.log(error);
448+
}
449+
} else {
450+
console.log("user choosed to not move the app!");
451+
}
452+
});
453+
}
454+
});
455+
456+
// Set default property for nothing-found-window
457+
Storage.has("noting-found-window", (error, hasKey) => {
458+
if (error) throw error;
459+
if (!hasKey) {
460+
Storage.set("noting-found-window", true, error => {
461+
if (error) throw error;
462+
nothingFoundWindowValue = true;
463+
});
464+
}
465+
});
466+
}
467+
468+
app.setAboutPanelOptions({
469+
applicationName: "Caption",
470+
applicationVersion: pkg.version,
471+
copyright: "Made with 💖 by Giel Cobben. \n www.gielcobben.com",
472+
credits: `With the invaluable help of: \n OpenSubtitles.org and Addic7ed.com`,
473+
version: pkg.version
474+
});
475+
476+
await installExtensions();
477+
478+
/*
479+
* MainWindow
480+
*/
481+
createMainWindow();
482+
483+
/*
484+
* IPC's
485+
*/
486+
ipcMain.on("close-main", () => {
487+
mainWindow.close();
488+
app.quit();
489+
});
490+
491+
ipcMain.on("lang-changed", () => {
492+
mainWindow.webContents.send("change-language");
493+
});
494+
495+
/*
496+
* Downloads
497+
*/
498+
mainWindow.webContents.session.on(
499+
"will-download",
500+
(event, item, webContents) => {
501+
item.on("updated", (event, state) => {
502+
if (state === "interrupted") {
503+
console.log("Download is interrupted but can be resumed");
504+
} else if (state === "progressing") {
505+
if (item.isPaused()) {
506+
console.log("Download is paused");
507+
} else {
508+
console.log(`Received bytes: ${item.getReceivedBytes()}`);
509+
}
510+
}
511+
});
512+
513+
item.once("done", (event, state) => {
514+
if (state === "completed") {
515+
console.log("Download successfully");
516+
} else {
517+
console.log(`Download failed: ${state}`);
518+
}
519+
});
520+
}
521+
);
522+
523+
/*
524+
* Development
525+
*/
526+
if (process.env.NODE_ENV === "development") {
527+
mainWindow.openDevTools();
528+
mainWindow.webContents.on("context-menu", (e, props) => {
529+
const { x, y } = props;
530+
531+
Menu.buildFromTemplate([
532+
{
533+
label: "Inspect element",
534+
click() {
535+
mainWindow.inspectElement(x, y);
536+
}
537+
}
538+
]).popup(mainWindow);
539+
});
540+
}
541+
542+
buildMenu();
514543
});

0 commit comments

Comments
 (0)