Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
139 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.newer-version-alert { | ||
position: fixed; | ||
bottom: 3px; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
background-color: rgba(0, 0, 0, 0.8); | ||
box-shadow: 0 0 46px 0 white; | ||
color: white; | ||
padding: 14px 30px; | ||
border-radius: 10px; | ||
|
||
span { | ||
font-style: italic; | ||
font-weight: bold; | ||
} | ||
.btn { | ||
font-weight: bold; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,76 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ToastrService } from 'ngx-toastr'; | ||
import { distinctUntilChanged } from 'rxjs/operators'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
import { MysqlService } from '../shared/services/mysql.service'; | ||
import { SqliteQueryService } from '@keira-shared/services/sqlite-query.service'; | ||
import { ElectronService } from '@keira-shared/services/electron.service'; | ||
import { KEIRA3_REPO_URL, LATEST_RELEASE_API_URL } from '@keira-constants/general'; | ||
import { version } from '../../../package.json'; | ||
import { SubscriptionHandler } from '@keira-shared/utils/subscription-handler/subscription-handler'; | ||
|
||
@Component({ | ||
selector: 'keira-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'] | ||
}) | ||
export class AppComponent implements OnInit { | ||
|
||
export class AppComponent extends SubscriptionHandler implements OnInit { | ||
public readonly KEIRA3_REPO_URL = KEIRA3_REPO_URL; | ||
showNewerVersionAlert = false; | ||
sqliteResult: { id: number; name: string }; | ||
|
||
constructor( | ||
public mysqlService: MysqlService, | ||
public toastrService: ToastrService, | ||
private sqliteQueryService: SqliteQueryService, | ||
private electronService: ElectronService, | ||
) {} | ||
private http: HttpClient, | ||
) { | ||
super(); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.mysqlService.connectionLost$ | ||
.pipe(distinctUntilChanged()) | ||
.subscribe((status) => { | ||
if (!status) { | ||
this.toastrService.error('Database connection lost'); | ||
} else { | ||
this.toastrService.success('Database reconnected'); | ||
} | ||
}); | ||
this.handleConnectionLostAlerts(); | ||
this.handleSqliteTest(); | ||
this.handleNewerVersionAlert(); | ||
} | ||
|
||
private handleSqliteTest() { | ||
/* istanbul ignore next */ | ||
if (this.electronService.isElectron()) { | ||
this.sqliteQueryService.query<{ id: number, name: string}>( | ||
'SELECT * FROM achievements WHERE id = 970', true | ||
).subscribe((result) => { | ||
this.sqliteResult = result ? result[0] : null; | ||
}); | ||
this.subscriptions.push( | ||
this.sqliteQueryService.query<{ id: number, name: string }>( | ||
'SELECT * FROM achievements WHERE id = 970', true | ||
).subscribe((result) => { | ||
this.sqliteResult = result ? result[0] : null; | ||
}), | ||
); | ||
} | ||
} | ||
|
||
private handleConnectionLostAlerts() { | ||
this.subscriptions.push( | ||
this.mysqlService.connectionLost$ | ||
.pipe(distinctUntilChanged()) | ||
.subscribe((status) => { | ||
if (!status) { | ||
this.toastrService.error('Database connection lost'); | ||
} else { | ||
this.toastrService.success('Database reconnected'); | ||
} | ||
}), | ||
); | ||
} | ||
|
||
private handleNewerVersionAlert() { | ||
this.subscriptions.push( | ||
this.http.get<{ tag_name: string }>(LATEST_RELEASE_API_URL).subscribe(release => { | ||
const currentTag = `v${version}`; | ||
if (currentTag !== release.tag_name) { | ||
this.showNewerVersionAlert = true; | ||
} | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters