add icon, fix bug in dark theme

This commit is contained in:
olebeck 2023-03-15 14:51:31 +01:00
parent 04293a74c5
commit 3c87663d02
9 changed files with 173 additions and 109 deletions

View File

@ -47,7 +47,10 @@ jobs:
env:
REPO_KEY: ${{ secrets.REPO_KEY }}
- run: go get ./cmd/bedrocktool
- name: dependencies
run: |
go get ./cmd/bedrocktool
go install gioui.org/cmd/gogio@latest
- name: build
id: build

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ token.json
*.bmp
*.bin
*.log
*.syso
/bedrocktool
/bedrocktool-*

204
build.py
View File

@ -16,12 +16,10 @@ print(f"VER: {VER}")
print(f"TAG: {TAG}")
GITHUB_OUTPUT = os.getenv("GITHUB_OUTPUT")
if GITHUB_OUTPUT:
with open(GITHUB_OUTPUT, "a") as f:
f.write(f"release_tag=r{VER}\n")
with open("./subcommands/resourcepack-d/resourcepack-d.go", "rb") as f:
PACK_SUPPORT = f.read(100).count(b"package ") > 0
print(f"Pack Support: {PACK_SUPPORT}")
@ -35,91 +33,149 @@ PLATFORMS = [
#("android", ["arm64"], ".apk")
]
platform_filter = ""
arch_filter = ""
if len(sys.argv) > 1:
platform_filter = sys.argv[1]
if len(sys.argv) > 2:
arch_filter = sys.argv[2]
def clean():
if os.path.exists("./tmp"):
shutil.rmtree("./tmp")
if os.path.exists("./builds"):
shutil.rmtree("./builds")
if os.path.exists("./updates"):
shutil.rmtree("./updates")
for file in os.listdir("./cmd/bedrocktool"):
if file.endswith(".syso"):
os.remove(f"./cmd/bedrocktool/{file}")
if os.path.exists("./tmp"):
shutil.rmtree("./tmp")
os.mkdir("./tmp")
def make_dirs():
os.mkdir("./tmp")
os.mkdir("./builds")
os.mkdir("./updates")
if os.path.exists("./builds"):
shutil.rmtree("./builds")
os.mkdir("./builds")
if os.path.exists("./updates"):
shutil.rmtree("./updates")
os.mkdir("./updates")
def build_cli(platform: str, arch: str, env_in: dict[str,str], tags: list[str], compiled_path: str):
env = {}
env.update(env_in)
env.update({
"GOOS": platform,
"GOARCH": arch,
})
args = [
"go", "build",
"-ldflags", LDFLAGS,
"-trimpath",
"-tags", ",".join(tags),
"-o", compiled_path,
"-v"
]
args.append("./cmd/bedrocktool")
for (platform_name, archs, ext) in PLATFORMS:
if platform_filter and platform_filter != platform_name:
continue
archs = [a for a in archs if arch_filter == "" or a == arch_filter]
if len(archs) == 0:
continue
for GUI in [False, True]:
if platform_name in ["android"] and not GUI:
env2 = os.environ.copy()
env2.update(env)
subprocess.run(args, env=env2).check_returncode()
def build_gui(platform: str, arch: str, env, tags: list[str], compiled_path: str):
ldflags = LDFLAGS
if platform == "windows":
ldflags = "-H=windows " + ldflags
args = [
"gogio",
"-arch", arch,
"-target", platform,
"-icon", "icon.png",
"-tags", ",".join(tags),
"-ldflags", ldflags,
"-o", compiled_path,
"-x"
]
if platform in ["android", "ios"]:
args.extend(["-appid", APP_ID])
args.append("./cmd/bedrocktool")
env2 = os.environ.copy()
env2.update(env)
subprocess.run(args, env=env2).check_returncode()
def package(platform: str, arch: str, compiled_path: str, GUI: bool, ext: str):
SUB1 = '-gui' if GUI else ''
exe_out_path = f"./builds/{NAME}-{platform}-{arch}-{TAG}{SUB1}{ext}"
# create hash and copy
with open(compiled_path, "rb") as f:
exe_data = f.read()
sha = binascii.b2a_base64(hashlib.sha256(exe_data).digest()).decode("utf8").split("\n")[0]
shutil.copy(compiled_path, exe_out_path)
# create update
updates_dir = f"./updates/{NAME}{SUB1}"
os.makedirs(updates_dir, exist_ok=True)
with open(f"{updates_dir}/{platform}-{arch}.json", "w") as f:
f.write(json.dumps({
"Version": TAG,
"Sha256": sha,
}, indent=2))
# write update data
os.makedirs(f"{updates_dir}/{TAG}", exist_ok=True)
with gzip.open(f"{updates_dir}/{TAG}/{platform}-{arch}.gz", "wb") as f:
f.write(exe_data)
os.remove(compiled_path)
def build_all(platform_filter: str, arch_filter: str):
for (platform, archs, ext) in PLATFORMS:
if platform_filter and platform_filter != platform:
continue
archs = [a for a in archs if arch_filter == "" or a == arch_filter]
if len(archs) == 0:
continue
for GUI in [False, True]:
if platform in ["android"] and not GUI:
continue
print(f"Building {platform_name} gui: {GUI}")
SUB1 = '-gui' if GUI else ''
name = f"{NAME}{SUB1}"
print(f"Building {platform} gui: {GUI}")
SUB1 = '-gui' if GUI else ''
name = f"{NAME}{SUB1}"
tags = []
if PACK_SUPPORT:
tags.append("packs")
if GUI:
tags.append("gui")
tags = []
if PACK_SUPPORT:
tags.append("packs")
if GUI:
tags.append("gui")
env = {
"GOVCS": "*:off"
}
env = {
"GOVCS": "*:off"
}
for arch in archs:
compiled_path = f"./tmp/{platform_name}-{arch}{SUB1}/{name}{ext}"
os.makedirs(os.path.dirname(compiled_path), exist_ok=True)
env.update({
"GOOS": platform_name,
"GOARCH": arch,
})
args = [
"go", "build",
"-ldflags", LDFLAGS,
"-trimpath",
"-tags", ",".join(tags),
"-v",
"-o", compiled_path,
]
args.append("./cmd/bedrocktool")
print(args)
for arch in archs:
compiled_path = f"./tmp/{platform}-{arch}{SUB1}/{name}{ext}"
os.makedirs(os.path.dirname(compiled_path), exist_ok=True)
env2 = os.environ.copy()
env2.update(env)
if GUI and platform != "linux":
build_gui(platform, arch, env, tags, compiled_path)
else:
build_cli(platform, arch, env, tags, compiled_path)
package(platform, arch, compiled_path, GUI, ext)
out = subprocess.run(args, env=env2)
out.check_returncode()
exe_out_path = f"./builds/{NAME}-{platform_name}-{arch}-{TAG}{SUB1}{ext}"
def main():
platform_filter = ""
arch_filter = ""
if len(sys.argv) > 1:
platform_filter = sys.argv[1]
with open(compiled_path, "rb") as f:
exe_data = f.read()
sha = binascii.b2a_base64(hashlib.sha256(exe_data).digest()).decode("utf8").split("\n")[0]
shutil.copy(compiled_path, exe_out_path)
if len(sys.argv) > 2:
arch_filter = sys.argv[2]
if platform_filter == "clean":
clean()
return
updates_dir = f"./updates/{NAME}{SUB1}"
os.makedirs(updates_dir, exist_ok=True)
with open(f"{updates_dir}/{platform_name}-{arch}.json", "w") as f:
f.write(json.dumps({
"Version": TAG,
"Sha256": sha,
}, indent=2))
os.makedirs(f"{updates_dir}/{TAG}", exist_ok=True)
with gzip.open(f"{updates_dir}/{TAG}/{platform_name}-{arch}.gz", "wb") as f:
f.write(exe_data)
clean()
make_dirs()
build_all(platform_filter, arch_filter)
os.remove(compiled_path)
main()

1
go.mod
View File

@ -39,6 +39,7 @@ require (
require (
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect
gioui.org/shader v1.0.6 // indirect
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 // indirect
github.com/benoitkugler/textlayout v0.3.0 // indirect
github.com/brentp/intintmap v0.0.0-20190211203843-30dc0ade9af9 // indirect
github.com/changkun/lockfree v0.0.1 // indirect

2
go.sum
View File

@ -8,6 +8,8 @@ gioui.org/shader v1.0.6 h1:cvZmU+eODFR2545X+/8XucgZdTtEjR3QWW6W65b0q5Y=
gioui.org/shader v1.0.6/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
gioui.org/x v0.0.0-20230313161557-05b40af72ed0 h1:jjdcmnjM8R1yhiBBbPinm5TLNs6uRei25fjnvgYBTjU=
gioui.org/x v0.0.0-20230313161557-05b40af72ed0/go.mod h1:kmHRtak7XgGZYYuqFgDBJ42PbQjPrV/xOpw9FLx3eVY=
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 h1:bGG/g4ypjrCJoSvFrP5hafr9PPB5aw8SjcOWWila7ZI=
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0/go.mod h1:+axXBRUTIDlCeE73IKeD/os7LoEnTKdkp8/gQOFjqyo=
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/benoitkugler/pstokenizer v1.0.0/go.mod h1:l1G2Voirz0q/jj0TQfabNxVsa8HZXh/VMxFSRALWTiE=

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -32,6 +32,20 @@ func (g *GUI) Init() bool {
return true
}
var paletteLight = material.Palette{
Bg: color.NRGBA{0xff, 0xff, 0xff, 0xff},
Fg: color.NRGBA{0x12, 0x12, 0x12, 0xff},
ContrastBg: color.NRGBA{0x7c, 0x00, 0xf8, 0xff},
ContrastFg: color.NRGBA{0x00, 0x00, 0x00, 0xff},
}
var paletteDark = material.Palette{
Bg: color.NRGBA{0x12, 0x12, 0x12, 0xff},
Fg: color.NRGBA{0xff, 0xff, 0xff, 0xff},
ContrastBg: color.NRGBA{0x7c, 0x00, 0xf8, 0xff},
ContrastFg: color.NRGBA{0xff, 0xff, 0xff, 0xff},
}
func (g *GUI) Start(ctx context.Context, cancel context.CancelFunc) (err error) {
g.cancel = cancel
@ -39,7 +53,20 @@ func (g *GUI) Start(ctx context.Context, cancel context.CancelFunc) (err error)
app.Title("Bedrocktool"),
)
g.router = pages.NewRouter(ctx, w.Invalidate)
th := material.NewTheme(gofont.Collection())
dark, err := theme.IsDarkMode()
if err != nil {
logrus.Warn(err)
}
if dark {
_th := th.WithPalette(paletteDark)
th = &_th
} else {
_th := th.WithPalette(paletteLight)
th = &_th
}
g.router = pages.NewRouter(ctx, w.Invalidate, th)
g.router.Register("Settings", settings.New(&g.router))
g.router.Register("worlds", worlds.New(&g.router))
@ -59,34 +86,7 @@ func (g *GUI) Start(ctx context.Context, cancel context.CancelFunc) (err error)
return err
}
var paletteLight = material.Palette{
Bg: color.NRGBA{0xff, 0xff, 0xff, 0xff},
Fg: color.NRGBA{0x12, 0x12, 0x12, 0xff},
ContrastBg: color.NRGBA{0x7c, 0x00, 0xf8, 0xff},
ContrastFg: color.NRGBA{0x00, 0x00, 0x00, 0xff},
}
var paletteDark = material.Palette{
Bg: color.NRGBA{0x12, 0x12, 0x12, 0xff},
Fg: color.NRGBA{0xff, 0xff, 0xff, 0xff},
ContrastBg: color.NRGBA{0x7c, 0x00, 0xf8, 0xff},
ContrastFg: color.NRGBA{0xff, 0xff, 0xff, 0xff},
}
func (g *GUI) run(w *app.Window) error {
th := material.NewTheme(gofont.Collection())
dark, err := theme.IsDarkMode()
if err != nil {
logrus.Warn(err)
}
if dark {
_th := th.WithPalette(paletteDark)
th = &_th
} else {
_th := th.WithPalette(paletteLight)
th = &_th
}
var ops op.Ops
for {
select {
@ -96,7 +96,7 @@ func (g *GUI) run(w *app.Window) error {
return e.Err
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
g.router.Layout(gtx, th)
g.router.Layout(gtx, g.router.Theme)
e.Frame(gtx.Ops)
case *system.DestroyEvent:
g.cancel()

View File

@ -30,6 +30,8 @@ type Router struct {
Wg sync.WaitGroup
Invalidate func()
Theme *material.Theme
pages map[string]Page
current string
*component.ModalNavDrawer
@ -39,7 +41,7 @@ type Router struct {
NonModalDrawer, BottomBar bool
}
func NewRouter(ctx context.Context, invalidate func()) Router {
func NewRouter(ctx context.Context, invalidate func(), th *material.Theme) Router {
modal := component.NewModal()
nav := component.NewNav("Navigation Drawer", "This is an example.")
@ -55,6 +57,7 @@ func NewRouter(ctx context.Context, invalidate func()) Router {
return Router{
Ctx: ctx,
Invalidate: invalidate,
Theme: th,
pages: make(map[string]Page),
ModalLayer: modal,
ModalNavDrawer: modalNav,

View File

@ -3,7 +3,6 @@ package settings
import (
"image"
"gioui.org/font/gofont"
"gioui.org/layout"
"gioui.org/unit"
"gioui.org/widget"
@ -40,20 +39,19 @@ func New(router *pages.Router) *Page {
startButton: widget.Clickable{},
}
th := material.NewTheme(gofont.Collection())
options := make([]func(layout.Context) layout.Dimensions, 0, len(utils.ValidCMDs))
p.cmdMenu.items = make(map[string]*widget.Clickable, len(utils.ValidCMDs))
for k := range utils.ValidCMDs {
item := &widget.Clickable{}
p.cmdMenu.items[k] = item
options = append(options, component.MenuItem(th, item, k).Layout)
options = append(options, component.MenuItem(router.Theme, item, k).Layout)
}
p.cmdMenu.state = &component.MenuState{
OptionList: layout.List{},
Options: options,
}
p.cmdMenu.selected = "worlds"
for _, su := range settings.Settings {
su.Init()