feat: add tray control, priority restoration and session logging
This commit is contained in:
1 parent
4f8f6218ad
commit
4880aa46dc
25 files changed
+3072
-676
No files matched your search
@@ -0,0 +1,97 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
PriorityClassIdle = 0x00000040
|
||||
PriorityClassNormal = 0x00000020
|
||||
PriorityClassHigh = 0x00000080
|
||||
PriorityClassAboveNormal = 0x00008000
|
||||
PriorityClassRealtime = 0x00000100
|
||||
PriorityClassBelowNormal = 0x00004000
|
||||
)
|
||||
|
||||
func parseMemSize(s string) (uint64, error) {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return 0, fmt.Errorf("empty value")
|
||||
}
|
||||
multiplier := uint64(1)
|
||||
switch s[len(s)-1] {
|
||||
case 'k', 'K':
|
||||
multiplier = 1024
|
||||
s = s[:len(s)-1]
|
||||
case 'm', 'M':
|
||||
multiplier = 1024 * 1024
|
||||
s = s[:len(s)-1]
|
||||
case 'g', 'G':
|
||||
multiplier = 1024 * 1024 * 1024
|
||||
s = s[:len(s)-1]
|
||||
}
|
||||
n, err := strconv.ParseUint(s, 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if n > math.MaxUint64/multiplier {
|
||||
return 0, fmt.Errorf("value overflows uint64")
|
||||
}
|
||||
return n * multiplier, nil
|
||||
}
|
||||
|
||||
func formatMemSize(b uint64) string {
|
||||
if b >= 1024*1024*1024 {
|
||||
return fmt.Sprintf("%.1fGB", float64(b)/(1024*1024*1024))
|
||||
}
|
||||
if b >= 1024*1024 {
|
||||
return fmt.Sprintf("%dMB", b/1024/1024)
|
||||
}
|
||||
return fmt.Sprintf("%dKB", b/1024)
|
||||
}
|
||||
|
||||
func isAboveNormal(c uint32) bool {
|
||||
return c == PriorityClassAboveNormal ||
|
||||
c == PriorityClassHigh ||
|
||||
c == PriorityClassRealtime
|
||||
}
|
||||
|
||||
func desiredPriority(rss, mem uint64, current uint32, gameMode, isGame bool) uint32 {
|
||||
if gameMode {
|
||||
if isGame {
|
||||
return PriorityClassHigh
|
||||
}
|
||||
return PriorityClassIdle
|
||||
}
|
||||
if rss >= mem {
|
||||
return PriorityClassHigh
|
||||
}
|
||||
if isAboveNormal(current) {
|
||||
return PriorityClassNormal
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func prioName(c uint32) string {
|
||||
switch c {
|
||||
case PriorityClassIdle:
|
||||
return "IDLE"
|
||||
case PriorityClassBelowNormal:
|
||||
return "BELOW_NORMAL"
|
||||
case PriorityClassNormal:
|
||||
return "NORMAL"
|
||||
case PriorityClassAboveNormal:
|
||||
return "ABOVE_NORMAL"
|
||||
case PriorityClassHigh:
|
||||
return "HIGH"
|
||||
case PriorityClassRealtime:
|
||||
return "REALTIME"
|
||||
default:
|
||||
return fmt.Sprintf("0x%X", c)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user