-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dexc-desktop: Windows builder, installer (#2635)
* dexc-desktop: set the window icon This sets the window icon, which is different from either the tray icon or any icon embedded in the binary such as the windows ICOs. On Linxu, this uses gtk_window_set_icon to set the icon from one of the embedded (in-memory) images so it does not need the file on disk. On Windows, it applies the icon in a resource. This also changes to os-specific systray icons since Windows in particular needs these to be ico files, not pngs. This also adds Windows syso resource files for dexc-desktop, as is already done for dexc with -systray builds. On Windows, these resources are also used to set the window's icon with LoadImage specifying the window's handle and resource name instead of a file name. --------- Co-authored-by: Jonathan Chappelow <chappjc@protonmail.com>
- Loading branch information
Showing
32 changed files
with
709 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vscode/ | ||
.vs/ | ||
*.exe | ||
*.log | ||
*.log.*.gz | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
build/ | ||
pkg/installers | ||
certs/ | ||
pkg/windows-msi/bin | ||
pkg/windows-msi/obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// This code is available on the terms of the project LICENSE.md file, | ||
// also available online at https://blueoakcouncil.org/license/1.0.0. | ||
|
||
//go:generate go run github.com/tc-hib/go-winres@v0.3.1 make --in winres.json --arch "386,amd64" | ||
|
||
package main | ||
|
||
// After generating the rsrc_windows_amd64.syso file, it will be included in the | ||
// binary when making an amd64 build for windows. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This code is available on the terms of the project LICENSE.md file, | ||
// also available online at https://blueoakcouncil.org/license/1.0.0. | ||
|
||
//go:build !linux && !windows && !darwin | ||
|
||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"github.com/webview/webview" | ||
) | ||
|
||
//go:embed src/dexc.png | ||
var FavIcon []byte | ||
|
||
//go:embed src/symbol-bw-round.png | ||
var SymbolBWIcon []byte | ||
|
||
func useIcon(w webview.WebView, iconPath string) { /* not supported on this platform */ } | ||
|
||
func useIconBytes(w webview.WebView, iconBytes []byte) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// This code is available on the terms of the project LICENSE.md file, | ||
// also available online at https://blueoakcouncil.org/license/1.0.0. | ||
|
||
//go:build darwin | ||
|
||
package main | ||
|
||
import ( | ||
_ "embed" | ||
) | ||
|
||
//go:embed src/dexc.png | ||
var FavIcon []byte | ||
|
||
//go:embed src/symbol-bw-round.png | ||
var SymbolBWIcon []byte | ||
|
||
// On Darwin, we instead use macdriver (not webview) and | ||
// obj.Button().SetImage(cocoa.NSImage_InitWithData. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// This code is available on the terms of the project LICENSE.md file, | ||
// also available online at https://blueoakcouncil.org/license/1.0.0. | ||
|
||
//go:build linux | ||
|
||
package main | ||
|
||
// https://docs.gtk.org/gtk3/method.Window.set_icon_from_file.html | ||
|
||
/* | ||
#cgo linux pkg-config: gtk+-3.0 | ||
#include <stdlib.h> | ||
#include <gtk/gtk.h> | ||
void use_icon_file(void *hwnd, char* iconPathC) { | ||
gtk_window_set_icon_from_file(hwnd, iconPathC, NULL); | ||
} | ||
void use_icon_bytes(void *hwnd, void* iconBytes, gsize len) { | ||
GdkPixbufLoader* loader = gdk_pixbuf_loader_new(); | ||
gdk_pixbuf_loader_write(loader, (guchar *)(iconBytes), len, NULL); | ||
gdk_pixbuf_loader_close(loader, NULL); | ||
GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); | ||
gtk_window_set_icon(hwnd, pixbuf); | ||
g_object_unref(loader); | ||
} | ||
*/ | ||
import "C" | ||
import ( | ||
_ "embed" | ||
"unsafe" | ||
|
||
"github.com/webview/webview" | ||
) | ||
|
||
//go:embed src/dexc.png | ||
var FavIcon []byte | ||
|
||
//go:embed src/symbol-bw-round.png | ||
var SymbolBWIcon []byte | ||
|
||
func useIcon(w webview.WebView, iconPath string) { | ||
iconPathC := C.CString(iconPath) | ||
defer C.free(unsafe.Pointer(iconPathC)) | ||
|
||
C.use_icon_file(w.Window(), iconPathC) | ||
} | ||
|
||
func useIconBytes(w webview.WebView, iconBytes []byte) { | ||
C.use_icon_bytes(w.Window(), unsafe.Pointer(&iconBytes[0]), C.gsize(len(iconBytes))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// This code is available on the terms of the project LICENSE.md file, | ||
// also available online at https://blueoakcouncil.org/license/1.0.0. | ||
|
||
//go:build windows | ||
|
||
package main | ||
|
||
/* | ||
// This set_external_icon/set_resource_icon C implementation is originally from | ||
// a proposed webview example: | ||
// https://github.com/ldstein/webview/blob/2d7b6d32f5408b4a5e430711137aacd0a3791088/examples/icon-switching/main_windows.go | ||
#include <windows.h> | ||
void use_icon_file(const void *ptr, char* iconPath) { | ||
HICON iconBig = LoadImage(NULL, iconPath, IMAGE_ICON, GetSystemMetrics(SM_CXICON ), GetSystemMetrics(SM_CXICON ), LR_LOADFROMFILE); | ||
HICON iconSml = LoadImage(NULL, iconPath, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CXSMICON), LR_LOADFROMFILE); | ||
if (iconSml) SendMessage((HWND)ptr, WM_SETICON, ICON_SMALL, (LPARAM)iconSml); | ||
if (iconBig) SendMessage((HWND)ptr, WM_SETICON, ICON_BIG , (LPARAM)iconBig); | ||
} | ||
void use_icon_from_resource(const void *ptr, char* name) { | ||
HINSTANCE hInstance = GetModuleHandle(NULL); | ||
HICON iconBig = (HICON)LoadImage(hInstance, name, IMAGE_ICON, GetSystemMetrics(SM_CXICON ), GetSystemMetrics(SM_CXICON ), LR_DEFAULTCOLOR); | ||
HICON iconSml = (HICON)LoadImage(hInstance, name, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); | ||
if (iconSml) SendMessage((HWND)ptr, WM_SETICON, ICON_SMALL, (LPARAM)iconSml); | ||
if (iconBig) SendMessage((HWND)ptr, WM_SETICON, ICON_BIG , (LPARAM)iconBig); | ||
} | ||
*/ | ||
import "C" | ||
import ( | ||
_ "embed" | ||
"os" | ||
"strings" | ||
"unsafe" | ||
|
||
"github.com/webview/webview" | ||
) | ||
|
||
//go:embed src/logo_icon_v1.ico | ||
var FavIcon []byte | ||
|
||
//go:embed src/symbol-bw.ico | ||
var SymbolBWIcon []byte | ||
|
||
func fileExists(name string) bool { | ||
_, err := os.Stat(name) | ||
return !os.IsNotExist(err) | ||
} | ||
|
||
func useIcon(w webview.WebView, iconPath string) { | ||
iconPathC := C.CString(iconPath) | ||
defer C.free(unsafe.Pointer(iconPathC)) | ||
|
||
if strings.HasPrefix(iconPath, "#") || !fileExists(iconPath) { // numbered or named resource in winres.json | ||
C.use_icon_from_resource(w.Window(), iconPathC) | ||
} else { | ||
C.use_icon_file(w.Window(), iconPathC) | ||
} | ||
} | ||
|
||
func useIconBytes(w webview.WebView, iconBytes []byte) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## Windows build | ||
|
||
### Setting up the build environment | ||
|
||
This build setup is expected to be run on a freshly installed system (e.g. in a VM), which is the best practice for building binaries for release on Windows, therefore there are no prerequisites. The setup script will install all components of the toolchain, dependencies and SDKs required to build the `dexc-desktop` binary and the MSI (MS installer), there is no need to install anything manually before running this (it can actually cause issues if different versions of the dependencies are already on the system). The builder was tested on Windows 10, Windows 11 and server equivalents, 2019/2022. | ||
|
||
Download and run setup as Administrator (privileges are required in order to set environment variables). Open a command prompt as Administrator, and run: | ||
|
||
```batch | ||
cd %UserProfile% | ||
curl -O https://raw.githubusercontent.com/decred/dcrdex/master/client/cmd/dexc-desktop/pkg/setup-windows.cmd | ||
setup-windows.cmd <branch> <repoUrl> | ||
``` | ||
|
||
Both `branch` and `repoUrl` are optional. If not specified, it will clone the `master` branch in the default [dcrdex repository](https://github.com/decred/dcrdex). | ||
|
||
This will download and install `git` and `PowerShell`, clone the repo and install the build toolchain and required SDKs for the build. Once completed, close the above command prompt, open a new prompt in order to effectuate `PATH` and other environment variables configured by the setup script. Administrator privileges are NOT required for the rest of the steps. | ||
|
||
### Running the build | ||
|
||
```batch | ||
cd dcrdex\client\cmd\dexc-desktop | ||
``` | ||
|
||
Build the Windows binary: | ||
|
||
```batch | ||
pkg\build-windows.cmd | ||
``` | ||
|
||
This will also build the site bundle if `client/webserver/site/dist` does not exist. | ||
|
||
The resulting `.exe` will be in `build\windows`. | ||
|
||
### Build the MSI (Windows Installer) | ||
|
||
```batch | ||
pkg\pkg-windows.cmd | ||
``` | ||
|
||
The resulting installer binary will be located in `build\msi`. |
Oops, something went wrong.