From e9e4ad4515be92502253c2ef6d146cffc50f892b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CHulxv=E2=80=9D?= Date: Sat, 8 Jan 2022 22:17:49 +0200 Subject: [PATCH] Make 'fix #1' better & avoid some bugs --- main/background.js | 14 ++++++++------ main/util/index.js | 11 +++-------- renderer/components/Settings/vnStat/index.js | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/main/background.js b/main/background.js index 89ef89b..92f1fe3 100644 --- a/main/background.js +++ b/main/background.js @@ -66,6 +66,8 @@ async function INIT() { } await TrayIcon.init(); + mainWindow.webContents.send("send-config", (await AppConfig).get()); + if (!(await vnStatIsInstalled())) { error( "vnStat isn't installed, You should download and setup it before using this client.", @@ -74,18 +76,18 @@ async function INIT() { return; } - // Send Configs - mainWindow.webContents.send("send-config", (await AppConfig).get()); - - mainWindow.webContents.send("send-vn-configs", vnStat.configurations().read()); + // Send vnStat data + mainWindow.webContents.send( + "send-vn-configs", + vnStat.configurations().read(), + ); - // Send Data mainWindow.webContents.send("send-traffic", await vnStat.traffic().getData()); + mainWindow.webContents.send( "send-vnstat-interfaces", await vnStat.interfaces(), ); - mainWindow.webContents.send( "send-vn-daemon-status", await vnStat.daemon().status(), diff --git a/main/util/index.js b/main/util/index.js index adf6ecb..2aaa0d0 100644 --- a/main/util/index.js +++ b/main/util/index.js @@ -41,19 +41,14 @@ export async function vnStatIsInstalled() { let bash = ` if ! [ -x "$(command -v vnstat)" ]; then echo "false" - exit 1 - else echo "true" -fi - `; + exit 1 +fi`; try { const { stdout, stderr } = await exec(bash); if (stderr) throw stderr; - return stdout - .split("\n") - .map((e) => e.replace(/[\n, " "]/, "")) - .includes("true"); + return stdout.includes("true"); } catch (err) { return err; } diff --git a/renderer/components/Settings/vnStat/index.js b/renderer/components/Settings/vnStat/index.js index 34fe0d7..1faa1ab 100644 --- a/renderer/components/Settings/vnStat/index.js +++ b/renderer/components/Settings/vnStat/index.js @@ -24,7 +24,7 @@ function vnStat() { const { configs, daemonStatus, stopDaemon, startDaemon, restartDaemon } = useVnStat(); - if (!configs || !Object.keys(configs)) + if (!configs || !(Object.keys(configs).length > 0)) return ( Something went wrong