1
- import { app } from "electron" ;
1
+ import { app , shell } from "electron" ;
2
2
import electronDebug from "electron-debug" ;
3
3
import log from "electron-log" ;
4
4
import { autoUpdater } from "electron-updater" ;
5
5
import { setAutoLauch } from "./lib/auto-launch" ;
6
6
import { initBreaks } from "./lib/breaks" ;
7
7
import "./lib/ipc" ;
8
+ import { showNotification } from "./lib/notifications" ;
8
9
import { getAppInitialized } from "./lib/store" ;
9
10
import { initTray } from "./lib/tray" ;
10
11
import { createSettingsWindow , createSoundsWindow } from "./lib/windows" ;
@@ -28,15 +29,60 @@ if (!gotTheLock) {
28
29
app . exit ( ) ;
29
30
}
30
31
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
+
31
50
function checkForUpdates ( ) : void {
32
51
log . info ( "Checking for updates..." ) ;
33
52
autoUpdater . logger = log ;
53
+
34
54
autoUpdater . on ( "error" , ( error ) => {
35
55
log . error ( `Auto updater error: ${ error } ` ) ;
36
56
} ) ;
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
+ }
40
86
}
41
87
42
88
if ( process . env . NODE_ENV === "production" ) {
@@ -101,7 +147,7 @@ app.on("ready", async () => {
101
147
initTray ( ) ;
102
148
createSoundsWindow ( ) ;
103
149
104
- if ( process . env . NODE_ENV !== "development" && process . platform !== "win32" ) {
150
+ if ( process . env . NODE_ENV !== "development" ) {
105
151
checkForUpdates ( ) ;
106
152
}
107
153
} ) ;
0 commit comments