修复图标显示
This commit is contained in:
@@ -8,6 +8,8 @@
|
|||||||
*.app
|
*.app
|
||||||
*.dmg
|
*.dmg
|
||||||
*.exe
|
*.exe
|
||||||
|
*.syso
|
||||||
|
resources/icon.ico
|
||||||
|
|
||||||
# Go
|
# Go
|
||||||
/vendor/
|
/vendor/
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ APP_BUNDLE = $(APP_NAME).app
|
|||||||
GO = go
|
GO = go
|
||||||
CGO_ENABLED = 1
|
CGO_ENABLED = 1
|
||||||
GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
VERSION = 0.3.5-$(GIT_HASH)
|
VERSION = 0.3.6-$(GIT_HASH)
|
||||||
LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION)
|
LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION)
|
||||||
|
|
||||||
.PHONY: all build app run daemon clean vet tidy fmt icon build-windows
|
.PHONY: all build app run daemon clean vet tidy fmt icon icon-windows build-windows
|
||||||
|
|
||||||
## all: build the .app bundle (default)
|
## all: build the .app bundle (default)
|
||||||
all: app
|
all: app
|
||||||
@@ -81,8 +81,15 @@ fmt:
|
|||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR) $(APP_BUNDLE)
|
rm -rf $(BUILD_DIR) $(APP_BUNDLE)
|
||||||
|
|
||||||
|
## icon-windows: generate icon.ico and compile Windows resource (.syso)
|
||||||
|
icon-windows:
|
||||||
|
go run resources/genico/main.go
|
||||||
|
x86_64-w64-mingw32-windres -i resources/lmvpn.rc -O coff -o cmd/lmvpn/resource_windows_amd64.syso
|
||||||
|
x86_64-w64-mingw32-windres -i resources/lmvpn.rc -O coff -o cmd/lmvpnd/resource_windows_amd64.syso
|
||||||
|
@echo "Generated Windows icon resources"
|
||||||
|
|
||||||
## build-windows: cross-compile Windows x86_64 exes (requires mingw-w64)
|
## build-windows: cross-compile Windows x86_64 exes (requires mingw-w64)
|
||||||
build-windows:
|
build-windows: icon-windows
|
||||||
mkdir -p $(BUILD_DIR)
|
mkdir -p $(BUILD_DIR)
|
||||||
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc \
|
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc \
|
||||||
$(GO) build -ldflags "$(LDFLAGS) -H windowsgui" -o $(BUILD_DIR)/$(GUI_BIN).exe ./cmd/lmvpn
|
$(GO) build -ldflags "$(LDFLAGS) -H windowsgui" -o $(BUILD_DIR)/$(GUI_BIN).exe ./cmd/lmvpn
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// genico converts resources/icon.png into a Windows .ico file using the
|
||||||
|
// PNG-in-ICO format (the PNG bytes are wrapped in a minimal ICO container
|
||||||
|
// without decoding/re-encoding). Works on Windows Vista and later.
|
||||||
|
//
|
||||||
|
// Run: go run resources/genico/main.go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pngData, err := os.ReadFile("resources/icon.png")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "genico: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ICO header (6 bytes) + one directory entry (16 bytes) = 22 bytes overhead.
|
||||||
|
const headerSize = 6
|
||||||
|
const entrySize = 16
|
||||||
|
dataOffset := uint32(headerSize + entrySize)
|
||||||
|
|
||||||
|
ico := make([]byte, 0, headerSize+entrySize+len(pngData))
|
||||||
|
|
||||||
|
// ICONDIR
|
||||||
|
ico = binary.LittleEndian.AppendUint16(ico, 0) // reserved
|
||||||
|
ico = binary.LittleEndian.AppendUint16(ico, 1) // type = icon
|
||||||
|
ico = binary.LittleEndian.AppendUint16(ico, 1) // count = 1 image
|
||||||
|
|
||||||
|
// ICONDIRENTRY
|
||||||
|
ico = append(ico, 0) // width (0 = 256+, actual size in PNG header)
|
||||||
|
ico = append(ico, 0) // height (0 = 256+, actual size in PNG header)
|
||||||
|
ico = append(ico, 0) // color count (0 = ≥256 colors)
|
||||||
|
ico = append(ico, 0) // reserved
|
||||||
|
ico = binary.LittleEndian.AppendUint16(ico, 1) // planes
|
||||||
|
ico = binary.LittleEndian.AppendUint16(ico, 32) // bit count
|
||||||
|
ico = binary.LittleEndian.AppendUint32(ico, uint32(len(pngData)))
|
||||||
|
ico = binary.LittleEndian.AppendUint32(ico, dataOffset)
|
||||||
|
|
||||||
|
// PNG image data
|
||||||
|
ico = append(ico, pngData...)
|
||||||
|
|
||||||
|
if err := os.WriteFile("resources/icon.ico", ico, 0644); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "genico: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println("Generated resources/icon.ico")
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
LMVPN ICON "resources/icon.ico"
|
||||||
Reference in New Issue
Block a user