rpcfetch: placeholder: add %hostname placeholder

The variable should be assigned a value in the init function of platform-specific apply implementations.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-06-21 12:09:50 +09:00
parent 2c859c1a46
commit 101b997771
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
3 changed files with 13 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import (
var (
pidS = strconv.Itoa(os.Getpid())
hostname string
launchTime = time.Now().Unix()
)
@ -23,6 +24,9 @@ var substitute = map[string]func(s *applyState) string{
"pid": func(_ *applyState) string {
return pidS
},
"hostname": func(_ *applyState) string {
return hostname
},
"1min": func(s *applyState) string {
s.populateLoadavg()
return s.loadavg[0]

View File

@ -9,6 +9,14 @@ import (
"strings"
)
func init() {
if h, err := os.Hostname(); err != nil {
log.Fatalf("error reading hostname: %s", err)
} else {
hostname = h
}
}
func (s *applyState) populateLoadavg() {
if s.loadavg != nil {
return

View File

@ -18,7 +18,7 @@ var defaultConfig = config{
Timestamps: &rpcfetch.ActivityTimestamps{Start: &launchTime},
Assets: &rpcfetch.ActivityAssets{
LargeImage: "yorha",
LargeText: "1252927154480611351",
LargeText: "%hostname",
SmallImage: "flan",
SmallText: "PID: %pid",
},