mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove networkOnline checks
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
parent
b7e982c5b2
commit
ecc87933b2
@ -39,7 +39,6 @@ import AbortController from "abort-controller";
|
|||||||
import { Agent, AgentOptions } from "https";
|
import { Agent, AgentOptions } from "https";
|
||||||
import type { Patch } from "rfc6902";
|
import type { Patch } from "rfc6902";
|
||||||
import electron from "electron";
|
import electron from "electron";
|
||||||
import { ipcMainOn } from "../ipc";
|
|
||||||
import { promises as dns } from "dns";
|
import { promises as dns } from "dns";
|
||||||
import retry from "async-retry";
|
import retry from "async-retry";
|
||||||
|
|
||||||
@ -239,10 +238,7 @@ export class KubeApi<T extends KubeObject> {
|
|||||||
protected watchDisposer: () => void;
|
protected watchDisposer: () => void;
|
||||||
private watchId = 1;
|
private watchId = 1;
|
||||||
private watchingSystemStatus = false; // If true, we are watching system status ('suspend'/'resume')
|
private watchingSystemStatus = false; // If true, we are watching system status ('suspend'/'resume')
|
||||||
private watchingNetworkStatus = false;
|
|
||||||
private systemSuspended = false;
|
private systemSuspended = false;
|
||||||
private networkOnline = true; // default is true as we assume the network is online when the KubeApi is initialized
|
|
||||||
|
|
||||||
constructor(protected options: IKubeApiOptions<T>) {
|
constructor(protected options: IKubeApiOptions<T>) {
|
||||||
const {
|
const {
|
||||||
objectConstructor,
|
objectConstructor,
|
||||||
@ -545,18 +541,6 @@ export class KubeApi<T extends KubeObject> {
|
|||||||
this.watchingSystemStatus = true;
|
this.watchingSystemStatus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private watchNetworkStatus() {
|
|
||||||
ipcMainOn("network:online", () => {
|
|
||||||
this.networkOnline = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMainOn("network:offline", () => {
|
|
||||||
this.networkOnline = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.watchingNetworkStatus = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private whenCanResolveDomainName(url = "k8slens.dev", retryOptions: Parameters<typeof retry>[1]) {
|
private whenCanResolveDomainName(url = "k8slens.dev", retryOptions: Parameters<typeof retry>[1]) {
|
||||||
return retry(() => dns.lookup(url), retryOptions);
|
return retry(() => dns.lookup(url), retryOptions);
|
||||||
}
|
}
|
||||||
@ -582,10 +566,6 @@ export class KubeApi<T extends KubeObject> {
|
|||||||
this.watchSystemStatus();
|
this.watchSystemStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.watchingNetworkStatus) {
|
|
||||||
this.watchNetworkStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
electron.powerMonitor.once("suspend", () => {
|
electron.powerMonitor.once("suspend", () => {
|
||||||
logger.info(`[KUBE-API] system suspended, abort watching of ${watchUrl}...`);
|
logger.info(`[KUBE-API] system suspended, abort watching of ${watchUrl}...`);
|
||||||
|
|
||||||
@ -602,7 +582,7 @@ export class KubeApi<T extends KubeObject> {
|
|||||||
const url = "k8slens.dev"; // url to check if domain names are resolvable.
|
const url = "k8slens.dev"; // url to check if domain names are resolvable.
|
||||||
|
|
||||||
this.whenCanResolveDomainName(url, { retries: 50, maxTimeout: 3000 }).then(() => {
|
this.whenCanResolveDomainName(url, { retries: 50, maxTimeout: 3000 }).then(() => {
|
||||||
logger.info(`[KUBE-API] domain name can be resolved, checking networkOnline:${this.networkOnline.toString?.()}`);
|
logger.info(`[KUBE-API] domain name can be resolved.`);
|
||||||
|
|
||||||
let abortController = opts.abortController;
|
let abortController = opts.abortController;
|
||||||
|
|
||||||
@ -610,16 +590,8 @@ export class KubeApi<T extends KubeObject> {
|
|||||||
abortController = new AbortController();
|
abortController = new AbortController();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.networkOnline) {
|
|
||||||
logger.info(`[KUBE-API] system resumed, resume watching of ${watchUrl}...`);
|
logger.info(`[KUBE-API] system resumed, resume watching of ${watchUrl}...`);
|
||||||
this.watch({ ...opts, abortController, namespace, callback, watchId, retry: true });
|
this.watch({ ...opts, abortController, namespace, callback, watchId, retry: true });
|
||||||
} else {
|
|
||||||
logger.info(`[KUBE-API] system resumed but network appears to be offline, resume watching when online.`);
|
|
||||||
electron.ipcMain.once("network:online", () => {
|
|
||||||
logger.info(`[KUBE-API] network on line, resume watching of ${watchUrl}...`);
|
|
||||||
this.watch({ ...opts, abortController, namespace, callback, watchId, retry: true });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
logger.warn(`[KUBE-API] error resolving domain name ${url}`, error);
|
logger.warn(`[KUBE-API] error resolving domain name ${url}`, error);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user