Skip to content

Commit ef685bf

Browse files
Notify about new versions on non-auto-updating builds
1 parent a790871 commit ef685bf

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

app/global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ declare const processEnv: {
2727
[key: string]: string;
2828
};
2929

30+
declare const processPlatform: string;
31+
3032
declare module "*.scss" {
3133
const content: { [className: string]: string };
3234
export = content;

app/main/index.ts

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { app } from "electron";
1+
import { app, shell } from "electron";
22
import electronDebug from "electron-debug";
33
import log from "electron-log";
44
import { autoUpdater } from "electron-updater";
55
import { setAutoLauch } from "./lib/auto-launch";
66
import { initBreaks } from "./lib/breaks";
77
import "./lib/ipc";
8+
import { showNotification } from "./lib/notifications";
89
import { getAppInitialized } from "./lib/store";
910
import { initTray } from "./lib/tray";
1011
import { createSettingsWindow, createSoundsWindow } from "./lib/windows";
@@ -28,15 +29,60 @@ if (!gotTheLock) {
2829
app.exit();
2930
}
3031

32+
function getDownloadUrl(): string {
33+
switch (process.platform) {
34+
case "win32":
35+
return "https://github.com/tom-james-watson/breaktimer-app/releases/latest/download/BreakTimer.exe";
36+
case "linux":
37+
return "https://github.com/tom-james-watson/breaktimer-app/releases/latest";
38+
default:
39+
throw new Error("Download URL should not be called for macOS");
40+
}
41+
}
42+
43+
function shouldAutoInstall(): boolean {
44+
const isAppImage = process.env.APPIMAGE !== undefined;
45+
const isMac = process.platform === "darwin";
46+
47+
return isMac || isAppImage;
48+
}
49+
3150
function checkForUpdates(): void {
3251
log.info("Checking for updates...");
3352
autoUpdater.logger = log;
53+
3454
autoUpdater.on("error", (error) => {
3555
log.error(`Auto updater error: ${error}`);
3656
});
37-
autoUpdater.checkForUpdatesAndNotify().catch((error) => {
38-
log.error(`Unable to run auto updater: ${error}`);
39-
});
57+
58+
if (shouldAutoInstall()) {
59+
autoUpdater.checkForUpdatesAndNotify().catch((error) => {
60+
log.error(`Unable to run auto updater: ${error}`);
61+
});
62+
} else {
63+
autoUpdater.autoDownload = false;
64+
65+
autoUpdater.on("update-available", (info) => {
66+
log.info("Update available:", info);
67+
68+
const downloadUrl = getDownloadUrl();
69+
70+
showNotification(
71+
"Update Available",
72+
"A new version of BreakTimer is available. Click to download.",
73+
() => {
74+
shell.openExternal(downloadUrl).catch((error) => {
75+
log.error(`Failed to open download URL: ${error}`);
76+
});
77+
},
78+
false,
79+
);
80+
});
81+
82+
autoUpdater.checkForUpdates().catch((error) => {
83+
log.error(`Unable to check for updates: ${error}`);
84+
});
85+
}
4086
}
4187

4288
if (process.env.NODE_ENV === "production") {
@@ -101,7 +147,7 @@ app.on("ready", async () => {
101147
initTray();
102148
createSoundsWindow();
103149

104-
if (process.env.NODE_ENV !== "development" && process.platform !== "win32") {
150+
if (process.env.NODE_ENV !== "development") {
105151
checkForUpdates();
106152
}
107153
});

app/renderer/preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { contextBridge, ipcRenderer } = require("electron");
1010

1111
process.once("loaded", () => {
1212
contextBridge.exposeInMainWorld("processEnv", { ...process.env });
13+
contextBridge.exposeInMainWorld("processPlatform", process.platform);
1314
contextBridge.exposeInMainWorld("ipcRenderer", {
1415
invokeBreakPostpone: (action) => {
1516
return ipcRenderer.invoke("BREAK_POSTPONE", action);

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module.exports = [
4040
// Electron globals
4141
ipcRenderer: "readonly",
4242
processEnv: "readonly",
43+
processPlatform: "readonly",
4344
// React types
4445
React: "readonly",
4546
},
@@ -100,6 +101,7 @@ module.exports = [
100101
// Electron globals
101102
ipcRenderer: "readonly",
102103
processEnv: "readonly",
104+
processPlatform: "readonly",
103105
},
104106
},
105107
plugins: {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "breaktimer",
3-
"version": "2.0.0",
3+
"version": "1.1.10",
44
"productName": "BreakTimer",
55
"description": "Manage periodic breaks",
66
"scripts": {

0 commit comments

Comments
 (0)