@@ -3,7 +3,7 @@ import { ProgressInfo } from 'electron-updater/node_modules/electron-builder-htt
33import * as dateFormat from 'dateformat' ;
44
55import { GamesCollection } from '../models/GamesCollection' ;
6- import { PotentialGame } from '../models/PotentialGame' ;
6+ import { GameSource , PotentialGame } from '../models/PotentialGame' ;
77import { PlayableGame } from '../models/PlayableGame' ;
88import { languageInstance } from './Language' ;
99import { displayRemoveGameModal , formatTimePlayed , urlify } from './helpers' ;
@@ -12,13 +12,16 @@ export class VitrineClient {
1212 private potentialGames : GamesCollection < PotentialGame > ;
1313 private playableGames : GamesCollection < PlayableGame > ;
1414 private clickedGame : PlayableGame ;
15+ private releaseUrl : string ;
1516
16- constructor ( ) {
17+ public constructor ( ) {
1718 this . potentialGames = new GamesCollection ( ) ;
1819 this . playableGames = new GamesCollection ( ) ;
19- window . onerror = function ( error , url , line ) {
20+ this . releaseUrl = 'https://github.com/paul-roman/vitrine/releases/tag/v' ;
21+
22+ window . onerror = function ( message : string , filename ?: string , line ?: number , col ?: number , error ?: Error ) {
2023 let errorHtml : string = '<h4>' + languageInstance . replaceJs ( 'error' ) + '</h4><hr>'
21- + '<pre>' + url + ':' + line + '</pre><p>' + error . replace ( 'Uncaught Error: ' , '' ) + '</p>' ;
24+ + '<pre>' + filename + ':' + line + ':' + col + ' </pre><p>' + message . replace ( 'Uncaught Error: ' , '' ) + '</p>' ;
2225 $ ( '#error-message' ) . clear ( ) . html ( errorHtml ) ;
2326 $ ( '#error-modal' ) . modal ( 'show' ) ;
2427 }
@@ -58,9 +61,7 @@ export class VitrineClient {
5861 $ ( '#update-app-disclaimer' ) . html ( languageInstance . replaceJs ( 'updateText' , version ) ) ;
5962 $ ( '#app-change-logs' ) . html ( changeLogsHtml ) . click ( ( event ) => {
6063 event . preventDefault ( ) ;
61-
62- let releaseUrl : string = 'https://github.com/paul-roman/vitrine/releases/tag/v' + version ;
63- shell . openExternal ( releaseUrl ) ;
64+ shell . openExternal ( this . releaseUrl + version ) ;
6465 } ) ;
6566 $ ( '#update-app-btn' ) . click ( function ( ) {
6667 $ ( this ) . loading ( ) ;
@@ -70,9 +71,7 @@ export class VitrineClient {
7071 }
7172
7273 private serverError ( event : Electron . Event , error : string ) {
73- if ( error ) {
74- throw new Error ( error ) ;
75- }
74+ throw new Error ( error ) ;
7675 }
7776
7877 private getIgdbGame ( event : Electron . Event , error : string , game : any ) {
@@ -82,7 +81,7 @@ export class VitrineClient {
8281 $ ( '#submit-igdb-research-btn' ) . html ( languageInstance . replaceJs ( 'submitNewGame' ) ) ;
8382 $ ( '#igdb-research-modal' ) . modal ( 'hide' ) ;
8483
85- let formSelector = $ ( '#add-game-form' ) ;
84+ let formSelector : JQuery = $ ( '#add-game-form' ) ;
8685
8786 formSelector . find ( 'input[name=name]' ) . val ( game . name ) ;
8887 formSelector . find ( 'input[name=series]' ) . val ( game . series ) ;
@@ -112,6 +111,12 @@ export class VitrineClient {
112111 'background-image' : urlify ( game . cover )
113112 } ) ;
114113 formSelector . find ( 'input[name=cover]' ) . val ( game . cover ) ;
114+ if ( ! formSelector . find ( 'input[name=source]' ) . val ( ) )
115+ formSelector . find ( 'input[name=source]' ) . val ( GameSource . LOCAL ) ;
116+ if ( $ ( '#add-games-modal' ) . is ( ':visible' ) )
117+ $ ( '#add-games-modal' ) . modal ( 'hide' ) ;
118+ if ( ! $ ( '#add-game-modal' ) . is ( ':visible' ) )
119+ $ ( '#add-game-modal' ) . modal ( 'show' ) ;
115120 }
116121
117122 private getIgdbSearches ( event : Electron . Event , error : string , games : any ) {
@@ -144,15 +149,15 @@ export class VitrineClient {
144149
145150 private addPotentialGames ( event : Electron . Event , games : PotentialGame [ ] ) {
146151 this . potentialGames . games = games ;
147- this . renderPotentialGames ( ) ;
152+ this . renderPotentialGames ( event ) ;
148153 }
149154
150155 private removePotentialGame ( event : Electron . Event , gameId : string ) {
151156 this . potentialGames . removeGame ( gameId , ( error , game : PotentialGame ) => {
152157 if ( error )
153158 throw new Error ( error ) ;
154159 else if ( game ) {
155- this . renderPotentialGames ( ) ;
160+ this . renderPotentialGames ( event ) ;
156161 }
157162 } ) ;
158163 }
@@ -168,10 +173,8 @@ export class VitrineClient {
168173 }
169174
170175 private addPlayableGame ( event : Electron . Event , playableGame : PlayableGame ) {
171- if ( ! playableGame . details . steamId ) {
172- $ ( '#add-game-modal' ) . modal ( 'hide' ) ;
173- $ ( '#add-game-submit-btn' ) . html ( languageInstance . replaceJs ( 'submitNewGame' ) ) ;
174- }
176+ $ ( '#add-game-modal' ) . modal ( 'hide' ) ;
177+ $ ( '#add-game-submit-btn' ) . html ( languageInstance . replaceJs ( 'submitNewGame' ) ) ;
175178 this . playableGames . addGame ( playableGame ) ;
176179 this . renderPlayableGames ( ( ) => {
177180 this . updateGameUi ( playableGame ) ;
@@ -202,31 +205,41 @@ export class VitrineClient {
202205 } ) ;
203206 }
204207
205- private renderPotentialGames ( ) {
208+ private renderPotentialGames ( event : Electron . Event ) {
206209 if ( ! this . potentialGames . games . length ) {
207210 $ ( '#potential-games-area' ) . clear ( ) ;
208211 return ;
209212 }
210213 this . potentialGames . sort ( ) ;
211214 let counter : number = 0 ;
212- let gamesListHtml : string = '<div class="row potential-games-row">' ;
215+ let gamesList : JQuery = $ ( '<div class="row potential-games-row"></div>' ) ;
213216 this . potentialGames . forEach ( ( potentialGame : PotentialGame ) => {
214- gamesListHtml += '<div class="col-md-3 potential-game">'
215- + '<div class="potential-game-cover" style="background-image: url(' + potentialGame . details . cover + ')"></div>'
216- + potentialGame . name
217+ let gameHtml : string = '<div class="col-md-3">'
218+ + '<div class="potential-game-cover"><div class="image" style="background-image: url(' + potentialGame . details . cover + ')"></div>'
219+ + '<i class="fa fa-plus-circle icon animated"></i></div>'
220+ + '<span class="potential-game-name">' + potentialGame . name + '</span>'
217221 + '</div>' ;
222+ let game : JQuery = $ ( gameHtml ) ;
223+ game . find ( 'div.potential-game-cover' ) . blurPicture ( 55 , function ( ) {
224+ $ ( this ) . find ( '.image' ) . off ( ) . addClass ( 'cover-hovered' ) ;
225+ $ ( this ) . find ( '.icon' ) . off ( ) . removeClass ( 'fa-plus-circle' ) . addClass ( 'fa-spinner fa-spin cover-hovered' ) ;
226+ event . sender . send ( 'client.fill-igdb-game' , potentialGame . details . id ) ;
227+ let formSelector : JQuery = $ ( '#add-game-form' ) ;
228+ let exePath : string = potentialGame . commandLine . shift ( ) ;
229+ formSelector . find ( 'input[name=executable]' ) . val ( exePath ) ;
230+ formSelector . find ( 'input[name=arguments]' ) . val ( potentialGame . commandLine . join ( ' ' ) ) ;
231+ formSelector . find ( 'input[name=source]' ) . val ( potentialGame . source ) ;
232+ $ ( '#fill-with-igdb-btn' ) . prop ( 'disabled' , false ) ;
233+ $ ( '#add-game-submit-btn' ) . prop ( 'disabled' , false ) ;
234+ } ) ;
235+ gamesList . append ( game ) ;
218236 counter ++ ;
219- if ( counter % 4 === 0 || counter === this . potentialGames . games . length ) {
220- gamesListHtml += '</div>' ;
221- if ( counter === this . potentialGames . games . length ) {
222- $ ( '#add-games-modal' ) . find ( '.modal-body' ) . clear ( ) . html ( gamesListHtml ) ;
223- let buttonHtml : string = '<button id="add-potential-games-btn" class="btn btn-primary" data-toggle="modal" data-target="#add-games-modal">' +
224- languageInstance . replaceJs ( 'potentialGamesAdd' , this . potentialGames . games . length ) +
225- '</button>' ;
226- $ ( '#potential-games-area' ) . html ( buttonHtml ) ;
227- }
228- else
229- gamesListHtml += '<div class="row potential-games-row">' ;
237+ if ( counter === this . potentialGames . games . length ) {
238+ $ ( '#add-games-modal' ) . find ( '.modal-body' ) . clear ( ) . append ( gamesList ) ;
239+ let buttonHtml : string = '<button id="add-potential-games-btn" class="btn btn-primary" data-toggle="modal" data-target="#add-games-modal">' +
240+ languageInstance . replaceJs ( 'potentialGamesAdd' , this . potentialGames . games . length ) +
241+ '</button>' ;
242+ $ ( '#potential-games-area' ) . html ( buttonHtml ) ;
230243 }
231244 } ) ;
232245 }
@@ -280,6 +293,7 @@ export class VitrineClient {
280293 $ ( '#game-play' ) . addClass ( 'game-infos-visible' ) . find ( 'button' ) . off ( 'click' ) . click ( ( ) => {
281294 ipcRenderer . send ( 'client.launch-game' , game . uuid ) ;
282295 } ) ;
296+ $ ( '#game-play' ) . find ( 'p' ) . clear ( ) ;
283297 if ( game . timePlayed )
284298 $ ( '#game-play' ) . find ( 'p' ) . html ( languageInstance . replaceJs ( 'timePlayed' ) + ' ' + formatTimePlayed ( game . timePlayed ) ) ;
285299 $ ( '#game-desc' ) . addClass ( 'game-infos-visible' ) . html ( game . details . summary ) ;
0 commit comments