mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-12-24 05:24:43 +00:00
Dev (#261)
* fix bug * updata UI * 0.3.2 ### Added - [Files] Files can now be selected multiple files and downloaded, deleted, moved, etc. - [Apps] Support to modify the application opening address.([#204](https://github.com/IceWhaleTech/CasaOS/issues/204)) ### Changed - [Apps] Hide the display of non-essential environment variables in the application. - [System] Network, disk, cpu, memory, etc. information is modified to be pushed via socket. - [System] Optimize opening speed.([#214](https://github.com/IceWhaleTech/CasaOS/issues/214)) ### Fixed - [System] Fixed the problem that sync data cannot submit the device ID ([#68](https://github.com/IceWhaleTech/CasaOS/issues/68)) - [Files] Fixed the code editor center alignment display problem.([#210](https://github.com/IceWhaleTech/CasaOS/issues/210)) - [Files] Fixed the problem of wrong name when downloading files.([#240](https://github.com/IceWhaleTech/CasaOS/issues/240)) - [System] Fixed the network display as a negative number problem.([#224](https://github.com/IceWhaleTech/CasaOS/issues/224)) * Modify log help class * Fix some bugs in 0.3.2 * Solve the operation file queue problem * Exclude web folders * update UI
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
net2 "net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/mem"
|
||||
"github.com/shirou/gopsutil/v3/net"
|
||||
)
|
||||
|
||||
type SystemService interface {
|
||||
@@ -23,11 +28,45 @@ type SystemService interface {
|
||||
ExecUSBAutoMountShell(state string)
|
||||
UpAppOrderFile(str string)
|
||||
GetAppOrderFile() []byte
|
||||
GetNet(physics bool) []string
|
||||
GetNetInfo() []net.IOCountersStat
|
||||
GetCpuCoreNum() int
|
||||
GetCpuPercent() float64
|
||||
GetMemInfo() *mem.VirtualMemoryStat
|
||||
}
|
||||
type systemService struct {
|
||||
log loger.OLog
|
||||
}
|
||||
|
||||
func (c *systemService) GetMemInfo() *mem.VirtualMemoryStat {
|
||||
memInfo, _ := mem.VirtualMemory()
|
||||
memInfo.UsedPercent, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", memInfo.UsedPercent), 64)
|
||||
return memInfo
|
||||
}
|
||||
|
||||
func (c *systemService) GetCpuPercent() float64 {
|
||||
percent, _ := cpu.Percent(0, false)
|
||||
value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", percent[0]), 64)
|
||||
return value
|
||||
}
|
||||
|
||||
func (c *systemService) GetCpuCoreNum() int {
|
||||
count, _ := cpu.Counts(false)
|
||||
return count
|
||||
}
|
||||
|
||||
func (c *systemService) GetNetInfo() []net.IOCountersStat {
|
||||
parts, _ := net.IOCounters(true)
|
||||
return parts
|
||||
}
|
||||
func (c *systemService) GetNet(physics bool) []string {
|
||||
t := "1"
|
||||
if physics {
|
||||
t = "2"
|
||||
}
|
||||
return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetNetCard " + t)
|
||||
}
|
||||
|
||||
func (s *systemService) UpdateSystemVersion(version string) {
|
||||
//command2.OnlyExec(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
|
||||
//s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
|
||||
@@ -99,12 +138,12 @@ func (s *systemService) GetCasaOSLogs(lineNumber int) string {
|
||||
|
||||
func GetDeviceAllIP() []string {
|
||||
var address []string
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
addrs, err := net2.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return address
|
||||
}
|
||||
for _, a := range addrs {
|
||||
if ipNet, ok := a.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
|
||||
if ipNet, ok := a.(*net2.IPNet); ok && !ipNet.IP.IsLoopback() {
|
||||
if ipNet.IP.To16() != nil {
|
||||
address = append(address, ipNet.IP.String())
|
||||
}
|
||||
@@ -112,6 +151,6 @@ func GetDeviceAllIP() []string {
|
||||
}
|
||||
return address
|
||||
}
|
||||
func NewSystemService(log loger.OLog) SystemService {
|
||||
return &systemService{log: log}
|
||||
func NewSystemService() SystemService {
|
||||
return &systemService{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user