add server ping check
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2020-10-28 10:20:48 -05:00
parent f98369436e
commit 22c7dc2c95
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -11,8 +11,6 @@ import {Database} from './db/Database';
import {DatabaseColumn} from './db/DatabaseColumn'; import {DatabaseColumn} from './db/DatabaseColumn';
import {DatabaseEntry} from './db/DatabaseEntry'; import {DatabaseEntry} from './db/DatabaseEntry';
import {FileGroup} from './db/FileGroup'; import {FileGroup} from './db/FileGroup';
import {Page} from './db/Page'
import {PageNode} from "./db/PageNode";
export class ResourceNotAvailableOfflineError extends Error { export class ResourceNotAvailableOfflineError extends Error {
constructor(msg = 'This resource is not yet available offline on this device.') { constructor(msg = 'This resource is not yet available offline on this device.') {
@ -43,10 +41,30 @@ export class ApiService {
if ( !isConnected ) { if ( !isConnected ) {
this.makeOffline(); this.makeOffline();
} else { } else {
this.makeOnline(); // TODO add checks for server. this.checkOnline().then(isOnline => {
if ( isOnline ) {
this.makeOnline();
} else {
this.makeOffline();
} }
}); });
} }
});
this.checkOnline().then(isConnected => {
if ( !isConnected ) {
this.makeOffline();
} else {
this.makeOnline();
}
});
}
public checkOnline(): Promise<boolean> {
return fetch(this.statUrl).then(resp => {
return resp && (resp.ok || resp.type === 'opaque');
});
}
public makeOffline() { public makeOffline() {
this.offline = true; this.offline = true;