Skip to content

Commit 3e40c0e

Browse files
committed
Fetch latest version string and displays it in the byond panel
1 parent 2398e8e commit 3e40c0e

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

src/app/app.config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ import { provideAnimations } from '@angular/platform-browser/animations';
22
import { TuiRootModule } from '@taiga-ui/core';
33
import {
44
ApplicationConfig,
5-
provideZoneChangeDetection,
65
importProvidersFrom,
6+
provideZoneChangeDetection,
77
} from '@angular/core';
88
import { provideRouter } from '@angular/router';
99

1010
import { routes } from './app.routes';
11+
import { provideHttpClient, withFetch } from '@angular/common/http';
1112

1213
export const appConfig: ApplicationConfig = {
1314
providers: [
1415
provideAnimations(),
1516
provideZoneChangeDetection({ eventCoalescing: true }),
1617
provideRouter(routes),
1718
importProvidersFrom(TuiRootModule),
19+
provideHttpClient(withFetch()),
1820
],
1921
};
+12-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
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+
}
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
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';
25

36
@Component({
47
selector: 'app-panel-byond',
58
standalone: true,
6-
imports: [],
9+
imports: [AsyncPipe, TuiLoaderModule],
710
templateUrl: './byond.component.html',
811
styleUrl: './byond.component.scss',
912
})
1013
export default class ByondPanel {
1114
// noinspection JSUnusedGlobalSymbols
1215
static title = 'BYOND versions';
16+
17+
constructor(protected byondService: ByondService) {}
1318
}

src/vm/byond.service.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

0 commit comments

Comments
 (0)