mirror of
https://github.com/wavetermdev/wails.git
synced 2026-04-22 15:26:15 -07:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37b395c308 | |||
| 428584d583 | |||
| ee1978aa42 | |||
| 895d6d4b80 | |||
| a5ddce2c7c | |||
| e4789750c8 | |||
| f8c673874b |
@@ -250,6 +250,7 @@ func (cba *ControlBase) Size() (width, height int) {
|
||||
rect := w32.GetWindowRect(cba.hwnd)
|
||||
width = int(rect.Right - rect.Left)
|
||||
height = int(rect.Bottom - rect.Top)
|
||||
width, height = cba.scaleToDefaultDPI(width, height)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -498,6 +499,14 @@ func (cba *ControlBase) scaleWithWindowDPI(width, height int) (int, int) {
|
||||
return scaledWidth, scaledHeight
|
||||
}
|
||||
|
||||
func (cba *ControlBase) scaleToDefaultDPI(width, height int) (int, int) {
|
||||
dpix, dpiy := cba.GetWindowDPI()
|
||||
scaledWidth := ScaleToDefaultDPI(width, dpix)
|
||||
scaledHeight := ScaleToDefaultDPI(height, dpiy)
|
||||
|
||||
return scaledWidth, scaledHeight
|
||||
}
|
||||
|
||||
func (cba *ControlBase) tryInvokeOnCurrentGoRoutine(f func()) bool {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
@@ -149,3 +149,8 @@ func ScreenToClientRect(hwnd w32.HWND, rect *w32.RECT) *Rect {
|
||||
func ScaleWithDPI(pixels int, dpi uint) int {
|
||||
return (pixels * int(dpi)) / 96
|
||||
}
|
||||
|
||||
// ScaleToDefaultDPI scales the pixels from scaled DPI-Space to default DPI-Space (96).
|
||||
func ScaleToDefaultDPI(pixels int, dpi uint) int {
|
||||
return (pixels * 96) / int(dpi)
|
||||
}
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# TODO
|
||||
|
||||
Informal and incomplete list of things needed in v3.
|
||||
|
||||
## General
|
||||
|
||||
- [ ] Generate Bindings
|
||||
- [ ] Generate TS Models
|
||||
- [ ] Port NSIS creation
|
||||
- [ ] Dev Mode
|
||||
- [ ] Generate Info.Plist from `info.json`
|
||||
|
||||
- [ ] Windows Port
|
||||
- [ ] Linux Port
|
||||
|
||||
## Runtime
|
||||
|
||||
- [ ] Pass window ID with runtime calls in JS
|
||||
- [ ] Implement alias for `window` in JS
|
||||
- [ ] Implement runtime dispatcher
|
||||
|
||||
## Templates
|
||||
|
||||
- [ ] Create plain template
|
||||
- [ ] Improve default template
|
||||
|
||||
## Runtime
|
||||
|
||||
- [ ] To log or not to log?
|
||||
- [ ] Unify cross-platform events, eg. `onClose`
|
||||
@@ -134,3 +134,87 @@ tasks:
|
||||
- install-runtime-deps
|
||||
cmds:
|
||||
- task: build-runtime-all
|
||||
|
||||
recreate-template-dir:
|
||||
dir: internal/templates
|
||||
internal: true
|
||||
silent: true
|
||||
cmds:
|
||||
- rm -rf {{.TEMPLATE_DIR}}
|
||||
- mkdir -p {{.TEMPLATE_DIR}}
|
||||
|
||||
generate-template:
|
||||
dir: internal/templates/{{.TEMPLATE}}
|
||||
deps:
|
||||
- task: recreate-template-dir
|
||||
vars:
|
||||
TEMPLATE_DIR: "{{.TEMPLATE}}"
|
||||
silent: true
|
||||
cmds:
|
||||
- cmd: pnpm create vite frontend --template {{.TEMPLATE}}
|
||||
- cmd: cp -rf ../_base/{{.TEMPLATE}}/* .
|
||||
ignore_error: true
|
||||
- cmd: cp -rf ../_base/default/* .
|
||||
ignore_error: true
|
||||
- cmd: rm frontend/public/vite.svg
|
||||
- cmd: go run ../../../tasks/sed/sed.go replace -dir frontend -old Vite -new Wails -ext .ts,.js,.html -ignore vite.config.js,vite.config.ts,vite-env.d.ts
|
||||
- cmd: go run ../../../tasks/sed/sed.go replace -dir frontend -old vite -new wails -ext .ts,.js,.html -ignore vite.config.js,vite.config.ts,vite-env.d.ts
|
||||
- cmd: go run ../../../tasks/sed/sed.go replace -dir frontend -old wails.svg -new wails.png -ext .ts,.js,.html -ignore vite.config.js,vite.config.ts,vite-env.d.ts
|
||||
- cmd: go run ../../../tasks/sed/sed.go replace -dir frontend -old wailsjs.dev -new wails.io -ext .ts,.js,.html -ignore vite.config.js,vite.config.ts,vite-env.d.ts
|
||||
- cmd: go run ../../../tasks/sed/sed.go replace -dir frontend -old "framework powered by Wails" -new "framework powered by Vite" -ext .ts,.js,.html,.svelte -ignore vite.config.js,vite.config.ts,vite-env.d.ts
|
||||
|
||||
reinstall-cli:
|
||||
dir: cmd/wails
|
||||
internal: true
|
||||
cmds:
|
||||
- go install
|
||||
- echo "Reinstalled wails CLI"
|
||||
|
||||
generate-templates:
|
||||
dir: internal/templates/
|
||||
deps:
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: svelte
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: svelte-ts
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: vue
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: vue-ts
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: react
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: react-ts
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: preact
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: preact-ts
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: lit
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: lit-ts
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: vanilla
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: vanilla-ts
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: react-swc
|
||||
- task: generate-template
|
||||
vars:
|
||||
TEMPLATE: react-swc-ts
|
||||
cmds:
|
||||
- task: reinstall-cli
|
||||
- echo "Generated templates"
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
func main() {
|
||||
app := clir.NewCli("Wails", "The Wails CLI", "v3")
|
||||
app.NewSubCommandFunction("build", "Build the project", commands.Build)
|
||||
app.NewSubCommandFunction("init", "Initialise a new project", commands.Init)
|
||||
task := app.NewSubCommand("task", "Run and list tasks")
|
||||
task.NewSubCommandFunction("run", "Run a task", commands.RunTask)
|
||||
|
||||
@@ -20,10 +20,9 @@ tasks:
|
||||
|
||||
generate-icons:
|
||||
summary: Generates Windows `.ico` and Mac `.icns` files from an image
|
||||
dir: build
|
||||
cmds:
|
||||
# Generates both .ico and .icns files
|
||||
- wails generate icon -input appicon.png
|
||||
- wails generate icons -input appicon.png
|
||||
|
||||
build-prod:
|
||||
summary: Creates a production build of the application
|
||||
|
||||
@@ -6,6 +6,7 @@ require (
|
||||
github.com/go-task/task/v3 v3.20.0
|
||||
github.com/jackmordaunt/icns/v2 v2.2.1
|
||||
github.com/leaanthony/clir v1.5.0
|
||||
github.com/leaanthony/gosod v1.0.3
|
||||
github.com/leaanthony/winicon v1.0.0
|
||||
github.com/pterm/pterm v0.12.51
|
||||
github.com/samber/lo v1.37.0
|
||||
|
||||
@@ -49,6 +49,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/leaanthony/clir v1.0.4/go.mod h1:k/RBkdkFl18xkkACMCLt09bhiZnrGORoxmomeMvDpE0=
|
||||
github.com/leaanthony/clir v1.5.0 h1:zaH7fgsZ5OLfr0YwJBwQ+EYxCjXQsHF+CRudIiZb0KQ=
|
||||
github.com/leaanthony/clir v1.5.0/go.mod h1:k/RBkdkFl18xkkACMCLt09bhiZnrGORoxmomeMvDpE0=
|
||||
github.com/leaanthony/debme v1.2.1 h1:9Tgwf+kjcrbMQ4WnPcEIUcQuIZYqdWftzZkBr+i/oOc=
|
||||
github.com/leaanthony/debme v1.2.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
|
||||
github.com/leaanthony/gosod v1.0.3 h1:Fnt+/B6NjQOVuCWOKYRREZnjGyvg+mEhd1nkkA04aTQ=
|
||||
github.com/leaanthony/gosod v1.0.3/go.mod h1:BJ2J+oHsQIyIQpnLPjnqFGTMnOZXDbvWtRCSG7jGxs4=
|
||||
github.com/leaanthony/slicer v1.5.0 h1:aHYTN8xbCCLxJmkNKiLB6tgcMARl4eWmH9/F+S/0HtY=
|
||||
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
|
||||
github.com/leaanthony/winicon v1.0.0 h1:ZNt5U5dY71oEoKZ97UVwJRT4e+5xo5o/ieKuHuk8NqQ=
|
||||
@@ -56,6 +60,7 @@ github.com/leaanthony/winicon v1.0.0/go.mod h1:en5xhijl92aphrJdmRPlh4NI1L6wq3gEm
|
||||
github.com/lithammer/fuzzysearch v1.1.5 h1:Ag7aKU08wp0R9QCfF4GoGST9HbmAIeLP7xwMrOBEp1c=
|
||||
github.com/lithammer/fuzzysearch v1.1.5/go.mod h1:1R1LRNk7yKid1BaQkmuLQaHruxcC4HmAH30Dh61Ih1Q=
|
||||
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
|
||||
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
|
||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
|
||||
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
@@ -114,8 +119,6 @@ github.com/tc-hib/winres v0.1.6 h1:qgsYHze+BxQPEYilxIz/KCQGaClvI2+yLBAZs+3+0B8=
|
||||
github.com/tc-hib/winres v0.1.6/go.mod h1:pe6dOR40VOrGz8PkzreVKNvEKnlE8t4yR8A8naL+t7A=
|
||||
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
|
||||
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
|
||||
github.com/wailsapp/task/v3 v3.19.1 h1:syDKYaPBXgrXKKSJVEWcOEoSFtZzpvxqlHf90YRukRc=
|
||||
github.com/wailsapp/task/v3 v3.19.1/go.mod h1:y7rWakbLR5gFElGgo6rA2dyr6vU/zNIDVfn3S4Of6OI=
|
||||
github.com/wailsapp/wails/v2 v2.3.2-0.20230117193915-45c3a501d9e6 h1:Wn+nhnS+VytzE0PegUzSh4T3hXJCtggKGD/4U5H9+wQ=
|
||||
github.com/wailsapp/wails/v2 v2.3.2-0.20230117193915-45c3a501d9e6/go.mod h1:zlNLI0E2c2qA6miiuAHtp0Bac8FaGH0tlhA19OssR/8=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/internal/flags"
|
||||
)
|
||||
|
||||
func Build(options *flags.Build) error {
|
||||
return RunTask(&RunTaskOptions{
|
||||
Name: "build",
|
||||
})
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
@@ -15,17 +15,9 @@ import (
|
||||
type IconsOptions struct {
|
||||
Example bool `description:"Generate example icon file (appicon.png) in the current directory"`
|
||||
Input string `description:"The input image file"`
|
||||
Sizes string `description:"The sizes to generate in .ico file (comma separated)"`
|
||||
WindowsFilename string `description:"The output filename for the Windows icon"`
|
||||
MacFilename string `description:"The output filename for the Mac icon bundle"`
|
||||
}
|
||||
|
||||
func (i *IconsOptions) Default() *IconsOptions {
|
||||
return &IconsOptions{
|
||||
Sizes: "256,128,64,48,32,16",
|
||||
MacFilename: "icons.icns",
|
||||
WindowsFilename: "icons.ico",
|
||||
}
|
||||
Sizes string `description:"The sizes to generate in .ico file (comma separated)" default:"256,128,64,48,32,16"`
|
||||
WindowsFilename string `description:"The output filename for the Windows icon" default:"icon.ico"`
|
||||
MacFilename string `description:"The output filename for the Mac icon bundle" default:"icons.icns"`
|
||||
}
|
||||
|
||||
func GenerateIcons(options *IconsOptions) error {
|
||||
@@ -51,7 +43,6 @@ func GenerateIcons(options *IconsOptions) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
iconData, err := os.ReadFile(options.Input)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,8 +1,44 @@
|
||||
package commands
|
||||
|
||||
type InitOptions struct {
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/wailsapp/wails/v3/internal/flags"
|
||||
"github.com/wailsapp/wails/v3/internal/templates"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
)
|
||||
|
||||
func Init(options *flags.Init) error {
|
||||
if options.List {
|
||||
return printTemplates()
|
||||
}
|
||||
|
||||
if options.Quiet {
|
||||
pterm.DisableOutput()
|
||||
}
|
||||
|
||||
if options.ProjectName == "" {
|
||||
return fmt.Errorf("please use the -n flag to specify a project name")
|
||||
}
|
||||
|
||||
if !templates.ValidTemplateName(options.TemplateName) {
|
||||
return fmt.Errorf("invalid template name: %s. Use -l flag to view available templates", options.TemplateName)
|
||||
}
|
||||
|
||||
return templates.Install(options)
|
||||
}
|
||||
|
||||
func Init(options *InitOptions) error {
|
||||
return nil
|
||||
func printTemplates() error {
|
||||
defaultTemplates := templates.GetDefaultTemplates()
|
||||
|
||||
pterm.DefaultSection.Println("Available templates")
|
||||
|
||||
table := pterm.TableData{{"Name", "Description"}}
|
||||
for _, template := range defaultTemplates {
|
||||
table = append(table, []string{template.Name, template.Description})
|
||||
}
|
||||
err := pterm.DefaultTable.WithHasHeader(true).WithBoxed(true).WithData(table).Render()
|
||||
pterm.Println()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func ListTasks(options *ListTaskOptions) error {
|
||||
return err
|
||||
}
|
||||
if len(tasks) == 0 {
|
||||
return fmt.Errorf("no tasks found. Ensure there is a `Taskfile.yml` in your project. You can generate a default takfile by running `wails generate defaults`")
|
||||
return fmt.Errorf("no tasks found. Ensure there is a `Taskfile.tmpl.yml` in your project. You can generate a default takfile by running `wails generate defaults`")
|
||||
}
|
||||
tableData := [][]string{
|
||||
{"Task", "Summary"},
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package flags
|
||||
|
||||
type Build struct {
|
||||
Common
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package flags
|
||||
|
||||
type Common struct {
|
||||
NoColour bool `description:"Disable colour in output"`
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package flags
|
||||
|
||||
type Init struct {
|
||||
Common
|
||||
|
||||
TemplateName string `name:"t" description:"Name of built-in template to use, path to template or template url" default:"vanilla"`
|
||||
ProjectName string `name:"n" description:"Name of project" default:"."`
|
||||
//CIMode bool `name:"ci" description:"CI Mode"`
|
||||
ProjectDir string `name:"d" description:"Project directory" default:"."`
|
||||
Quiet bool `name:"q" description:"Suppress output to console"`
|
||||
//InitGit bool `name:"g" description:"Initialise git repository"`
|
||||
//IDE string `name:"ide" description:"Generate IDE project files"`
|
||||
List bool `name:"l" description:"List templates"`
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
version: '3'
|
||||
|
||||
vars:
|
||||
APP_NAME: "{{.ProjectName}}"
|
||||
|
||||
tasks:
|
||||
|
||||
pre-build:
|
||||
summary: Pre-build hooks
|
||||
|
||||
post-build:
|
||||
summary: Post-build hooks
|
||||
|
||||
install-frontend-deps:
|
||||
summary: Install frontend dependencies
|
||||
dir: frontend
|
||||
sources:
|
||||
- package.json
|
||||
- package-lock.json
|
||||
generates:
|
||||
- node_modules/*
|
||||
preconditions:
|
||||
- sh: npm version
|
||||
msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/"
|
||||
cmds:
|
||||
- npm install
|
||||
|
||||
build-frontend:
|
||||
summary: Build the frontend project
|
||||
dir: frontend
|
||||
deps:
|
||||
- install-frontend-deps
|
||||
cmds:
|
||||
- npm run build
|
||||
|
||||
build:
|
||||
summary: Builds the application
|
||||
cmds:
|
||||
- task: pre-build
|
||||
- task: build-frontend
|
||||
- go build -gcflags=all="-N -l" -o build/bin/{{ "{{.APP_NAME}}" }} main.go
|
||||
- task: post-build
|
||||
env:
|
||||
CGO_CFLAGS: "-mmacosx-version-min=10.13"
|
||||
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
|
||||
|
||||
generate-icons:
|
||||
summary: Generates Windows `.ico` and Mac `.icns` files from an image
|
||||
dir: build
|
||||
cmds:
|
||||
# Generates both .ico and .icns files
|
||||
- wails generate icons -input appicon.png
|
||||
|
||||
build-app-prod-darwin:
|
||||
summary: Creates a production build of the application
|
||||
cmds:
|
||||
- GOOS=darwin GOARCH={{ "{{.ARCH}}" }} go build -tags production -ldflags="-w -s" -o build/bin/{{ "{{.APP_NAME}}" }}
|
||||
env:
|
||||
CGO_CFLAGS: "-mmacosx-version-min=10.13"
|
||||
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
|
||||
vars:
|
||||
ARCH: $GOARCH
|
||||
|
||||
|
||||
create-app-bundle:
|
||||
summary: Builds a `.app` bundle
|
||||
cmds:
|
||||
- mkdir -p {{ "{{.APP_NAME}}" }}.app/Contents/{MacOS,Resources}
|
||||
- cp build/icons.icns {{ "{{.APP_NAME}}" }}.app/Contents/Resources
|
||||
- cp build/bin/{{ "{{.APP_NAME}}" }} {{ "{{.APP_NAME}}" }}.app/Contents/MacOS
|
||||
- cp build/Info.plist {{ "{{.APP_NAME}}" }}.app/Contents
|
||||
|
||||
package-darwin-arm64:
|
||||
summary: Packages a production build of the application into a `.app` bundle
|
||||
platform: darwin
|
||||
deps:
|
||||
- task: build-app-prod-darwin
|
||||
vars:
|
||||
ARCH: arm64
|
||||
- generate-icons
|
||||
cmds:
|
||||
- task: create-app-bundle
|
||||
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>{{ "{{.Info.ProductName}}" }}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>{{ "{{.ProjectName}}" }}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.wails.{{ "{{.ProjectName}}" }}</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>v1.0.0</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>This is a comment</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>v1.0.0</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>iconfile</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.13.0</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<string>true</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>(c) 2023 My Company Name</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"fixed": {
|
||||
"file_version": "v1.0.0"
|
||||
},
|
||||
"info": {
|
||||
"0000": {
|
||||
"ProductVersion": "v1.0.0",
|
||||
"CompanyName": "My Company Name",
|
||||
"FileDescription": "A thing that does a thing",
|
||||
"LegalCopyright": "(c) 2023 My Company Name",
|
||||
"ProductName": "My Product Name",
|
||||
"Comments": "This is a comment"
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user