From beb9519e037c613f7078396ed0001cb40bcf6121 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 24 Apr 2019 17:10:05 +0200 Subject: Revert "ui: introduce system icon loading" This reverts commit 8d29c7136535524e387091a7387a33a243062f2b. Signed-off-by: Jason A. Donenfeld --- ui/systemimageprovider.go | 78 ----------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 ui/systemimageprovider.go (limited to 'ui/systemimageprovider.go') 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 -} -- cgit v1.2.3-59-g8ed1b