Skip to content

Commit

Permalink
Make 'fix #1' better & avoid some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hulxv committed Jan 8, 2022
1 parent b7c41cd commit e9e4ad4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
14 changes: 8 additions & 6 deletions main/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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(),
Expand Down
11 changes: 3 additions & 8 deletions main/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion renderer/components/Settings/vnStat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Stack align='center'>
<Heading>Something went wrong</Heading>
Expand Down

0 comments on commit e9e4ad4

Please sign in to comment.