Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12f4dc75f0 | ||
|
|
913fcc34ee | ||
|
|
ac856f4174 | ||
|
|
a5d793926b | ||
|
|
40a94bd001 |
@@ -18,7 +18,7 @@ It is i3bar text generator.
|
|||||||
|
|
||||||
## How to build it
|
## How to build it
|
||||||
|
|
||||||
This appliction was tested to compile with go v1.24.
|
This application was tested to compile with go v1.24.
|
||||||
|
|
||||||
All you need is go lang compiler and gnu make utility. Invoke
|
All you need is go lang compiler and gnu make utility. Invoke
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
batteries []*battery.Battery = []*battery.Battery{}
|
batteries = []*battery.Battery{}
|
||||||
Batts string
|
Batts string
|
||||||
ch int
|
ch int
|
||||||
status string
|
status string
|
||||||
@@ -52,6 +52,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to read file %s: %s", file, err)
|
log.Printf("Unable to read file %s: %s", file, err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to read file %s: %s", statusFile, err)
|
log.Printf("Unable to read file %s: %s", statusFile, err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +93,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to convert string from file %s to integer", file)
|
log.Printf("Unable to convert string from file %s to integer", file)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,9 +103,9 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
batteries, _ = battery.GetAll()
|
|
||||||
// In theory, this module should give for each entry its separate err, but in practice it gives
|
// In theory, this module should give for each entry its separate err, but in practice it gives
|
||||||
// one single err for all entries, so we cannot detemine whist exatly entry errored.
|
// one single err for all entries, so we cannot detemine whist exatly entry errored.
|
||||||
|
batteries, _ = battery.GetAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -1049,7 +1049,7 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.Vpn.Font == "" {
|
if sampleConfig.Vpn.Font == "" {
|
||||||
sampleConfig.Vpn.FontSize = sampleConfig.Font
|
sampleConfig.Vpn.Font = sampleConfig.Font
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.Vpn.FontSize == "" {
|
if sampleConfig.Vpn.FontSize == "" {
|
||||||
@@ -1463,6 +1463,7 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.CmdRun.Cmd == "" && sampleConfig.CmdRun.Enabled {
|
if sampleConfig.CmdRun.Cmd == "" && sampleConfig.CmdRun.Enabled {
|
||||||
sampleConfig.CmdRun.Enabled = false
|
sampleConfig.CmdRun.Enabled = false
|
||||||
|
|
||||||
log.Print(
|
log.Print(
|
||||||
"Setting sampleConfig.CmdRun.Enabled to false because sampleConfig.CmdRun.Cmd is not set",
|
"Setting sampleConfig.CmdRun.Enabled to false because sampleConfig.CmdRun.Cmd is not set",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (c *MyConfig) UpdateMemStats() {
|
|||||||
if c.Values.Memory.Usedpct != uint64(v.UsedPercent) || c.Values.Memory.Shared != v.Shared/1024/1024 || c.Values.Memory.Swap != v.SwapTotal-v.SwapFree {
|
if c.Values.Memory.Usedpct != uint64(v.UsedPercent) || c.Values.Memory.Shared != v.Shared/1024/1024 || c.Values.Memory.Swap != v.SwapTotal-v.SwapFree {
|
||||||
c.Values.Memory.Usedpct = uint64(v.UsedPercent)
|
c.Values.Memory.Usedpct = uint64(v.UsedPercent)
|
||||||
c.Values.Memory.Shared = v.Shared / 1024 / 1024
|
c.Values.Memory.Shared = v.Shared / 1024 / 1024
|
||||||
c.Values.Memory.Swap = sw.Used
|
c.Values.Memory.Swap = sw.Used / 1024 / 1024
|
||||||
c.Channels.UpdateReady <- true
|
c.Channels.UpdateReady <- true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
41
internal/lib/runcommand.go
Normal file
41
internal/lib/runcommand.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunCommands gets list of commands runs them sequentally and conacatenates their output.
|
||||||
|
func (c *MyConfig) RunCommand() {
|
||||||
|
var (
|
||||||
|
InitialDelay = 100 * time.Millisecond
|
||||||
|
LoopIterationDelay = time.Duration(c.CmdRun.Delay) * time.Second
|
||||||
|
Delay = InitialDelay
|
||||||
|
ticker = time.NewTicker(Delay)
|
||||||
|
)
|
||||||
|
|
||||||
|
for range ticker.C {
|
||||||
|
if Delay == InitialDelay {
|
||||||
|
Delay = LoopIterationDelay
|
||||||
|
ticker.Reset(Delay)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
outputString string
|
||||||
|
command = []string{c.CmdRun.Cmd}
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(c.CmdRun.Args) > 0 {
|
||||||
|
command = append(command, c.CmdRun.Args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
outputString += RunProcess(command)
|
||||||
|
|
||||||
|
log.Println(c.Values.RunCommandOutput)
|
||||||
|
|
||||||
|
if c.Values.RunCommandOutput != outputString {
|
||||||
|
c.Values.RunCommandOutput = outputString
|
||||||
|
c.Channels.UpdateReady <- true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
func (c *MyConfig) Spawner() {
|
func (c *MyConfig) Spawner() {
|
||||||
for prg := range c.Channels.RunChan {
|
for prg := range c.Channels.RunChan {
|
||||||
<-time.After(25 * time.Millisecond)
|
<-time.After(25 * time.Millisecond)
|
||||||
|
|
||||||
devnullR, _ := os.Open(os.DevNull)
|
devnullR, _ := os.Open(os.DevNull)
|
||||||
devnullW, _ := os.OpenFile(os.DevNull, os.O_WRONLY|os.O_APPEND, 0644)
|
devnullW, _ := os.OpenFile(os.DevNull, os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
|
|
||||||
@@ -68,9 +69,9 @@ func RunProcess(command []string) string {
|
|||||||
|
|
||||||
switch len(command) {
|
switch len(command) {
|
||||||
case 1:
|
case 1:
|
||||||
cmd = exec.Command(command[0], "")
|
cmd = exec.Command(command[0], "") //nolint: gosec
|
||||||
default:
|
default:
|
||||||
cmd = exec.Command(command[0], command[1:]...)
|
cmd = exec.Command(command[0], command[1:]...) //nolint: gosec
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Dir = "/"
|
cmd.Dir = "/"
|
||||||
@@ -87,10 +88,10 @@ func RunProcess(command []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
} else {
|
}
|
||||||
if stderr.String() != "" {
|
|
||||||
log.Printf("%s: %s", strings.Join(command, " "), stderr.String())
|
if stderr.String() != "" {
|
||||||
}
|
log.Printf("%s: %s", strings.Join(command, " "), stderr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimRight(stdout.String(), "\n")
|
return strings.TrimRight(stdout.String(), "\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user