5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 03:20:09 +08:00

[windows-x] Use winres for processing manifest + icon

This commit is contained in:
Lea Anthony 2021-08-15 20:16:14 +10:00
parent 1d6cce7c52
commit 3ac1dcc8d9
7 changed files with 87 additions and 36 deletions

View File

@ -25,11 +25,11 @@ require (
github.com/leaanthony/webview2runtime v1.1.0
github.com/leaanthony/winicon v0.0.0-20200606125418-4419cea822a0
github.com/matryer/is v1.4.0
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0 // indirect
github.com/tadvi/winc v0.0.0-20190405175627-5454f291903d
github.com/tc-hib/winres v0.1.5
github.com/tdewolff/minify v2.3.6+incompatible
github.com/tdewolff/parse v2.3.4+incompatible // indirect
github.com/tdewolff/test v1.0.6 // indirect

View File

@ -145,6 +145,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tc-hib/winres v0.1.5 h1:2dA5yfjdoEA3UyRaOC92HNMt3jap66pLzoW4MjpC/0M=
github.com/tc-hib/winres v0.1.5/go.mod h1:pe6dOR40VOrGz8PkzreVKNvEKnlE8t4yR8A8naL+t7A=
github.com/tdewolff/minify v2.3.6+incompatible h1:2hw5/9ZvxhWLvBUnHE06gElGYz+Jv9R4Eys0XUzItYo=
github.com/tdewolff/minify v2.3.6+incompatible/go.mod h1:9Ov578KJUmAWpS6NeZwRZyT56Uf6o3Mcz9CEsg8USYs=
github.com/tdewolff/parse v2.3.4+incompatible h1:x05/cnGwIMf4ceLuDMBOdQ1qGniMoxpP46ghf0Qzh38=
@ -181,8 +183,9 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 h1:nfeHNc1nAqecKCy2FCy4HY+soOOe5sDLJ/gZLbx6GYI=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=

View File

@ -13,7 +13,7 @@ import {EventsEmit, EventsNotify, EventsOff, EventsOn, EventsOnce, EventsOnMulti
import {Callback} from './calls';
import {SetBindings} from "./bindings";
// import {AddScript, DisableDefaultContextMenu, InjectCSS} from './utils';
// import {AddIPCListener, SendMessage} from 'ipc';
import {SendMessage} from './ipc';
// Backend is where the Go struct wrappers get bound to
window.backend = {};
@ -29,18 +29,26 @@ window.runtime = {
// Initialise global if not already
window.wails = {
Callback,
EventsNotify,
SetBindings,
// AddScript,
// InjectCSS,
// DisableDefaultContextMenu,
// // Init,
// AddIPCListener,
// SystemCall,
// SendMessage,
Callback,
EventsNotify,
SetBindings,
};
window.wails.SetBindings(window.wailsbindings);
delete window.wails['SetBindings'];
delete window['wailsbindings'];
// Setup drag handler
// Based on code from: https://github.com/patr0nus/DeskGap
window.addEventListener('mousedown', (e) => {
let currentElement = e.target;
while (currentElement != null) {
if (currentElement.hasAttribute('data-wails-no-drag')) {
break;
} else if (currentElement.hasAttribute('data-wails-drag')) {
SendMessage("drag");
break;
}
currentElement = currentElement.parentElement;
}
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -1,2 +0,0 @@
100 ICON "app.ico"
110 24 "{{.Name}}.exe.manifest"

View File

@ -3,6 +3,7 @@
package build
import (
"github.com/leaanthony/slicer"
"github.com/wailsapp/wails/v2/internal/ffenestri/windows/x64"
"os"
"path/filepath"
@ -11,6 +12,10 @@ import (
// PostCompilation is called after the compilation step, if successful
func (d *DesktopBuilder) PostCompilation(options *Options) error {
// Dump the DLLs
userTags := slicer.String(options.UserTags)
if userTags.Contains("experimental") {
return nil
}
err := os.WriteFile(filepath.Join(options.BuildDirectory, "WebView2Loader.dll"), x64.WebView2Loader, 0755)
if err != nil {
return err

View File

@ -3,8 +3,8 @@ package build
import (
"fmt"
"github.com/leaanthony/winicon"
"github.com/tc-hib/winres"
"github.com/wailsapp/wails/v2/internal/fs"
"github.com/wailsapp/wails/v2/internal/shell"
"github.com/wailsapp/wails/v2/pkg/buildassets"
"os"
"path/filepath"
@ -18,12 +18,6 @@ func packageApplication(options *Options) error {
return err
}
// Ensure RC file is present
err = generateRCFile(options)
if err != nil {
return err
}
// Ensure Manifest is present
err = generateManifest(options)
if err != nil {
@ -48,18 +42,9 @@ func generateManifest(options *Options) error {
return nil
}
func generateRCFile(options *Options) error {
filename := options.ProjectData.Name + ".rc"
rcFile := filepath.Join(options.ProjectData.Path, "build", "windows", filename)
if !fs.FileExists(rcFile) {
return buildassets.RegenerateRCFile(options.ProjectData.Path, options.ProjectData.Name)
}
return nil
}
func generateIcoFile(options *Options) error {
// Check ico file exists already
icoFile := filepath.Join(options.ProjectData.Path, "build", "windows", "app.ico")
icoFile := filepath.Join(options.ProjectData.Path, "build", "windows", "icon.ico")
if !fs.FileExists(icoFile) {
// Check icon exists
appicon := filepath.Join(options.ProjectData.Path, "build", "appicon.png")
@ -84,9 +69,61 @@ func generateIcoFile(options *Options) error {
}
func compileResources(options *Options) error {
windowsBuildDir := filepath.Join(options.ProjectData.Path, "build", "windows")
sourcefile := filepath.Join(options.ProjectData.BuildDir, "windows", options.ProjectData.Name+".rc")
currentDir, err := os.Getwd()
if err != nil {
return err
}
defer func() {
os.Chdir(currentDir)
}()
windowsDir := filepath.Join(options.ProjectData.Path, "build", "windows")
err = os.Chdir(windowsDir)
if err != nil {
return err
}
rs := winres.ResourceSet{}
icon := filepath.Join(windowsDir, "icon.ico")
iconFile, err := os.Open(icon)
if err != nil {
return err
}
defer iconFile.Close()
ico, err := winres.LoadICO(iconFile)
if err != nil {
return err
}
err = rs.SetIcon(winres.RT_ICON, ico)
if err != nil {
return err
}
ManifestFilename := options.ProjectData.Name + ".exe.manifest"
manifestData, err := os.ReadFile(ManifestFilename)
xmlData, err := winres.AppManifestFromXML(manifestData)
if err != nil {
return err
}
rs.SetManifest(xmlData)
targetFile := filepath.Join(options.ProjectData.Path, options.ProjectData.Name+"-res.syso")
_, _, err := shell.RunCommand(windowsBuildDir, "windres", "-o", targetFile, sourcefile)
return err
fout, err := os.Create(targetFile)
if err != nil {
return err
}
defer fout.Close()
archs := map[string]winres.Arch{
"amd64": winres.ArchAMD64,
}
targetArch, supported := archs[options.Arch]
if !supported {
return fmt.Errorf("arch '%s' not supported", options.Arch)
}
err = rs.WriteObject(fout, targetArch)
if err != nil {
return err
}
return nil
}