app-init
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// mkico packs internal/gui/logo.png into a single-image ICO at cmd/tunnel/app.ico.
|
||||
// Prefer replacing app.ico with a proper multi-size .ico from a designer tool;
|
||||
// this helper is a quick path when you only have a PNG.
|
||||
func main() {
|
||||
root, err := findRoot()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pngPath := filepath.Join(root, "internal", "gui", "logo.png")
|
||||
icoPath := filepath.Join(root, "cmd", "tunnel", "app.ico")
|
||||
|
||||
png, err := os.ReadFile(pngPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var w, h uint32
|
||||
if len(png) >= 24 {
|
||||
w = binary.BigEndian.Uint32(png[16:20])
|
||||
h = binary.BigEndian.Uint32(png[20:24])
|
||||
}
|
||||
wb, hb := byte(w), byte(h)
|
||||
if w >= 256 {
|
||||
wb = 0
|
||||
}
|
||||
if h >= 256 {
|
||||
hb = 0
|
||||
}
|
||||
out := make([]byte, 22+len(png))
|
||||
binary.LittleEndian.PutUint16(out[2:], 1)
|
||||
binary.LittleEndian.PutUint16(out[4:], 1)
|
||||
out[6] = wb
|
||||
out[7] = hb
|
||||
binary.LittleEndian.PutUint16(out[10:], 1)
|
||||
binary.LittleEndian.PutUint16(out[12:], 32)
|
||||
binary.LittleEndian.PutUint32(out[14:], uint32(len(png)))
|
||||
binary.LittleEndian.PutUint32(out[18:], 22)
|
||||
copy(out[22:], png)
|
||||
if err := os.WriteFile(icoPath, out, 0o644); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("wrote", icoPath)
|
||||
}
|
||||
|
||||
func findRoot() (string, error) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dir := wd
|
||||
for {
|
||||
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
|
||||
return dir, nil
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
return "", fmt.Errorf("go.mod not found from %s", wd)
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user