mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-03 21:43:18 +00:00
typescript: Migrate reconnect-util to typescript.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const isOnline = require('is-online');
|
import * as isOnline from 'is-online';
|
||||||
const Logger = require('./logger-util');
|
|
||||||
|
import Logger = require('./logger-util');
|
||||||
|
|
||||||
const logger = new Logger({
|
const logger = new Logger({
|
||||||
file: `domain-util.log`,
|
file: `domain-util.log`,
|
||||||
@@ -7,16 +8,22 @@ const logger = new Logger({
|
|||||||
});
|
});
|
||||||
|
|
||||||
class ReconnectUtil {
|
class ReconnectUtil {
|
||||||
constructor(serverManagerView) {
|
// TODO: TypeScript - Figure out how to annotate serverManagerView
|
||||||
|
// it should be ServerManagerView; maybe make it a generic so we can
|
||||||
|
// pass the class from main.js
|
||||||
|
serverManagerView: any;
|
||||||
|
alreadyReloaded: boolean;
|
||||||
|
|
||||||
|
constructor(serverManagerView: any) {
|
||||||
this.serverManagerView = serverManagerView;
|
this.serverManagerView = serverManagerView;
|
||||||
this.alreadyReloaded = false;
|
this.alreadyReloaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearState() {
|
clearState(): void {
|
||||||
this.alreadyReloaded = false;
|
this.alreadyReloaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pollInternetAndReload() {
|
pollInternetAndReload(): void {
|
||||||
const pollInterval = setInterval(() => {
|
const pollInterval = setInterval(() => {
|
||||||
this._checkAndReload()
|
this._checkAndReload()
|
||||||
.then(status => {
|
.then(status => {
|
||||||
@@ -28,11 +35,12 @@ class ReconnectUtil {
|
|||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
_checkAndReload() {
|
// TODO: Make this a async function
|
||||||
|
_checkAndReload(): Promise<boolean> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
if (!this.alreadyReloaded) { // eslint-disable-line no-negated-condition
|
if (!this.alreadyReloaded) { // eslint-disable-line no-negated-condition
|
||||||
isOnline()
|
isOnline()
|
||||||
.then(online => {
|
.then((online: boolean) => {
|
||||||
if (online) {
|
if (online) {
|
||||||
if (!this.alreadyReloaded) {
|
if (!this.alreadyReloaded) {
|
||||||
this.serverManagerView.reloadCurrentView();
|
this.serverManagerView.reloadCurrentView();
|
||||||
@@ -57,4 +65,4 @@ class ReconnectUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ReconnectUtil;
|
export = ReconnectUtil;
|
||||||
Reference in New Issue
Block a user