Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
radeeyate committed Mar 31, 2024
0 parents commit 040b0fc
Show file tree
Hide file tree
Showing 9 changed files with 868 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ember
*.apk
*.exe
.idea
8 changes: 8 additions & 0 deletions FyneApp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Website = "https://radi8.dev"

[Details]
Icon = "Icon.png"
Name = "Ember"
ID = "com.radi8.ember"
Version = "1.0.0"
Build = 27
Binary file added Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Ember: Hand Warmer App

Ember is a simple app that helps warm your hands by utilizing your device's CPU.

## Features

* Toggle on/off hand warmer functionality
* Learn how the app works
* Cross platform (Should work on Linux, Windows, MacOS, Android, and iOS)
* View device information like CPU cores, architecture, OS, and Go version.

## Screenshots

![On Linux](./Screenshots/Screenshot%20from%202024-03-31%2013-26-38.png)
![On Android](./Screenshots/Screenshot_20240331-132544.png)

## Download

Download the latest release from [the releases](https://github.com/radeeyate/ember/releases).

## Building the App

Requirements:

* Go compiler and environment setup

Steps:

1. Clone the repo `git clone https://github.com/radeeyate/ember.git`
1. Navigate to the directory `cd ember`
1. `go get`
1. Build the app:
* `go build .` for Linux, Windows, and MacOS
* `fyne package -os android` for Android
* to build for Android you need Android Studio + NDK
* `fyne package -os ios` for iOS
* to build for iOS you need Xcode + CocoaPods probably

You will either get a binary or .apk/.app.

Listen I don't want to write these so it might be wrong. I do not care. Just make an issue if there's a problem.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/Screenshot_20240331-132544.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module ember

go 1.21.6

require (
fyne.io/fyne/v2 v2.4.4
golang.org/x/text v0.14.0
)

require (
fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8 // indirect
github.com/go-text/typesetting v0.1.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tevino/abool v1.2.0 // indirect
github.com/yuin/goldmark v1.5.5 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
)
664 changes: 664 additions & 0 deletions go.sum

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package main

import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"math"
"os"
"runtime"
"strconv"
"strings"
"sync"
)

var (
isHeating bool
wg sync.WaitGroup
stopWorkChan chan struct{}
)

func getCPUTemp() string {
out, err := os.ReadFile("/sys/class/thermal/thermal_zone0/temp")
if err != nil {
fmt.Println(err)
return "Unknown error"
}

temp := strings.Replace(string(out), "\n", "", -1)

tempInt, err := strconv.Atoi(temp)
if err != nil {
fmt.Println(err)
return "Unknown error"
}

return fmt.Sprintf("%.1f°C", float64(tempInt)/1000.0)
}

func getDeviceInfo() string {
if runtime.GOOS == "linux" {
return "CPU Cores: " + fmt.Sprint(runtime.NumCPU()) +
"\nArchitecture: " + runtime.GOARCH +
"\nOS: " + cases.Title(language.English).String(string(runtime.GOOS)) +
"\nGo Version: " + runtime.Version() +
"\nCPU Temp: " + getCPUTemp()
}
return "CPU Cores: " + fmt.Sprint(runtime.NumCPU()) +
"\nArchitecture: " + runtime.GOARCH +
"\nOS: " + cases.Title(language.English).String(string(runtime.GOOS)) +
"\nGo Version: " + runtime.Version()
}

func doWork() {
var t float64 = math.MaxFloat64
for {
select {
case <-stopWorkChan:
return
default:
t /= 2.0
if t > math.SmallestNonzeroFloat32 {
t = math.MaxFloat64
}
}
}
}

func main() {
getCPUTemp()
runtime.GOMAXPROCS(runtime.NumCPU())

a := app.New()
w := a.NewWindow("Hand Warmer")

howItWorksContent := widget.NewLabel(`This app does computationally expensive work by continuously dividing ` +
`a very large number (math.MaxFloat64) by 2.0. ` +
`When the number gets too small (smaller than the smallest non-zero float32), ` +
`it's reset back to the largest number. ` +
`This loop keeps the CPU busy and therefore heats up your device.`)

howItWorksContent.Wrapping = fyne.TextWrapWord
howItWorksItem := widget.NewAccordionItem("How it Works", howItWorksContent)

deviceInfoAccordionItem := widget.NewAccordionItem("Device Info", widget.NewLabel(getDeviceInfo()))

label := widget.NewLabel("Hand Warmer Off")
label.Wrapping = fyne.TextWrapWord

button := widget.NewButton("Toggle On/Off Hand Warmer", func() {
if isHeating {
label.SetText("Cooling down...")
isHeating = false
close(stopWorkChan)
} else {
label.SetText("Heating up...")
isHeating = true
wg.Add(runtime.NumCPU())
stopWorkChan = make(chan struct{})
for i := 0; i < runtime.NumCPU(); i++ {
go doWork()
}
}
})

aboutAccordion := widget.NewAccordion(howItWorksItem)
devInfoAccordion := widget.NewAccordion(deviceInfoAccordionItem)
w.SetContent(container.NewVBox(label, button, aboutAccordion, devInfoAccordion))
w.ShowAndRun()
wg.Wait()
}

0 comments on commit 040b0fc

Please sign in to comment.