@@ -19,23 +19,20 @@ import { ipcMain } from 'electron'
19
19
import { sendFrontendMessage } from 'backend/main_window'
20
20
import { loadEpicHyperPlayGameInfoMap } from './hyperplay/utils'
21
21
import { isGameAvailable } from 'backend/api/helpers'
22
- interface GameManagerMap {
23
- [ key : string ] : GameManager
24
- }
22
+ import { notify } from '../dialog/dialog'
23
+ import i18next from 'i18next'
24
+
25
+ const MAX_GAMES_UPDATE_NOTIFICATIONS = 3
25
26
26
- export const gameManagerMap : GameManagerMap = {
27
+ export const gameManagerMap : Record < Runner , GameManager > = {
27
28
hyperplay : HyperPlayGameManager ,
28
29
sideload : SideloadGameManager ,
29
30
gog : GOGGameManager ,
30
31
legendary : LegendaryGameManager ,
31
32
nile : NileGameManager
32
33
}
33
34
34
- interface LibraryManagerMap {
35
- [ key : string ] : LibraryManager
36
- }
37
-
38
- export const libraryManagerMap : LibraryManagerMap = {
35
+ export const libraryManagerMap : Record < Runner , LibraryManager > = {
39
36
hyperplay : HyperPlayLibraryManager ,
40
37
sideload : SideloadLibraryManager ,
41
38
gog : GOGLibraryManager ,
@@ -91,6 +88,59 @@ export function autoUpdate(runner: Runner, gamesToUpdate: string[]) {
91
88
return gamesToUpdate
92
89
}
93
90
91
+ let notificationsSent = false
92
+
93
+ // We only check hyperplay games for updates
94
+ export async function sendGameUpdatesNotifications ( ) {
95
+ if ( notificationsSent ) {
96
+ return
97
+ }
98
+ notificationsSent = true
99
+ const gamesToUpdate : string [ ] = [ ]
100
+ const allGames = await libraryManagerMap . hyperplay . listUpdateableGames ( )
101
+ const gamesToCheck = allGames . slice ( 0 , MAX_GAMES_UPDATE_NOTIFICATIONS )
102
+
103
+ const gameSettings = await Promise . all (
104
+ gamesToCheck . map ( async ( game ) => gameManagerMap . hyperplay . getSettings ( game ) )
105
+ )
106
+
107
+ const notifiableGames = gamesToCheck . filter ( async ( _game , index ) => {
108
+ const { ignoreGameUpdates } = gameSettings [ index ]
109
+ return ! ignoreGameUpdates
110
+ } )
111
+
112
+ gamesToUpdate . push ( ...notifiableGames )
113
+
114
+ if ( gamesToUpdate . length === 0 ) {
115
+ return
116
+ }
117
+
118
+ const leadGameInfo = gameManagerMap . hyperplay . getGameInfo ( gamesToUpdate [ 0 ] )
119
+
120
+ const title = i18next . t (
121
+ 'gameUpdateNotifications.title' ,
122
+ 'Game Updates Available'
123
+ )
124
+
125
+ let body = ''
126
+
127
+ if ( gamesToUpdate . length > 1 ) {
128
+ body = i18next . t (
129
+ 'gameUpdateNotifications.body.multiple' ,
130
+ `${ leadGameInfo . title } and other games are ready to update.` ,
131
+ { gameName : leadGameInfo . title }
132
+ )
133
+ } else {
134
+ body = i18next . t (
135
+ 'gameUpdateNotifications.body.single' ,
136
+ `There is an update ready for ${ leadGameInfo . title } .` ,
137
+ { gameName : leadGameInfo . title }
138
+ )
139
+ }
140
+
141
+ notify ( { title, body } )
142
+ }
143
+
94
144
export async function initStoreManagers ( ) {
95
145
await LegendaryLibraryManager . initLegendaryLibraryManager ( )
96
146
await GOGLibraryManager . refresh ( )
0 commit comments