mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
check if is online
This commit is contained in:
@@ -3,6 +3,7 @@ import { UtilsService } from './utils.service';
|
||||
import path from 'path';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { BSVersion } from 'shared/bs-version.interface';
|
||||
import isOnline from 'is-online';
|
||||
|
||||
export class BSVersionLibService{
|
||||
|
||||
@@ -34,7 +35,7 @@ export class BSVersionLibService{
|
||||
this.bsVersions = JSON.parse(body);
|
||||
resolve(this.bsVersions);
|
||||
});
|
||||
res.on('error', (err) => reject(null))
|
||||
res.on('error', () => reject(null))
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -52,7 +53,7 @@ export class BSVersionLibService{
|
||||
|
||||
private async loadBsVersions(): Promise<BSVersion[]>{
|
||||
const [localVersions, remoteVersions] = await Promise.all([
|
||||
this.getLocalVersions(), this.getRemoteVersions()
|
||||
this.getLocalVersions(), (await isOnline({timeout: 1500}) && this.getRemoteVersions())
|
||||
]);
|
||||
let resVersions = localVersions;
|
||||
if(remoteVersions && remoteVersions.length){ resVersions = remoteVersions; this.updateLocalVersions(resVersions); }
|
||||
|
||||
@@ -4,6 +4,7 @@ import { IpcService } from "./ipc.service";
|
||||
import { ModalExitCode, ModalService, ModalType } from './modale.service';
|
||||
import { NotificationService } from './notification.service';
|
||||
import { ProgressBarService } from './progress-bar.service';
|
||||
import { IpcResponse } from 'shared/models/ipc';
|
||||
|
||||
export class BSVersionManagerService {
|
||||
|
||||
@@ -22,8 +23,7 @@ export class BSVersionManagerService {
|
||||
this.modalService = ModalService.getInsance();
|
||||
this.notificationService = NotificationService.getInstance();
|
||||
this.progressBarService = ProgressBarService.getInstance();
|
||||
this.askAvailableVersions();
|
||||
this.askInstalledVersions();
|
||||
this.askAvailableVersions().then(() => this.askInstalledVersions());
|
||||
}
|
||||
|
||||
public static getInstance(){
|
||||
@@ -45,13 +45,19 @@ export class BSVersionManagerService {
|
||||
return this.installedVersions$.value;
|
||||
}
|
||||
|
||||
public askAvailableVersions(): void{
|
||||
this.ipcService.send<BSVersion[]>("bs-version.get-version-dict").then(res => this.availableVersions$.next(res.data));
|
||||
}
|
||||
public askAvailableVersions(): Promise<BSVersion[]>{
|
||||
return this.ipcService.send<BSVersion[]>("bs-version.get-version-dict").then(res => {
|
||||
this.availableVersions$.next(res.data);
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
|
||||
public askInstalledVersions(): void{
|
||||
this.ipcService.send<BSVersion[]>("bs-version.installed-versions").then(res => this.setInstalledVersions(res.data));
|
||||
}
|
||||
public askInstalledVersions(): Promise<BSVersion[]>{
|
||||
return this.ipcService.send<BSVersion[]>("bs-version.installed-versions").then(res => {
|
||||
this.setInstalledVersions(res.data);
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
|
||||
public getAvailableYears(): string[]{
|
||||
return [...new Set(this.availableVersions$.value.map(v => v.year))].sort((a, b) => b.localeCompare(a));
|
||||
|
||||
Reference in New Issue
Block a user