diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 112 |
1 files changed, 96 insertions, 16 deletions
@@ -2,6 +2,7 @@ package main import ( "context" + "deepcool-display-linux/modules" "embed" "flag" "fmt" @@ -9,6 +10,7 @@ import ( "github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options/assetserver" "os" + "time" ) //go:embed all:frontend/dist @@ -16,7 +18,11 @@ var assets embed.FS var ( daemonFlag bool + err error filename string + tempFlag bool + celsiusFlag bool + usageFlag bool helpFlag bool versionFlag bool version = "0.1.0" @@ -32,6 +38,9 @@ Options: -h, --help Show this help message -d, --daemon Run in daemon mode -f, --file Specify CSV file path for pattern + -t, --temp Show CPU temperature + -c, --celsius Show CPU temperature in Celsius + -u, --usage Show CPU usage -v, --version Show the version of the app Modes: @@ -40,7 +49,7 @@ Modes: Example: %s 2. Daemon Mode: - Run with -d flag and specify a CSV file to load a pattern + Run with -d flag and specify an option. Example: %s -d -f pattern.csv For more information, visit: https://github.com/blaster4385/deepcool-display-linux @@ -52,6 +61,12 @@ func main() { flag.BoolVar(&daemonFlag, "d", false, "Run as daemon") flag.StringVar(&filename, "file", "", "CSV file") flag.StringVar(&filename, "f", "", "CSV file") + flag.BoolVar(&tempFlag, "temp", false, "Show CPU temperature") + flag.BoolVar(&tempFlag, "t", false, "Show CPU temperature") + flag.BoolVar(&celsiusFlag, "celsius", false, "Show CPU temperature in Celsius") + flag.BoolVar(&celsiusFlag, "c", false, "Show CPU temperature in Celsius") + flag.BoolVar(&usageFlag, "usage", false, "Show CPU usage") + flag.BoolVar(&usageFlag, "u", false, "Show CPU usage") flag.BoolVar(&helpFlag, "help", false, "Show help message") flag.BoolVar(&helpFlag, "h", false, "Show help message") flag.BoolVar(&versionFlag, "version", false, "Show app version") @@ -70,23 +85,88 @@ func main() { app := NewApp() if daemonFlag { - if filename == "" { - fmt.Println("Error: CSV file path is required in daemon mode") - fmt.Println("Use -h or --help for usage information") - os.Exit(1) - } - ctx := context.Background() app.startup(ctx) - grid, err := app.ParseCSV(filename) - if err != nil { - fmt.Printf("Error parsing CSV file: %v\n", err) - os.Exit(1) - } - err = app.SendPattern(grid) - if err != nil { - fmt.Printf("Error sending pattern: %v\n", err) - os.Exit(1) + if filename != "" { + grid, err := app.ParseCSV(filename) + if err != nil { + fmt.Printf("Error parsing CSV file: %v\n", err) + os.Exit(1) + } + err = app.SendPattern(grid) + if err != nil { + fmt.Printf("Error sending pattern: %v\n", err) + os.Exit(1) + } + } else if tempFlag { + ticker := time.NewTicker(3 * time.Second) + defer ticker.Stop() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + go func() { + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + var temp float64 + if celsiusFlag { + temp, err = modules.GetCPUTemperature(false) + grid, err := modules.CreateNumberGrid(int(temp), "celsius", 5) + if err != nil { + fmt.Printf("Error creating number grid: %v\n", err) + os.Exit(1) + } + err = app.SendPattern(grid) + if err != nil { + fmt.Printf("Error sending pattern: %v\n", err) + os.Exit(1) + } + } else { + temp, err = modules.GetCPUTemperature(true) + grid, err := modules.CreateNumberGrid(int(temp), "fahrenheit", 5) + if err != nil { + fmt.Printf("Error creating number grid: %v\n", err) + os.Exit(1) + } + err = app.SendPattern(grid) + } + } + } + }() + } else if usageFlag { + ticker := time.NewTicker(3 * time.Second) + defer ticker.Stop() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + go func() { + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + usage, err := modules.GetCPUUsage() + if err != nil { + fmt.Printf("Error getting CPU usage: %v\n", err) + os.Exit(1) + } + grid, err := modules.CreateNumberGrid(int(usage), "percent", 5) + if err != nil { + fmt.Printf("Error creating number grid: %v\n", err) + os.Exit(1) + } + err = app.SendPattern(grid) + if err != nil { + fmt.Printf("Error sending pattern: %v\n", err) + os.Exit(1) + } + } + } + }() } select {} } else { |