File tree 4 files changed +72
-3
lines changed
4 files changed +72
-3
lines changed Original file line number Diff line number Diff line change @@ -2,18 +2,20 @@ import { provideAnimations } from '@angular/platform-browser/animations';
2
2
import { TuiRootModule } from '@taiga-ui/core' ;
3
3
import {
4
4
ApplicationConfig ,
5
- provideZoneChangeDetection ,
6
5
importProvidersFrom ,
6
+ provideZoneChangeDetection ,
7
7
} from '@angular/core' ;
8
8
import { provideRouter } from '@angular/router' ;
9
9
10
10
import { routes } from './app.routes' ;
11
+ import { provideHttpClient , withFetch } from '@angular/common/http' ;
11
12
12
13
export const appConfig : ApplicationConfig = {
13
14
providers : [
14
15
provideAnimations ( ) ,
15
16
provideZoneChangeDetection ( { eventCoalescing : true } ) ,
16
17
provideRouter ( routes ) ,
17
18
importProvidersFrom ( TuiRootModule ) ,
19
+ provideHttpClient ( withFetch ( ) ) ,
18
20
] ,
19
21
} ;
Original file line number Diff line number Diff line change 1
- < p > byond works!</ p >
1
+ @if (byondService.latestVersion | async; as latestVersions) {
2
+ < p >
3
+ Latest stable: < span class ="font-bold "> {{ latestVersions.stable }}</ span >
4
+ </ p >
5
+ @if (latestVersions.beta) {
6
+ < p >
7
+ Latest beta: < span class ="font-bold "> {{ latestVersions.beta }}</ span >
8
+ </ p >
9
+ }
10
+ } @else {
11
+ Loading latest version...
12
+ }
Original file line number Diff line number Diff line change 1
1
import { Component } from '@angular/core' ;
2
+ import { ByondService } from '../../../vm/byond.service' ;
3
+ import { AsyncPipe } from '@angular/common' ;
4
+ import { TuiLoaderModule } from '@taiga-ui/core' ;
2
5
3
6
@Component ( {
4
7
selector : 'app-panel-byond' ,
5
8
standalone : true ,
6
- imports : [ ] ,
9
+ imports : [ AsyncPipe , TuiLoaderModule ] ,
7
10
templateUrl : './byond.component.html' ,
8
11
styleUrl : './byond.component.scss' ,
9
12
} )
10
13
export default class ByondPanel {
11
14
// noinspection JSUnusedGlobalSymbols
12
15
static title = 'BYOND versions' ;
16
+
17
+ constructor ( protected byondService : ByondService ) { }
13
18
}
Original file line number Diff line number Diff line change
1
+ import { Injectable } from '@angular/core' ;
2
+ import { HttpClient } from '@angular/common/http' ;
3
+ import { firstValueFrom , map } from 'rxjs' ;
4
+
5
+ @Injectable ( {
6
+ providedIn : 'root' ,
7
+ } )
8
+ export class ByondService {
9
+ public latestVersion : Promise < { beta ?: ByondVersion ; stable : ByondVersion } > ;
10
+
11
+ constructor ( httpClient : HttpClient ) {
12
+ this . latestVersion = firstValueFrom (
13
+ httpClient
14
+ . get ( 'https://secure.byond.com/download/version.txt' , {
15
+ responseType : 'text' ,
16
+ } )
17
+ . pipe (
18
+ map ( ( x ) => {
19
+ const [ stable , beta ] = x
20
+ . split ( '\n' )
21
+ . filter ( ( x ) => x )
22
+ . map ( ( x ) => new ByondVersion ( x ) ) ;
23
+ return { stable, beta } ;
24
+ } ) ,
25
+ ) ,
26
+ ) ;
27
+ }
28
+ }
29
+
30
+ export class ByondVersion {
31
+ public readonly major : number ;
32
+ public readonly minor : number ;
33
+
34
+ constructor ( version : string ) ;
35
+ constructor ( major : number , minor : number ) ;
36
+ constructor ( versionOrMajor : string | number , minor ?: number ) {
37
+ if ( typeof versionOrMajor === 'number' ) {
38
+ this . major = versionOrMajor ;
39
+ this . minor = minor ! ;
40
+ } else {
41
+ console . log ( versionOrMajor . split ( '.' ) ) ;
42
+ const [ major , minor ] = versionOrMajor . split ( '.' ) . map ( ( x ) => parseInt ( x ) ) ;
43
+ this . major = major ;
44
+ this . minor = minor ;
45
+ }
46
+ }
47
+
48
+ toString ( ) {
49
+ return `${ this . major } .${ this . minor } ` ;
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments