mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-05 12:24:08 +01:00
Eigenes Fenster: App-Icon als Fenstersymbol (16/32/48/256 px)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhyZeAnaXMQzGXmQU3
This commit is contained in:
5 files changed
+50
-7
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package icon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"image"
|
||||
"image/png"
|
||||
)
|
||||
|
||||
//go:embed sshtermy-16.png sshtermy-32.png sshtermy-48.png sshtermy-256.png
|
||||
var windowPNGs embed.FS
|
||||
|
||||
// Window liefert das Fenstersymbol in mehreren Größen (Titelleiste,
|
||||
// Taskleiste, Alt+Tab); das System nimmt die passende.
|
||||
func Window() []image.Image {
|
||||
var out []image.Image
|
||||
for _, n := range []string{"sshtermy-16.png", "sshtermy-32.png", "sshtermy-48.png", "sshtermy-256.png"} {
|
||||
b, err := windowPNGs.ReadFile(n)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if im, err := png.Decode(bytes.NewReader(b)); err == nil {
|
||||
out = append(out, im)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package icon
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestWindow(t *testing.T) {
|
||||
ims := Window()
|
||||
if len(ims) != 4 {
|
||||
t.Fatalf("%d Bilder, erwartet 4", len(ims))
|
||||
}
|
||||
for i, want := range []int{16, 32, 48, 256} {
|
||||
if b := ims[i].Bounds(); b.Dx() != want || b.Dy() != want {
|
||||
t.Errorf("Bild %d: %v, erwartet %d px", i, b, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/charmbracelet/x/term"
|
||||
|
||||
"github.com/db9979/sshtermy/assets/icon"
|
||||
"github.com/db9979/sshtermy/internal/crash"
|
||||
"github.com/db9979/sshtermy/internal/fullbackup"
|
||||
"github.com/db9979/sshtermy/internal/gui"
|
||||
@@ -65,7 +66,7 @@ func main() {
|
||||
// neues Fenster eines abgetrennten Tabs (⇧F10), siehe internal/detach;
|
||||
// „-window“: aus dem eigenen Fenster heraus, also wieder ein eigenes
|
||||
if len(os.Args) == 4 && os.Args[3] == "-window" && gui.Available() {
|
||||
os.Exit(gui.RunAttach(os.Args[2], gui.Options{Title: version.Name}))
|
||||
os.Exit(gui.RunAttach(os.Args[2], gui.Options{Title: version.Name, Icon: icon.Window()}))
|
||||
}
|
||||
if len(os.Args) != 3 {
|
||||
fail(fmt.Errorf("attach <ordner> [-window]"))
|
||||
@@ -140,7 +141,7 @@ func main() {
|
||||
log.SetOutput(io.Discard)
|
||||
if windowed {
|
||||
app.SetWindowed()
|
||||
_, err = gui.Run(app, gui.Options{Title: version.Name, CloseMsg: ui.WindowClosedMsg{}})
|
||||
_, err = gui.Run(app, gui.Options{Title: version.Name, Icon: icon.Window(), CloseMsg: ui.WindowClosedMsg{}})
|
||||
} else {
|
||||
_, err = tea.NewProgram(app).Run()
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
// Options für Run.
|
||||
type Options struct {
|
||||
Title string // Fenstertitel (Standard „sshTermy“)
|
||||
FontSize float64 // Schriftgröße in logischen Pixeln (Standard 14)
|
||||
Icon image.Image // Fenstersymbol (Windows/Linux)
|
||||
Title string // Fenstertitel (Standard „sshTermy“)
|
||||
FontSize float64 // Schriftgröße in logischen Pixeln (Standard 14)
|
||||
Icon []image.Image // Fenstersymbol in mehreren Größen (Windows/Linux)
|
||||
// CloseMsg geht an das Programm, wenn jemand das Fenster schließt, damit
|
||||
// es Sitzungen und Protokolle sauber beendet. nil = sofort beenden.
|
||||
CloseMsg tea.Msg
|
||||
|
||||
@@ -160,8 +160,8 @@ func (w *window) run() error {
|
||||
// Bild bleibt stehen; Draw zeichnet nur neu, wenn sich etwas geändert hat
|
||||
// (Akku, GPU).
|
||||
ebiten.SetScreenClearedEveryFrame(false)
|
||||
if icon := w.opts.Icon; icon != nil {
|
||||
ebiten.SetWindowIcon([]image.Image{icon})
|
||||
if len(w.opts.Icon) > 0 {
|
||||
ebiten.SetWindowIcon(w.opts.Icon)
|
||||
}
|
||||
return ebiten.RunGameWithOptions(w, &ebiten.RunGameOptions{InitUnfocused: false})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user