Skip to content

Commit 82b2481

Browse files
committed
check network info with interval
1 parent 107d9e9 commit 82b2481

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

packages/machine-setup/frontend/src/components/NetworkInfo.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script setup lang="ts">
2929
import { filesystem, os } from '@neutralinojs/lib';
3030
import { NCard, NGrid, NGi, NButton, NInput, NSpace } from 'naive-ui';
31-
import { onMounted, ref } from 'vue';
31+
import { onMounted, onUnmounted, ref } from 'vue';
3232
3333
const netInfo = ref<any[]>([]);
3434
@@ -75,7 +75,7 @@ const saveConfig = async () => {
7575
}
7676
};
7777
78-
onMounted(async () => {
78+
const getIp = async () => {
7979
try {
8080
const res = await os.execCommand('ip --json address');
8181
const info = JSON.parse(res.stdOut);
@@ -92,7 +92,17 @@ onMounted(async () => {
9292
window.ip = ips?.[0]?.v4;
9393
} catch (error) {
9494
console.error(error);
95-
9695
}
96+
};
97+
98+
let intervalId: NodeJS.Timeout;
99+
100+
onMounted(async () => {
101+
await getIp();
102+
intervalId = setInterval(getIp, 5000);
103+
});
104+
105+
onUnmounted(() => {
106+
clearInterval(intervalId);
97107
});
98108
</script>

0 commit comments

Comments
 (0)