aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-04-24 17:10:05 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-04-24 17:10:05 +0200
commitbeb9519e037c613f7078396ed0001cb40bcf6121 (patch)
tree87018522ea5c3a623ee2bbba5cd82bd144f29955 /ui
parentui: introduce system icon loading (diff)
downloadwireguard-windows-beb9519e037c613f7078396ed0001cb40bcf6121.tar.xz
wireguard-windows-beb9519e037c613f7078396ed0001cb40bcf6121.zip
Revert "ui: introduce system icon loading"
This reverts commit 8d29c7136535524e387091a7387a33a243062f2b. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--ui/systemimageprovider.go78
-rw-r--r--ui/tunnelspage.go13
-rw-r--r--ui/ui.go5
3 files changed, 4 insertions, 92 deletions
diff --git a/ui/systemimageprovider.go b/ui/systemimageprovider.go
deleted file mode 100644
index 26764ccc..00000000
--- a/ui/systemimageprovider.go
+++ /dev/null
@@ -1,78 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
- */
-
-package ui
-
-import (
- "fmt"
- "path"
-
- "github.com/lxn/walk"
- "github.com/lxn/win"
- "golang.org/x/sys/windows"
-)
-
-var (
- systemIconAddTunnel,
- systemIconAddTunnelFromScratch,
- systemIconAddTunnelFromFile,
- systemIconDeleteTunnel,
- systemIconExportTunnels,
- systemIconSaveTunnelsToZip,
- _ *walk.Icon
-)
-
-func loadSystemIcon(dll string, index uint) (*walk.Icon, error) {
- system32, err := windows.GetSystemDirectory()
- if err != nil {
- return nil, err
- }
- hicon := win.ExtractIcon(win.GetModuleHandle(nil), windows.StringToUTF16Ptr(path.Join(system32, dll+".dll")), int32(index))
- if hicon <= 1 {
- return nil, fmt.Errorf("Unable to find icon %d of %s", index, dll)
- }
- return walk.NewIconFromHICON(hicon)
-}
-
-func setIconOnAction(wb *walk.WindowBase, action *walk.Action, icon *walk.Icon) error {
- //TODO: this is an unholy hack. Fix walk!
- bitmap, err := walk.NewBitmapFromIcon(icon, walk.Size{32, 32})
- if err != nil {
- return err
- }
- wb.AddDisposable(bitmap)
- return action.SetImage(bitmap)
-}
-
-func loadSystemIcons() (err error) {
- //TODO: this should probably be in an object that is disposable instead of using globals like this
-
- systemIconAddTunnel, err = loadSystemIcon("shell32", 149)
- if err != nil {
- return
- }
- systemIconAddTunnelFromScratch, err = loadSystemIcon("imageres", 2)
- if err != nil {
- return
- }
- systemIconAddTunnelFromFile, err = loadSystemIcon("imageres", 3)
- if err != nil {
- return
- }
- systemIconDeleteTunnel, err = loadSystemIcon("shell32", 131)
- if err != nil {
- return
- }
- systemIconExportTunnels, err = loadSystemIcon("shell32", 45)
- if err != nil {
- return
- }
- systemIconSaveTunnelsToZip, err = loadSystemIcon("imageres", 165)
- if err != nil {
- return
- }
-
- return
-}
diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go
index 48a25425..ac778b3a 100644
--- a/ui/tunnelspage.go
+++ b/ui/tunnelspage.go
@@ -58,23 +58,18 @@ func NewTunnelsPage() (*TunnelsPage, error) {
toolBarContainer, _ := walk.NewComposite(tunnelsContainer)
toolBarContainer.SetLayout(walk.NewHBoxLayout())
- tunnelsToolBar, _ := walk.NewToolBarWithOrientationAndButtonStyle(toolBarContainer, walk.Horizontal, walk.ToolBarButtonImageOnly)
- imageList, _ := walk.NewImageList(walk.Size{32, 32}, 0)
- tunnelsToolBar.SetImageList(imageList)
+ tunnelsToolBar, _ := walk.NewToolBarWithOrientationAndButtonStyle(toolBarContainer, walk.Horizontal, walk.ToolBarButtonTextOnly)
importAction := walk.NewAction()
importAction.SetText("Import tunnels from file...")
- setIconOnAction(tp.AsWindowBase(), importAction, systemIconAddTunnelFromFile)
importAction.Triggered().Attach(tp.onImport)
addAction := walk.NewAction()
addAction.SetText("Add empty tunnel")
- setIconOnAction(tp.AsWindowBase(), addAction, systemIconAddTunnelFromScratch)
addAction.Triggered().Attach(tp.onAddTunnel)
exportTunnelsAction := walk.NewAction()
exportTunnelsAction.SetText("Export tunnels to zip...")
- setIconOnAction(tp.AsWindowBase(), exportTunnelsAction, systemIconSaveTunnelsToZip)
exportTunnelsAction.Triggered().Attach(tp.onExportTunnels)
addMenu, _ := walk.NewMenu()
@@ -82,18 +77,18 @@ func NewTunnelsPage() (*TunnelsPage, error) {
addMenu.Actions().Add(addAction)
addMenu.Actions().Add(importAction)
addMenuAction, _ := tunnelsToolBar.Actions().AddMenu(addMenu)
- setIconOnAction(tp.AsWindowBase(), addMenuAction, systemIconAddTunnel)
+ addMenuAction.SetText("➕")
deleteAction := walk.NewAction()
tunnelsToolBar.Actions().Add(deleteAction)
- setIconOnAction(tp.AsWindowBase(), deleteAction, systemIconDeleteTunnel)
+ deleteAction.SetText("➖")
deleteAction.Triggered().Attach(tp.onDelete)
settingsMenu, _ := walk.NewMenu()
tp.AddDisposable(settingsMenu)
settingsMenu.Actions().Add(exportTunnelsAction)
settingsMenuAction, _ := tunnelsToolBar.Actions().AddMenu(settingsMenu)
- setIconOnAction(tp.AsWindowBase(), settingsMenuAction, systemIconExportTunnels)
+ settingsMenuAction.SetText("⚙")
}
currentTunnelContainer, _ := walk.NewComposite(tp)
diff --git a/ui/ui.go b/ui/ui.go
index 9e0b01cc..58b52e46 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -36,11 +36,6 @@ func RunUI() {
}
defer icon.Dispose()
- err = loadSystemIcons() //TODO: Load these the proper way and make dispose and be more like tunnelstatusimageprovider.
- if err != nil {
- panic(err)
- }
-
mtw, err := NewManageTunnelsWindow(icon, logger)
if err != nil {
panic(err)