From cf620962bb9b1be2e973bf8bc3203b531ed7a852 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sat, 8 Jun 2024 20:55:42 +0200 Subject: [PATCH] alert on core error --- backend/api/api.go | 9 +++++++++ frontend/src/store/modules/data.ts | 16 +++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/backend/api/api.go b/backend/api/api.go index ebabc8e..0ca447b 100644 --- a/backend/api/api.go +++ b/backend/api/api.go @@ -176,6 +176,15 @@ func (a *APIHandler) loadData(c *gin.Context) (interface{}, error) { return "", err } onlines, err := a.StatsService.GetOnlines() + + sysInfo := a.ServerService.GetSingboxInfo() + if sysInfo["running"] == false { + logs := a.ServerService.GetLogs("sing-box", "1", "debug") + if len(logs) > 0 { + data["lastLog"] = logs[0] + } + } + if err != nil { return "", err } diff --git a/frontend/src/store/modules/data.ts b/frontend/src/store/modules/data.ts index b725dcb..2488b69 100644 --- a/frontend/src/store/modules/data.ts +++ b/frontend/src/store/modules/data.ts @@ -1,6 +1,7 @@ import { FindDiff } from '@/plugins/utils' import HttpUtils from '@/plugins/httputil' import { defineStore } from 'pinia' +import Message from './message' const Data = defineStore('Data', { state: () => ({ @@ -20,17 +21,10 @@ const Data = defineStore('Data', { this.lastLoad = Math.floor((new Date()).getTime()/1000) // Set new data - const data = JSON.parse(JSON.stringify(msg.obj)) - if (data.subURI) this.subURI = data.subURI - if (data.config) this.config = data.config - if (data.clients) this.clients = data.clients - if (data.tls) this.tlsConfigs = data.tls - this.onlines = data.onlines - - // To avoid ref copy - if (data.config) this.oldData.config = { ...msg.obj }.config - if (data.clients) this.oldData.clients = { ...msg.obj }.clients - if (data.tls) this.oldData.tlsConfigs = { ...msg.obj }.tls + if (msg.obj.lastLog) { + const sb = Message() + sb.showMessage('Core error: \n' + msg.obj.lastLog,'error', 5000) + } } }, async pushData() {