Skip to content

Commit

Permalink
Displays active version
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkar598 committed Jun 28, 2024
1 parent b3bf91c commit 044c756
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
23 changes: 14 additions & 9 deletions src/app/panels/byond/byond.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@

<ul>
@for (version of byondService.versions; track version[0]) {
{{ version[0] }} ({{ statusToMessage[version[1]] }})
<button
tuiButton
appearance="primary"
size="xs"
(click)="byondService.setActive(version[0])"
>
Set active
</button>
{{ version[0] }}
@if (version[0] === byondService.activeVersion) {
(Active)
} @else {
({{ statusToMessage[version[1]] }})
<button
tuiButton
appearance="primary"
size="xs"
(click)="byondService.setActive(version[0])"
>
Set active
</button>
}
<button
tuiButton
appearance="secondary-destructive"
Expand Down
13 changes: 9 additions & 4 deletions src/vm/byond.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export enum VersionStatus {
export class ByondService {
public latestVersion: Promise<{ beta?: string; stable: string }>;
private lock = new SharedLock();
private active: string | null = null;

private _activeVersion: string | null = null;
public get activeVersion() {
return this._activeVersion;
}

public deleteVersion = this.lock.wrap(async (version: string) => {
const installs = await this.getByondFolder();
await installs.removeEntry(version.toString());
Expand All @@ -28,7 +33,7 @@ export class ByondService {
'/bin/rm',
`-rf\0/var/lib/byond/${version}.zip\0/var/lib/byond/${version}`,
);
if (this.active === version) this.active = null;
if (this._activeVersion === version) this._activeVersion = null;
});

private _versions = new Map<string, VersionStatus>();
Expand Down Expand Up @@ -58,7 +63,7 @@ export class ByondService {
`/mnt/host/byond/${version}.zip`,
);
this._versions.set(version, VersionStatus.Loaded);
this.active = version;
this._activeVersion = version;
} catch (e) {
this._versions.set(version, VersionStatus.Fetched);
await this.commandQueueService.runToCompletion(
Expand Down Expand Up @@ -131,7 +136,7 @@ export class ByondService {

public useActive<T extends (path: string | null) => any>(fn: T) {
this.lock.run(() =>
fn(this.active ? `/var/lib/byond/${this.active}/` : null),
fn(this._activeVersion ? `/var/lib/byond/${this._activeVersion}/` : null),
);
}
}

0 comments on commit 044c756

Please sign in to comment.