Compare commits

...

65 Commits

Author SHA1 Message Date
Lea Anthony
2729081f2c [v2] v2.0.0-beta.8 2021-10-09 07:57:23 +11:00
Lea Anthony
cad1317fc8 [v2] Tags passthrough for wails generate module 2021-10-09 07:56:19 +11:00
Lea Anthony
1368c20029 [website] v2.0.0-beta.7 2021-10-09 00:06:39 +11:00
Lea Anthony
0acfdd1516 [website] v2.0.0-beta.6 2021-10-09 00:03:35 +11:00
Lea Anthony
212a20626a [website] Update go webview 2021-10-09 00:02:53 +11:00
Lea Anthony
722ecc969b [website] Update docs to v2.0.0-beta.5 2021-10-08 20:27:10 +11:00
Lea Anthony
078145c030 [v2] v2.0.0-beta.5 2021-10-08 19:54:48 +11:00
Lea Anthony
3765c8fb57 [v2] Auto update wails version in projects in dev mode 2021-10-08 19:53:46 +11:00
Lea Anthony
10ac38c650 [v2] update go build url 2021-10-08 19:51:51 +11:00
Lea Anthony
a16e41f813 [v2] Tidy up frontend 2021-10-07 21:04:33 +11:00
Lea Anthony
1bd3deb39f Merge pull request #859 from marktohark/master
PutAreBrowserAcceleratorKeysEnabled => false
2021-10-07 21:02:27 +11:00
unknown
be5f7ceb0e uncomment PostMessage 2021-10-07 17:34:06 +08:00
Lea Anthony
6943b657c9 [v2] Fix error messages in dev mode 2021-10-07 18:56:53 +11:00
unknown
a148c67df0 don't hook any AcceleratorKey in callback 2021-10-07 14:35:14 +08:00
unknown
69297667c1 PutAreBrowserAcceleratorKeysEnabled => false 2021-10-07 14:28:52 +08:00
Lea Anthony
1ae9469e90 [v2] Fix bindings build tags 2021-10-06 20:36:31 +11:00
Lea Anthony
d597d8e1c9 [v2] Fix bindings build tags 2021-10-06 20:36:15 +11:00
Lea Anthony
d32152ed84 [website] Add sponsor 2021-10-06 20:36:15 +11:00
Lea Anthony
d28a7e8987 [v2] Run go mod tidy first to ensure deps are up to date 2021-10-06 20:36:15 +11:00
Lea Anthony
ef362a746a Merge pull request #849 from marktohark/filter-execjs-json
add template.JSEscapeString to ensure ExecJs normal execution
2021-10-06 20:13:19 +11:00
Lea Anthony
c16c95673e Merge pull request #855 from wailsapp/dependabot/go_modules/github.com/gorilla/websocket-1.4.1
Bump github.com/gorilla/websocket from 1.4.0 to 1.4.1
2021-10-06 07:19:52 +11:00
dependabot[bot]
d426fc46b5 Bump github.com/gorilla/websocket from 1.4.0 to 1.4.1
Bumps [github.com/gorilla/websocket](https://github.com/gorilla/websocket) from 1.4.0 to 1.4.1.
- [Release notes](https://github.com/gorilla/websocket/releases)
- [Commits](https://github.com/gorilla/websocket/compare/v1.4.0...v1.4.1)

---
updated-dependencies:
- dependency-name: github.com/gorilla/websocket
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-05 18:12:23 +00:00
Lea Anthony
0efeed4d7f Merge pull request #852 from misitebao/synchronize-chinese-documents
feat(website): synchronize chinese documents
2021-10-06 05:10:38 +11:00
misitebao
a11a75fa12 feat(website): correct and optimize documents 2021-10-05 22:26:34 +08:00
misitebao
2d551cd019 feat(website): synchronize showcase 2021-10-05 22:26:34 +08:00
misitebao
37259b8adb feat(website): synchronize chinese documents 2021-10-05 22:26:33 +08:00
misitebao
d5cfcc80f7 config(website): update dependency configuration file 2021-10-05 22:26:33 +08:00
misitebao
25564b7211 ci: add scripts for automatic deployment of mirrored websites 2021-10-05 22:26:32 +08:00
Lea Anthony
661b24cfa2 Update Sponsors 2021-10-05 23:34:04 +11:00
Lea Anthony
75f703465a [v2] Generate module command. Updated wails dev 2021-10-05 22:27:12 +11:00
unknown
9949420639 add template.JSEscapeString to ensure ExecJs normal execution 2021-10-05 09:45:36 +08:00
Lea Anthony
9e347bf71f [v2] Generate ipcdev.js and runtimedev.js 2021-10-04 19:58:46 +11:00
Lea Anthony
829fd8616b [v2] Make ipc.js cross-platform 2021-10-04 19:42:22 +11:00
Lea Anthony
ae980d48fd [v2] Fix connection delay for websockets 2021-10-04 17:10:46 +11:00
Lea Anthony
ba9e64f53a Merge pull request #848 from codydbentley/refactor-dev-command
Refactored `wails dev` command:
2021-10-04 17:10:26 +11:00
Lea Anthony
b15d98b555 [v2] Rename noautoinjectbindings -> noautoinjectipc 2021-10-04 16:53:27 +11:00
Cody Bentley
bdda454f69 Refactored wails dev command:
- added `devFlags` data structure for managing flags
- created `defaultDevFlags()` for generating default `devFlags` struct
- created `loadAndMergeProjectConfig()` to consolidate wails.json interaction
- re-arranged some variable creation and logic to put related pieces together
- consolidated `frontend:dev` handling to `runFrontendDevCommand()`
- added `generateBuildOptions()` for readability
- removed unused `passthruArgs` slice
- consolidated `restartApp()` call signature, removed unused `firstRun` argument
- fixed browser open option still using hard-coded default value, switched to recently added const `defaultDevServerURL`
- removed unnecessary `projectDir` variable (it's identical to `cwd` variable)
- consolidated watcher init to `initialiseWatcher()` which returns a deferable closer
- moved the main watch loop to `doWatcherLoop()`
- moved new deBounce flag handling to `loadAndMergeProjectConfig()`
2021-10-03 23:01:42 -06:00
Lea Anthony
a59d01ddb9 [v2] Fix killing dev command on Windows 2021-10-03 22:19:40 +11:00
Lea Anthony
27f8df2b31 [v2] Support "frontend:dev" command 2021-10-03 21:29:59 +11:00
Lea Anthony
1b28f69236 [v2] Fix -devserverurl flag 2021-10-03 16:44:37 +11:00
Lea Anthony
7572b64bec [v2] Add -devserverurl flag 2021-10-03 15:07:10 +11:00
Lea Anthony
f6b83b0933 [v2] New -debounce flag to configure debounce time of dev server 2021-10-03 14:04:05 +11:00
Lea Anthony
a51ab25e2c Merge pull request #845 from codydbentley/add-new-templates
Added two new Vue3 TS templates to website
2021-10-03 13:33:57 +11:00
Lea Anthony
aeaaccb942 Merge pull request #846 from codydbentley/fix-template-generator
Fixed base NEXTSTEPS and README in v2 template generator
2021-10-03 12:36:20 +11:00
Cody Bentley
4bf3eb303b Fixed base NEXTSTEPS and README in v2 template generator 2021-10-02 17:29:43 -06:00
Cody Bentley
b5437ed1b5 Added two new Vue3 TS templates to website 2021-10-02 17:27:07 -06:00
Lea Anthony
e2e752dd06 [v2] Fix timing bug 2021-10-02 19:55:49 +10:00
Lea Anthony
9dc2caecf0 [website] Rename heading 2021-10-02 14:27:06 +10:00
Lea Anthony
b0da974a7d [v2] v2.0.0-beta.4 2021-10-02 14:16:40 +10:00
Lea Anthony
b4dc8c252a [v2] update now uses go install 2021-10-02 14:14:07 +10:00
Lea Anthony
afb1d12c3b [v2] Add meta tag to control script injection behaviour 2021-10-02 14:04:59 +10:00
Lea Anthony
7a0cb428f2 Merge pull request #840 from codydbentley/fix-missing-comma-in-bindings
Fixed missing comma that breaks bindings with more than one package
2021-09-30 19:28:56 +10:00
Cody Bentley
e6a89790e3 Fixed missing comma that would break bindings when more than one package exists 2021-09-29 22:04:28 -06:00
Lea Anthony
daede02c16 Merge pull request #776 from wailsapp/dependabot/npm_and_yarn/runtime/js/runtime/path-parse-1.0.7
Bump path-parse from 1.0.6 to 1.0.7 in /runtime/js/runtime
2021-09-30 08:40:10 +10:00
Lea Anthony
417895f40b Merge pull request #826 from wailsapp/dependabot/npm_and_yarn/website/prismjs-1.25.0
Bump prismjs from 1.24.1 to 1.25.0 in /website
2021-09-30 08:39:41 +10:00
Lea Anthony
6bc26aa669 [v2] Add .gitignore to templates 2021-09-30 08:20:32 +10:00
Lea Anthony
a641deb388 [v2] Devserver listen to localhost 2021-09-30 08:00:50 +10:00
Lea Anthony
e013ce14a1 [v2] fix tags in dev mode 2021-09-30 07:11:49 +10:00
Lea Anthony
9930ee10da Revert "Corrected obsolete 'text/javascript' mime to 'application/javascript'"
This reverts commit 23c1ebfac9.
2021-09-30 07:07:13 +10:00
Lea Anthony
de6c57771e [website] update sponsors 2021-09-30 07:01:30 +10:00
Lea Anthony
c8359b0743 [v2] sync go.sum 2021-09-30 07:01:12 +10:00
Lea Anthony
12b7cf09e6 [v2] Support Goland IDE 2021-09-30 07:00:46 +10:00
Lea Anthony
28af34f978 [website] update installation instructions to v2.0.0-beta.3 2021-09-29 20:39:58 +10:00
dependabot[bot]
7311868636 Bump prismjs from 1.24.1 to 1.25.0 in /website
Bumps [prismjs](https://github.com/PrismJS/prism) from 1.24.1 to 1.25.0.
- [Release notes](https://github.com/PrismJS/prism/releases)
- [Changelog](https://github.com/PrismJS/prism/blob/master/CHANGELOG.md)
- [Commits](https://github.com/PrismJS/prism/compare/v1.24.1...v1.25.0)

---
updated-dependencies:
- dependency-name: prismjs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-27 09:37:34 +00:00
dependabot[bot]
ed4b74f01b Bump path-parse from 1.0.6 to 1.0.7 in /runtime/js/runtime
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-12 21:19:10 +00:00
103 changed files with 17747 additions and 837 deletions

View File

@@ -0,0 +1,35 @@
name: Deploy mirror | 部署镜像
on:
push:
branches: [master]
# pull_request:
# branches: [ main ]
jobs:
build-and-deploy:
name: Automatic deployment | 自动部署
runs-on: ubuntu-latest
if: github.repository == 'misitebao/wails'
steps:
- name: Checkout | 切换到部署分支
uses: actions/checkout@v2
with:
ref: "master"
submodules: true
fetch-depth: 0
- name: Build Site | 构建网站
run: |
cd website &&
npm install && npm run build
- name: Deploy to Server | 部署到服务器
uses: hengkx/ssh-deploy@v1.0.1
with:
HOST: ${{ secrets.DEPLOY_HOST }}
USERNAME: ${{ secrets.DEPLOY_HOST_USER }}
PASSWORD: ${{ secrets.DEPLOY_HOST_PASSWORD }}
SOURCE: "website/build"
TARGET: "/www/wwwroot/wails.top"

View File

@@ -119,6 +119,16 @@ This project is supported by these kind people / companies:
<a href="https://github.com/marcus-crane" style="width:50px;border-radius: 50%">
<img src="https://github.com/marcus-crane.png?size=50" width="50" style="border-radius: 50%"/>
</a>
<a href="https://github.com/codydbentley" style="width:65px">
<img src="https://github.com/codydbentley.png?size=65" width="65"/>
</a>
<a href="https://github.com/bbergshaven" style="width:45px">
<img src="https://github.com/bbergshaven.png?size=45" width="45"/>
</a>
<a href="https://github.com/Gilgames000" style="width:45px">
<img src="https://github.com/Gilgames000.png?size=45" width="45"/>
</a>
<span id="nav-5"></span>

2
go.mod
View File

@@ -5,7 +5,7 @@ require (
github.com/abadojack/whatlanggo v1.0.1
github.com/fatih/color v1.7.0
github.com/go-playground/colors v1.2.0
github.com/gorilla/websocket v1.4.0
github.com/gorilla/websocket v1.4.1
github.com/jackmordaunt/icns v1.0.0
github.com/kennygrant/sanitize v1.2.4
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect

4
go.sum
View File

@@ -11,8 +11,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/go-playground/colors v1.2.0 h1:0EdjTXKrr2g1L/LQTYtIqabeHpZuGZz1U4osS1T8+5M=
github.com/go-playground/colors v1.2.0/go.mod h1:miw1R2JIE19cclPxsXqNdzLZsk4DP4iF+m88bRc7kfM=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/jackmordaunt/icns v1.0.0 h1:RYSxplerf/l/DUd09AHtITwckkv/mqjVv4DjYdPmAMQ=

View File

@@ -260,9 +260,9 @@
}
},
"path-parse": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
"dev": true
},
"path-type": {

View File

@@ -1,15 +1,20 @@
package dev
import (
"context"
"fmt"
"github.com/wailsapp/wails/v2/cmd/wails/internal"
"github.com/wailsapp/wails/v2/internal/gomod"
"io"
"log"
"net/http"
"os"
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"syscall"
"time"
@@ -27,6 +32,8 @@ import (
"github.com/wailsapp/wails/v2/pkg/commands/build"
)
const defaultDevServerURL = "http://localhost:34115"
func LogGreen(message string, args ...interface{}) {
text := fmt.Sprintf(message, args...)
println(colour.Green(text))
@@ -50,51 +57,43 @@ func sliceToMap(input []string) map[string]struct{} {
return result
}
type devFlags struct {
ldflags string
compilerCommand string
assetDir string
extensions string
openBrowser bool
noReload bool
wailsjsdir string
tags string
verbosity int
loglevel string
forceBuild bool
debounceMS int
devServerURL string
}
// AddSubcommand adds the `dev` command for the Wails application
func AddSubcommand(app *clir.Cli, w io.Writer) error {
command := app.NewSubCommand("dev", "Development mode")
// Passthrough ldflags
ldflags := ""
command.StringFlag("ldflags", "optional ldflags", &ldflags)
// compiler command
compilerCommand := "go"
command.StringFlag("compiler", "Use a different go compiler to build, eg go1.15beta1", &compilerCommand)
assetDir := ""
command.StringFlag("assetdir", "Serve assets from the given directory", &assetDir)
// extensions to trigger rebuilds of application
extensions := "go"
command.StringFlag("e", "Extensions to trigger rebuilds (comma separated) eg go", &extensions)
openBrowser := false
command.BoolFlag("browser", "Open application in browser", &openBrowser)
noreload := false
command.BoolFlag("noreload", "Disable reload on asset change", &noreload)
wailsjsdir := ""
command.StringFlag("wailsjsdir", "Directory to generate the Wails JS modules", &wailsjsdir)
// tags to pass to `go`
tags := ""
command.StringFlag("tags", "tags to pass to Go compiler (quoted and space separated)", &tags)
// Verbosity
verbosity := 1
command.IntFlag("v", "Verbosity level (0 - silent, 1 - standard, 2 - verbose)", &verbosity)
loglevel := ""
command.StringFlag("loglevel", "Loglevel to use - Trace, Dev, Info, Warning, Error", &loglevel)
forceBuild := false
command.BoolFlag("f", "Force build application", &forceBuild)
flags := defaultDevFlags()
command.StringFlag("ldflags", "optional ldflags", &flags.ldflags)
command.StringFlag("compiler", "Use a different go compiler to build, eg go1.15beta1", &flags.compilerCommand)
command.StringFlag("assetdir", "Serve assets from the given directory", &flags.assetDir)
command.StringFlag("e", "Extensions to trigger rebuilds (comma separated) eg go", &flags.extensions)
command.BoolFlag("browser", "Open application in browser", &flags.openBrowser)
command.BoolFlag("noreload", "Disable reload on asset change", &flags.noReload)
command.StringFlag("wailsjsdir", "Directory to generate the Wails JS modules", &flags.wailsjsdir)
command.StringFlag("tags", "tags to pass to Go compiler (quoted and space separated)", &flags.tags)
command.IntFlag("v", "Verbosity level (0 - silent, 1 - standard, 2 - verbose)", &flags.verbosity)
command.StringFlag("loglevel", "Loglevel to use - Trace, Dev, Info, Warning, Error", &flags.loglevel)
command.BoolFlag("f", "Force build application", &flags.forceBuild)
command.IntFlag("debounce", "The amount of time to wait to trigger a reload on change", &flags.debounceMS)
command.StringFlag("devserverurl", "The url of the dev server to use", &flags.devServerURL)
command.Action(func() error {
// Create logger
logger := clilogger.New(w)
app.PrintBanner()
@@ -103,90 +102,54 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
if err != nil {
return err
}
projectConfig, err := project.Load(cwd)
projectConfig, err := loadAndMergeProjectConfig(cwd, &flags)
if err != nil {
return err
}
if projectConfig.AssetDirectory == "" && assetDir == "" {
return fmt.Errorf("No asset directory provided. Please use -assetdir to indicate which directory contains your built assets.")
}
if assetDir == "" && projectConfig.AssetDirectory != "" {
assetDir = projectConfig.AssetDirectory
}
if assetDir != projectConfig.AssetDirectory {
projectConfig.AssetDirectory = filepath.ToSlash(assetDir)
err := projectConfig.Save()
if err != nil {
return err
}
}
assetDir, err := filepath.Abs(assetDir)
// Update go.mod to use current wails version
err = syncGoModVersion(cwd)
if err != nil {
return err
}
if wailsjsdir == "" && projectConfig.WailsJSDir != "" {
wailsjsdir = projectConfig.WailsJSDir
}
if wailsjsdir == "" {
wailsjsdir = "./frontend"
}
if wailsjsdir != projectConfig.WailsJSDir {
projectConfig.WailsJSDir = filepath.ToSlash(wailsjsdir)
err := projectConfig.Save()
if err != nil {
return err
}
}
buildOptions := &build.Options{
Logger: logger,
OutputType: "dev",
Mode: build.Dev,
Arch: runtime.GOARCH,
Pack: true,
Platform: runtime.GOOS,
LDFlags: ldflags,
Compiler: compilerCommand,
ForceBuild: forceBuild,
IgnoreFrontend: false,
Verbosity: verbosity,
WailsJSDir: wailsjsdir,
}
watcher, err := fsnotify.NewWatcher()
// Run go mod tidy to ensure we're up to date
err = runCommand(cwd, false, "go", "mod", "tidy")
if err != nil {
return err
}
defer func(watcher *fsnotify.Watcher) {
err := watcher.Close()
if err != nil {
log.Fatal(err)
}
}(watcher)
if flags.tags != "" {
err = runCommand(cwd, true, "wails", "generate", "module", "-tags", flags.tags)
} else {
err = runCommand(cwd, true, "wails", "generate", "module")
}
if err != nil {
return err
}
// frontend:dev server command
if projectConfig.DevCommand != "" {
var devCommandWaitGroup sync.WaitGroup
closer := runFrontendDevCommand(cwd, projectConfig.DevCommand, &devCommandWaitGroup)
defer closer(&devCommandWaitGroup)
}
buildOptions := generateBuildOptions(flags)
buildOptions.Logger = logger
buildOptions.UserTags = internal.ParseUserTags(flags.tags)
var debugBinaryProcess *process.Process = nil
var extensionsThatTriggerARebuild = sliceToMap(strings.Split(extensions, ","))
// Setup signal handler
quitChannel := make(chan os.Signal, 1)
signal.Notify(quitChannel, os.Interrupt, os.Kill, syscall.SIGTERM)
exitCodeChannel := make(chan int, 1)
var passthruArgs []string
//if len(os.Args) > 2 {
// passthruArgs = os.Args[2:]
//}
// Do initial build
logger.Println("Building application for development...")
newProcess, appBinary, err := restartApp(logger, buildOptions, debugBinaryProcess, loglevel, passthruArgs, assetDir, false, exitCodeChannel)
newProcess, appBinary, err := restartApp(buildOptions, debugBinaryProcess, flags, exitCodeChannel)
if err != nil {
return err
}
@@ -195,129 +158,32 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
}
// open browser
if openBrowser {
err = browser.OpenURL("http://localhost:34115")
if flags.openBrowser {
url := defaultDevServerURL
if flags.devServerURL != "" {
url = flags.devServerURL
}
err = browser.OpenURL(url)
if err != nil {
return err
}
}
if err != nil {
return err
}
var newBinaryProcess *process.Process
// Get project dir
projectDir, err := os.Getwd()
if err != nil {
return err
}
// Get all subdirectories
dirs, err := fs.GetSubdirectories(projectDir)
if err != nil {
return err
}
LogGreen("Watching (sub)/directory: %s", projectDir)
// Setup a watcher for non-node_modules directories
dirs.Each(func(dir string) {
if strings.Contains(dir, "node_modules") {
return
}
// Ignore build directory
if strings.HasPrefix(dir, filepath.Join(projectDir, "build")) {
return
}
// Ignore dot directories
if strings.HasPrefix(dir, ".") {
return
}
err = watcher.Add(dir)
// create the project files watcher
watcher, err := initialiseWatcher(cwd, logger.Fatal)
defer func(watcher *fsnotify.Watcher) {
err := watcher.Close()
if err != nil {
logger.Fatal(err.Error())
}
})
}(watcher)
// Main Loop
quit := false
// Use 100ms debounce
interval := 100 * time.Millisecond
timer := time.NewTimer(interval)
rebuild := false
reload := false
for quit == false {
//reload := false
select {
case exitCode := <-exitCodeChannel:
if exitCode == 0 {
quit = true
}
case item := <-watcher.Events:
// Check for file writes
if item.Op&fsnotify.Write == fsnotify.Write {
// Ignore directories
if fs.DirExists(item.Name) {
continue
}
LogGreen("Watching (sub)/directory: %s", cwd)
LogGreen("Using Dev Server URL: %s", flags.devServerURL)
LogGreen("Using reload debounce setting of %d milliseconds", flags.debounceMS)
// Iterate all file patterns
ext := filepath.Ext(item.Name)
if ext != "" {
ext = ext[1:]
if _, exists := extensionsThatTriggerARebuild[ext]; exists {
rebuild = true
continue
}
}
if strings.HasPrefix(item.Name, assetDir) {
reload = true
}
timer.Reset(interval)
}
// Check for new directories
if item.Op&fsnotify.Create == fsnotify.Create {
// If this is a folder, add it to our watch list
if fs.DirExists(item.Name) {
//node_modules is BANNED!
if !strings.Contains(item.Name, "node_modules") {
err := watcher.Add(item.Name)
if err != nil {
logger.Fatal("%s", err.Error())
}
LogGreen("Added new directory to watcher: %s", item.Name)
}
}
}
case <-timer.C:
if rebuild {
rebuild = false
LogGreen("[Rebuild triggered] files updated")
// Try and build the app
newBinaryProcess, _, err = restartApp(logger, buildOptions, debugBinaryProcess, loglevel, passthruArgs, assetDir, false, exitCodeChannel)
if err != nil {
LogRed("Error during build: %s", err.Error())
continue
}
// If we have a new process, save it
if newBinaryProcess != nil {
debugBinaryProcess = newBinaryProcess
}
}
if reload {
reload = false
_, err = http.Get("http://localhost:34115/wails/reload")
if err != nil {
LogRed("Error during refresh: %s", err.Error())
}
}
case <-quitChannel:
LogGreen("\nCaught quit")
quit = true
}
}
// Watch for changes and trigger restartApp()
doWatcherLoop(buildOptions, debugBinaryProcess, flags, watcher, exitCodeChannel, quitChannel)
// Kill the current program if running
if debugBinaryProcess != nil {
@@ -337,18 +203,226 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
return nil
})
return nil
}
func restartApp(logger *clilogger.CLILogger, buildOptions *build.Options, debugBinaryProcess *process.Process, loglevel string, passthruArgs []string, assetDir string, firstRun bool, exitCodeChannel chan int) (*process.Process, string, error) {
func syncGoModVersion(cwd string) error {
gomodFilename := filepath.Join(cwd, "go.mod")
gomodData, err := os.ReadFile(gomodFilename)
if err != nil {
return err
}
outOfSync, err := gomod.GoModOutOfSync(gomodData, internal.Version)
if err != nil {
return err
}
if !outOfSync {
return nil
}
LogGreen("Updating go.mod to use Wails '%s'", internal.Version)
newGoData, err := gomod.UpdateGoModVersion(gomodData, internal.Version)
if err != nil {
return err
}
return os.WriteFile(gomodFilename, newGoData, 0755)
}
func runCommand(dir string, exitOnError bool, command string, args ...string) error {
LogGreen("Executing: " + command + " " + strings.Join(args, " "))
cmd := exec.Command(command, args...)
cmd.Dir = dir
output, err := cmd.CombinedOutput()
if err != nil {
println(string(output))
if exitOnError {
os.Exit(1)
}
return err
}
return nil
}
// defaultDevFlags generates devFlags with default options
func defaultDevFlags() devFlags {
return devFlags{
devServerURL: defaultDevServerURL,
compilerCommand: "go",
verbosity: 1,
extensions: "go",
debounceMS: 100,
}
}
// generateBuildOptions creates a build.Options using the flags
func generateBuildOptions(flags devFlags) *build.Options {
return &build.Options{
OutputType: "dev",
Mode: build.Dev,
Arch: runtime.GOARCH,
Pack: true,
Platform: runtime.GOOS,
LDFlags: flags.ldflags,
Compiler: flags.compilerCommand,
ForceBuild: flags.forceBuild,
IgnoreFrontend: false,
Verbosity: flags.verbosity,
WailsJSDir: flags.wailsjsdir,
}
}
// loadAndMergeProjectConfig reconciles flags passed to the CLI with project config settings and updates
// the project config if necessary
func loadAndMergeProjectConfig(cwd string, flags *devFlags) (*project.Project, error) {
projectConfig, err := project.Load(cwd)
if err != nil {
return nil, err
}
var shouldSaveConfig bool
if projectConfig.AssetDirectory == "" && flags.assetDir == "" {
return nil, fmt.Errorf("No asset directory provided. Please use -assetdir to indicate which directory contains your built assets.")
}
if flags.assetDir == "" && projectConfig.AssetDirectory != "" {
flags.assetDir = projectConfig.AssetDirectory
}
if flags.assetDir != projectConfig.AssetDirectory {
projectConfig.AssetDirectory = filepath.ToSlash(flags.assetDir)
}
flags.assetDir, err = filepath.Abs(flags.assetDir)
if err != nil {
return nil, err
}
if flags.devServerURL == defaultDevServerURL && projectConfig.DevServerURL != defaultDevServerURL && projectConfig.DevServerURL != "" {
flags.devServerURL = projectConfig.DevServerURL
}
if flags.devServerURL != projectConfig.DevServerURL {
projectConfig.DevServerURL = flags.devServerURL
shouldSaveConfig = true
}
if flags.wailsjsdir == "" && projectConfig.WailsJSDir != "" {
flags.wailsjsdir = projectConfig.WailsJSDir
}
if flags.wailsjsdir == "" {
flags.wailsjsdir = "./frontend"
}
if flags.wailsjsdir != projectConfig.WailsJSDir {
projectConfig.WailsJSDir = filepath.ToSlash(flags.wailsjsdir)
shouldSaveConfig = true
}
if flags.debounceMS == 100 && projectConfig.DebounceMS != 100 {
if projectConfig.DebounceMS == 0 {
projectConfig.DebounceMS = 100
}
flags.debounceMS = projectConfig.DebounceMS
}
if flags.debounceMS != projectConfig.DebounceMS {
projectConfig.DebounceMS = flags.debounceMS
shouldSaveConfig = true
}
if shouldSaveConfig {
err = projectConfig.Save()
if err != nil {
return nil, err
}
}
return projectConfig, nil
}
// runFrontendDevCommand will run the `frontend:dev` command if it was given, ex- `npm run dev`
func runFrontendDevCommand(cwd string, devCommand string, wg *sync.WaitGroup) func(group *sync.WaitGroup) {
LogGreen("Running frontend dev command: '%s'", devCommand)
ctx, cancel := context.WithCancel(context.Background())
dir := filepath.Join(cwd, "frontend")
cmdSlice := strings.Split(devCommand, " ")
wg.Add(1)
cmd := exec.CommandContext(ctx, cmdSlice[0], cmdSlice[1:]...)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Dir = dir
go func(ctx context.Context, devCommand string, cwd string, wg *sync.WaitGroup) {
err := cmd.Run()
if err != nil {
if err.Error() != "exit status 1" {
LogRed("Error from '%s': %s", devCommand, err.Error())
}
}
LogGreen("Dev command exited!")
wg.Done()
}(ctx, devCommand, cwd, wg)
return func(wg *sync.WaitGroup) {
if runtime.GOOS == "windows" {
// Credit: https://stackoverflow.com/a/44551450
// For whatever reason, killing an npm script on windows just doesn't exit properly with cancel
kill := exec.Command("TASKKILL", "/T", "/F", "/PID", strconv.Itoa(cmd.Process.Pid))
kill.Stderr = os.Stderr
kill.Stdout = os.Stdout
err := kill.Run()
if err != nil {
if err.Error() != "exit status 1" {
LogRed("Error from '%s': %s", devCommand, err.Error())
}
}
} else {
cancel()
}
wg.Wait()
}
}
// initialiseWatcher creates the project directory watcher that will trigger recompile
func initialiseWatcher(cwd string, logFatal func(string, ...interface{})) (*fsnotify.Watcher, error) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
// Get all subdirectories
dirs, err := fs.GetSubdirectories(cwd)
if err != nil {
return nil, err
}
// Setup a watcher for non-node_modules directories
dirs.Each(func(dir string) {
if strings.Contains(dir, "node_modules") {
return
}
// Ignore build directory
if strings.HasPrefix(dir, filepath.Join(cwd, "build")) {
return
}
// Ignore dot directories
if strings.HasPrefix(dir, ".") {
return
}
err = watcher.Add(dir)
if err != nil {
logFatal(err.Error())
}
})
return watcher, nil
}
// restartApp does the actual rebuilding of the application when files change
func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process, flags devFlags, exitCodeChannel chan int) (*process.Process, string, error) {
appBinary, err := build.Build(buildOptions)
println()
if err != nil {
if firstRun {
return nil, "", err
}
LogRed("Build error - continuing to run current version")
LogDarkYellow(err.Error())
return nil, "", nil
@@ -359,7 +433,7 @@ func restartApp(logger *clilogger.CLILogger, buildOptions *build.Options, debugB
killError := debugBinaryProcess.Kill()
if killError != nil {
logger.Fatal("Unable to kill debug binary (PID: %d)!", debugBinaryProcess.PID())
buildOptions.Logger.Fatal("Unable to kill debug binary (PID: %d)!", debugBinaryProcess.PID())
}
debugBinaryProcess = nil
@@ -367,13 +441,12 @@ func restartApp(logger *clilogger.CLILogger, buildOptions *build.Options, debugB
// Start up new binary with correct args
args := slicer.StringSlicer{}
args.Add("-loglevel", loglevel)
if assetDir != "" {
args.Add("-assetdir", assetDir)
args.Add("-loglevel", flags.loglevel)
if flags.assetDir != "" {
args.Add("-assetdir", flags.assetDir)
}
if len(passthruArgs) > 0 {
args.AddSlice(passthruArgs)
if flags.devServerURL != "" {
args.Add("-devserverurl", flags.devServerURL)
}
newProcess := process.NewProcess(appBinary, args.AsSlice()...)
err = newProcess.Start(exitCodeChannel)
@@ -382,11 +455,98 @@ func restartApp(logger *clilogger.CLILogger, buildOptions *build.Options, debugB
if fs.FileExists(appBinary) {
deleteError := fs.DeleteFile(appBinary)
if deleteError != nil {
logger.Fatal("Unable to delete app binary: " + appBinary)
buildOptions.Logger.Fatal("Unable to delete app binary: " + appBinary)
}
}
logger.Fatal("Unable to start application: %s", err.Error())
buildOptions.Logger.Fatal("Unable to start application: %s", err.Error())
}
return newProcess, appBinary, nil
}
// doWatcherLoop is the main watch loop that runs while dev is active
func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Process, flags devFlags, watcher *fsnotify.Watcher, exitCodeChannel chan int, quitChannel chan os.Signal) {
// Main Loop
var (
err error
newBinaryProcess *process.Process
)
var extensionsThatTriggerARebuild = sliceToMap(strings.Split(flags.extensions, ","))
quit := false
interval := time.Duration(flags.debounceMS) * time.Millisecond
timer := time.NewTimer(interval)
rebuild := false
reload := false
for quit == false {
//reload := false
select {
case exitCode := <-exitCodeChannel:
if exitCode == 0 {
quit = true
}
case item := <-watcher.Events:
// Check for file writes
if item.Op&fsnotify.Write == fsnotify.Write {
// Ignore directories
if fs.DirExists(item.Name) {
continue
}
// Iterate all file patterns
ext := filepath.Ext(item.Name)
if ext != "" {
ext = ext[1:]
if _, exists := extensionsThatTriggerARebuild[ext]; exists {
rebuild = true
timer.Reset(interval)
continue
}
}
if strings.HasPrefix(item.Name, flags.assetDir) {
reload = true
}
timer.Reset(interval)
}
// Check for new directories
if item.Op&fsnotify.Create == fsnotify.Create {
// If this is a folder, add it to our watch list
if fs.DirExists(item.Name) {
//node_modules is BANNED!
if !strings.Contains(item.Name, "node_modules") {
err := watcher.Add(item.Name)
if err != nil {
buildOptions.Logger.Fatal("%s", err.Error())
}
LogGreen("Added new directory to watcher: %s", item.Name)
}
}
}
case <-timer.C:
if rebuild {
rebuild = false
LogGreen("[Rebuild triggered] files updated")
// Try and build the app
newBinaryProcess, _, err = restartApp(buildOptions, debugBinaryProcess, flags, exitCodeChannel)
if err != nil {
LogRed("Error during build: %s", err.Error())
continue
}
// If we have a new process, save it
if newBinaryProcess != nil {
debugBinaryProcess = newBinaryProcess
}
}
if reload {
reload = false
_, err = http.Get("http://localhost:34115/wails/reload")
if err != nil {
LogRed("Error during refresh: %s", err.Error())
}
}
case <-quitChannel:
LogGreen("\nCaught quit")
quit = true
}
}
}

View File

@@ -6,8 +6,6 @@ import (
"github.com/wailsapp/wails/v2/cmd/wails/internal/commands/generate/template"
"github.com/leaanthony/clir"
"github.com/wailsapp/wails/v2/pkg/clilogger"
"github.com/wailsapp/wails/v2/pkg/parser"
)
// AddSubcommand adds the `generate` command for the Wails application
@@ -15,34 +13,11 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
command := app.NewSubCommand("generate", "Code Generation Tools")
//AddModuleCommand(app, command, w)
err := AddModuleCommand(app, command, w)
if err != nil {
return err
}
template.AddSubCommand(app, command, w)
return nil
}
func logPackage(pkg *parser.Package, logger *clilogger.CLILogger) {
logger.Println("Processed Go package '" + pkg.Gopackage.Name + "' as '" + pkg.Name + "'")
for _, strct := range pkg.Structs() {
logger.Println("")
logger.Println(" Processed struct '" + strct.Name + "'")
if strct.IsBound {
for _, method := range strct.Methods {
logger.Println(" Bound method '" + method.Name + "'")
}
}
if strct.IsUsedAsData {
for _, field := range strct.Fields {
if !field.Ignored {
logger.Print(" Processed ")
if field.IsOptional {
logger.Print("optional ")
}
logger.Println("field '" + field.Name + "' as '" + field.JSName() + "'")
}
}
}
}
logger.Println("")
}

View File

@@ -1,58 +1,57 @@
package generate
import (
"io"
"time"
"github.com/leaanthony/clir"
"github.com/wailsapp/wails/v2/pkg/clilogger"
"github.com/wailsapp/wails/v2/pkg/parser"
"github.com/wailsapp/wails/v2/cmd/wails/internal"
"github.com/wailsapp/wails/v2/internal/shell"
"io"
"os"
"path/filepath"
"runtime"
"strings"
)
func AddModuleCommand(app *clir.Cli, parent *clir.Command, w io.Writer) {
// AddModuleCommand adds the `module` subcommand for the `generate` command
func AddModuleCommand(app *clir.Cli, parent *clir.Command, w io.Writer) error {
// Backend API
backendAPI := parent.NewSubCommand("module", "Generates a JS module for the frontend to interface with the backend")
command := parent.NewSubCommand("module", "Generate wailsjs modules")
var tags string
command.StringFlag("tags", "tags to pass to Go compiler (quoted and space separated)", &tags)
// Quiet Init
quiet := false
backendAPI.BoolFlag("q", "Suppress output to console", &quiet)
command.Action(func() error {
backendAPI.Action(func() error {
filename := "wailsbindings"
if runtime.GOOS == "windows" {
filename += ".exe"
}
// go build -tags bindings -o bindings.exe
tempDir := os.TempDir()
filename = filepath.Join(tempDir, filename)
// Create logger
logger := clilogger.New(w)
logger.Mute(quiet)
app.PrintBanner()
logger.Print("Generating Javascript module for Go code...")
// Start Time
start := time.Now()
p, err := parser.GenerateWailsFrontendPackage()
cwd, err := os.Getwd()
if err != nil {
return err
}
logger.Println("done.")
logger.Println("")
elapsed := time.Since(start)
packages := p.Packages
// Print report
for _, pkg := range p.Packages {
if pkg.ShouldGenerate() {
logPackage(pkg, logger)
}
tagList := internal.ParseUserTags(tags)
tagList = append(tagList, "bindings")
_, _, err = shell.RunCommand(cwd, "go", "build", "-tags", strings.Join(tagList, ","), "-o", filename)
if err != nil {
return err
}
logger.Println("%d packages parsed in %s.", len(packages), elapsed)
_, _, err = shell.RunCommand(cwd, filename)
if err != nil {
return err
}
err = os.Remove(filename)
if err != nil {
return err
}
return nil
})
return nil
}

View File

@@ -21,7 +21,7 @@ The next steps to complete the template are:
You can test your template by running this command:
`wails init -name test -t {{.TemplateDir}}`
`wails init -n test -t {{.TemplateDir}}`
### Checklist

View File

@@ -12,5 +12,5 @@ To generate a platform native package, add the `-package` flag.
## Live Development
To run in live development mode, run `wails dev` in the project directory. In another terminal, go into the `frontend`
directory and run `npm run dev`. The frontend dev server will run on http://localhost:5000. Connect to this
directory and run `npm run dev`. The frontend dev server will run on http://localhost:34115. Connect to this
in your browser and connect to your application.

View File

@@ -5,6 +5,9 @@ import (
"github.com/flytam/filenamify"
"github.com/leaanthony/slicer"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
@@ -78,7 +81,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
}
// Validate IDE option
supportedIDEs := slicer.String([]string{"vscode"})
supportedIDEs := slicer.String([]string{"vscode", "goland"})
ide = strings.ToLower(ide)
if ide != "" {
if !supportedIDEs.Contains(ide) {
@@ -101,6 +104,16 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
if err != nil {
return err
}
goBinary, err := exec.LookPath("go")
if err != nil {
return fmt.Errorf("unable to find Go compiler. Please download and install Go: https://golang.org/dl/")
}
// Get base path and convert to forward slashes
goPath := filepath.ToSlash(filepath.Dir(goBinary))
// Trim bin directory
goSDKPath := strings.TrimSuffix(goPath, "/bin")
// Create Template Options
options := &templates.Options{
ProjectName: projectName,
@@ -111,19 +124,20 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
InitGit: initGit,
ProjectNameFilename: projectFilename,
WailsVersion: app.Version(),
GoSDKPath: goSDKPath,
}
// Try to discover author details from git config
findAuthorDetails(options)
return initProject(options)
return initProject(options, quiet)
})
return nil
}
// initProject is our main init command
func initProject(options *templates.Options) error {
func initProject(options *templates.Options, quiet bool) error {
// Start Time
start := time.Now()
@@ -140,6 +154,19 @@ func initProject(options *templates.Options) error {
return err
}
// Run `go mod tidy` to ensure `go.sum` is up to date
cmd := exec.Command("go", "mod", "tidy")
cmd.Dir = options.TargetDir
cmd.Stderr = os.Stderr
if !quiet {
println("")
cmd.Stdout = os.Stdout
}
err = cmd.Run()
if err != nil {
return err
}
if options.InitGit {
err = initGit(options)
if err != nil {
@@ -147,6 +174,10 @@ func initProject(options *templates.Options) error {
}
}
if quiet {
return nil
}
// Output stats
elapsed := time.Since(start)
options.Logger.Println("")

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git"/>
</component>
</project>

View File

@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="ALL"/>
</component>
<component name="GOROOT" url="file://{{.GoSDKPath}}"/>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$"/>
</component>
<component name="GoLibraries">
<option name="indexEntireGoPath" value="false"/>
</component>
<component name="ProjectId" id="wails-{{.ProjectName}}"/>
<component name="ProjectLevelVcsManager" settingsEditedManually="true"/>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true"/>
<option name="showLibraryContents" value="true"/>
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true"/>
<property name="RunOnceActivity.ShowReadmeOnStart" value="true"/>
<property name="WebServerToolWindowFactoryState" value="false"/>
<property name="com.intellij.ide.scratch.LRUPopupBuilder$1/New Scratch File" value="TEXT"/>
<property name="go.formatter.settings.were.checked" value="true"/>
<property name="go.import.settings.migrated" value="true"/>
<property name="go.modules.go.list.on.any.changes.was.set" value="true"/>
<property name="go.sdk.automatically.set" value="true"/>
<property name="go.tried.to.enable.integration.vgo.integrator" value="true"/>
<property name="last_opened_file_path" value="$PROJECT_DIR$"/>
<property name="settings.editor.selected.configurable"
value="reference.settingsdialog.IDE.editor.colors.Console Font"/>
</component>
<component name="RunManager" selected="Go Build.{{.ProjectName}} (dev)">>
<configuration name="{{.ProjectName}} (dev)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="{{.ProjectName}}"/>
<working_directory value="$PROJECT_DIR$"/>
<go_parameters value="-gcflags &quot;all=-N -l&quot; -tags dev -o {{.PathToDesktopBinary}}"/>
<useCustomBuildTags value="true"/>
<parameters value="-assetdir {{.AssetDir}}"/>
<envs>
<env name="CGO_ENABLED" value="&quot;{{.CGOEnabled}}&quot;"/>
</envs>
<kind value="DIRECTORY"/>
<directory value="$PROJECT_DIR$"/>
<filePath value="$PROJECT_DIR$"/>
<method v="2">
</method>
</configuration>
<configuration name="{{.ProjectName}} (production)" type="GoApplicationRunConfiguration"
factoryName="Go Application">
<module name="{{.ProjectName}}"/>
<working_directory value="$PROJECT_DIR$"/>
<go_parameters
value="-ldflags &quot;-w -s{{.WindowsFlags}}&quot; -tags desktop,production -o {{.PathToDesktopBinary}}"/>
<useCustomBuildTags value="true"/>
<envs>
<env name="CGO_ENABLED" value="&quot;{{.CGOEnabled}}&quot;"/>
</envs>
<kind value="DIRECTORY"/>
<directory value="$PROJECT_DIR$"/>
<filePath value="$PROJECT_DIR$"/>
<method v="2">
</method>
</configuration>
<list>
<item itemvalue="Go Build.{{.ProjectName}} (dev)"/>
<item itemvalue="Go Remote.Local"/>
</list>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0"
DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true"/>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3"/>
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State/>
</value>
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true"/>
</component>
<component name="VgoProject">
<integration-enabled>true</integration-enabled>
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
</breakpoint-manager>
</component>
</project>

View File

@@ -42,6 +42,11 @@ type Data struct {
AuthorEmail string
AuthorNameAndEmail string
WailsDirectory string
GoSDKPath string
AssetDir string
WindowsFlags string
CGOEnabled string
OutputFile string
}
// Options for installing a template
@@ -60,6 +65,10 @@ type Options struct {
IDE string
ProjectNameFilename string // The project name but as a valid filename
WailsVersion string
GoSDKPath string
WindowsFlags string
CGOEnabled string
OutputFile string
}
// Template holds data relating to a template
@@ -243,6 +252,7 @@ func Install(options *Options) (bool, *Template, error) {
BinaryName := filepath.Base(options.TargetDir)
NPMProjectName := strings.ToLower(strings.ReplaceAll(BinaryName, " ", ""))
localWailsDirectory := fs.RelativePath("../../../../../..")
templateData := &Data{
ProjectName: options.ProjectName,
BinaryName: filepath.Base(options.TargetDir),
@@ -251,6 +261,8 @@ func Install(options *Options) (bool, *Template, error) {
AuthorEmail: options.AuthorEmail,
AuthorName: options.AuthorName,
WailsVersion: options.WailsVersion,
GoSDKPath: options.GoSDKPath,
AssetDir: options.AssetDir,
}
// Create a formatted name and email combo.
@@ -262,6 +274,10 @@ func Install(options *Options) (bool, *Template, error) {
}
templateData.AuthorNameAndEmail = strings.TrimSpace(templateData.AuthorNameAndEmail)
installer.RenameFiles(map[string]string{
"gitignore.txt": ".gitignore",
})
// Extract the template
err = installer.Extract(options.TargetDir, templateData)
if err != nil {
@@ -330,14 +346,29 @@ func generateIDEFiles(options *Options) error {
return nil
}
type ideOptions struct {
name string
targetDir string
options *Options
renameFiles map[string]string
ignoredFiles []string
}
func generateGolandFiles(options *Options) error {
targetDir := filepath.Join(options.TargetDir, ".idea")
renameFiles := map[string]string{
"projectname.iml": options.ProjectNameFilename + ".iml",
"gitignore.txt": ".gitignore",
"name": ".name",
ideoptions := ideOptions{
name: "goland",
targetDir: filepath.Join(options.TargetDir, ".idea"),
options: options,
renameFiles: map[string]string{
"projectname.iml": options.ProjectNameFilename + ".iml",
"gitignore.txt": ".gitignore",
"name": ".name",
},
}
err := installIDEFiles("goland", targetDir, options, renameFiles)
if !options.InitGit {
ideoptions.ignoredFiles = []string{"vcs.xml"}
}
err := installIDEFiles(ideoptions)
if err != nil {
return errors.Wrap(err, "generating Goland IDE files")
}
@@ -346,13 +377,17 @@ func generateGolandFiles(options *Options) error {
}
func generateVSCodeFiles(options *Options) error {
targetDir := filepath.Join(options.TargetDir, ".vscode")
return installIDEFiles("vscode", targetDir, options, nil)
ideoptions := ideOptions{
name: "vscode",
targetDir: filepath.Join(options.TargetDir, ".vscode"),
options: options,
}
return installIDEFiles(ideoptions)
}
func installIDEFiles(ideName string, targetDir string, options *Options, renameFiles map[string]string) error {
source, err := debme.FS(ides, "ides/"+ideName)
func installIDEFiles(o ideOptions) error {
source, err := debme.FS(ides, "ides/"+o.name)
if err != nil {
return err
}
@@ -360,18 +395,22 @@ func installIDEFiles(ideName string, targetDir string, options *Options, renameF
// Use gosod to install the template
installer := gosod.New(source)
if renameFiles != nil {
installer.RenameFiles(renameFiles)
if o.renameFiles != nil {
installer.RenameFiles(o.renameFiles)
}
binaryName := filepath.Base(options.TargetDir)
for _, ignoreFile := range o.ignoredFiles {
installer.IgnoreFile(ignoreFile)
}
binaryName := filepath.Base(o.options.TargetDir)
if runtime.GOOS == "windows" {
// yay windows
binaryName += ".exe"
}
// Parse wails.json for assetdir
wailsJSONBytes, err := os.ReadFile(filepath.Join(options.TargetDir, "wails.json"))
wailsJSONBytes, err := os.ReadFile(filepath.Join(o.options.TargetDir, "wails.json"))
if err != nil {
return err
}
@@ -385,10 +424,16 @@ func installIDEFiles(ideName string, targetDir string, options *Options, renameF
return fmt.Errorf("Unable to find 'assetdir' in 'wails.json' ")
}
options.AssetDir = assetDir.(string)
options.PathToDesktopBinary = filepath.ToSlash(filepath.Join("build", "bin", binaryName))
o.options.AssetDir = assetDir.(string)
o.options.PathToDesktopBinary = filepath.ToSlash(filepath.Join("build", "bin", binaryName))
err = installer.Extract(targetDir, options)
o.options.WindowsFlags = ""
o.options.CGOEnabled = "1"
if runtime.GOOS == "windows" {
o.options.WindowsFlags = " -H windowsgui"
o.options.CGOEnabled = "0"
}
err = installer.Extract(o.targetDir, o.options)
if err != nil {
return err
}

View File

@@ -0,0 +1,9 @@
# Wails bin directory
build/bin
# IDEs
.idea
.vscode
# The black hole that is...
node_modules

View File

@@ -15,6 +15,7 @@ github.com/fasthttp/websocket v0.0.0-20200320073529-1554a54587ab h1:9e2joQGp642w
github.com/fasthttp/websocket v0.0.0-20200320073529-1554a54587ab/go.mod h1:smsv/h4PBEBaU0XDTY5UwJTpZv69fQ0FfcLJr21mA6Y=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flytam/filenamify v1.0.0/go.mod h1:Dzf9kVycwcsBlr2ATg6uxjqiFgKGH+5SKFuhdeP5zu8=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gabriel-vasile/mimetype v1.3.1 h1:qevA6c2MtE1RorlScnixeG0VA1H4xrXyhyX3oWBynNQ=
github.com/gabriel-vasile/mimetype v1.3.1/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8=
@@ -76,7 +77,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leaanthony/clir v1.0.4/go.mod h1:k/RBkdkFl18xkkACMCLt09bhiZnrGORoxmomeMvDpE0=
github.com/leaanthony/debme v1.1.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
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/go-ansi-parser v1.0.1 h1:97v6c5kYppVsbScf4r/VZdXyQ21KQIfeQOk2DgKxGG4=
@@ -85,7 +85,7 @@ github.com/leaanthony/go-common-file-dialog v1.0.3 h1:O0uGjKnWtdEADGrkg+TyAAbZyl
github.com/leaanthony/go-common-file-dialog v1.0.3/go.mod h1:TGhEc9eSJgRsupZ+iH1ZgAOnEo9zp05cRH2j08RPrF0=
github.com/leaanthony/go-webview2 v0.0.0-20210928094513-a94a08b538bd h1:6m4zZ/esiByaDbzgdvDxjsOaIDgtuG1q2cyhjAi6uAg=
github.com/leaanthony/go-webview2 v0.0.0-20210928094513-a94a08b538bd/go.mod h1:lS5ds4bruPk9d7lzdF/OH31Z0YCerI6MmHNFGsWoUnM=
github.com/leaanthony/gosod v1.0.2/go.mod h1:W8RyeSFBXu7RpIxPGEJfW4moSyGGEjlJMLV25wEbAdU=
github.com/leaanthony/gosod v1.0.3/go.mod h1:BJ2J+oHsQIyIQpnLPjnqFGTMnOZXDbvWtRCSG7jGxs4=
github.com/leaanthony/idgen v1.0.0/go.mod h1:4nBZnt8ml/f/ic/EVQuLxuj817RccT2fyrUaZFxrcVA=
github.com/leaanthony/slicer v1.5.0 h1:aHYTN8xbCCLxJmkNKiLB6tgcMARl4eWmH9/F+S/0HtY=
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
@@ -147,8 +147,8 @@ github.com/valyala/fasthttp v1.28.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfY
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/wailsapp/wails/v2 v2.0.0-beta.2 h1:T17fV+EsjPpl4ZWVOEJ94qkCLhBJ0L6qtLkp4eA9C5M=
github.com/wailsapp/wails/v2 v2.0.0-beta.2/go.mod h1:V1CwD423vqoHslofcQpZ49Q7H1eDIKFCS7paSVBBNLw=
github.com/wailsapp/wails/v2 v2.0.0-beta.3 h1:8vhBbnjpYDF6cCUwKadon7J/98UjcP1nrnptUl70Tfg=
github.com/wailsapp/wails/v2 v2.0.0-beta.3/go.mod h1:aku28riyHF2G5jmx/qtxjLWi7VwpTjhhX/HVLCptWFA=
github.com/wzshiming/ctc v1.2.3/go.mod h1:2tVAtIY7SUyraSk0JxvwmONNPFL4ARavPuEsg5+KA28=
github.com/wzshiming/winseq v0.0.0-20200112104235-db357dc107ae/go.mod h1:VTAq37rkGeV+WOybvZwjXiJOicICdpLCN8ifpISjK20=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=

View File

@@ -0,0 +1,9 @@
# Wails bin directory
build/bin
# IDEs
.idea
.vscode
# The black hole that is...
node_modules

View File

@@ -15,6 +15,7 @@ github.com/fasthttp/websocket v0.0.0-20200320073529-1554a54587ab h1:9e2joQGp642w
github.com/fasthttp/websocket v0.0.0-20200320073529-1554a54587ab/go.mod h1:smsv/h4PBEBaU0XDTY5UwJTpZv69fQ0FfcLJr21mA6Y=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flytam/filenamify v1.0.0/go.mod h1:Dzf9kVycwcsBlr2ATg6uxjqiFgKGH+5SKFuhdeP5zu8=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gabriel-vasile/mimetype v1.3.1 h1:qevA6c2MtE1RorlScnixeG0VA1H4xrXyhyX3oWBynNQ=
github.com/gabriel-vasile/mimetype v1.3.1/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8=
@@ -76,7 +77,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leaanthony/clir v1.0.4/go.mod h1:k/RBkdkFl18xkkACMCLt09bhiZnrGORoxmomeMvDpE0=
github.com/leaanthony/debme v1.1.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
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/go-ansi-parser v1.0.1 h1:97v6c5kYppVsbScf4r/VZdXyQ21KQIfeQOk2DgKxGG4=
@@ -85,7 +85,7 @@ github.com/leaanthony/go-common-file-dialog v1.0.3 h1:O0uGjKnWtdEADGrkg+TyAAbZyl
github.com/leaanthony/go-common-file-dialog v1.0.3/go.mod h1:TGhEc9eSJgRsupZ+iH1ZgAOnEo9zp05cRH2j08RPrF0=
github.com/leaanthony/go-webview2 v0.0.0-20210928094513-a94a08b538bd h1:6m4zZ/esiByaDbzgdvDxjsOaIDgtuG1q2cyhjAi6uAg=
github.com/leaanthony/go-webview2 v0.0.0-20210928094513-a94a08b538bd/go.mod h1:lS5ds4bruPk9d7lzdF/OH31Z0YCerI6MmHNFGsWoUnM=
github.com/leaanthony/gosod v1.0.2/go.mod h1:W8RyeSFBXu7RpIxPGEJfW4moSyGGEjlJMLV25wEbAdU=
github.com/leaanthony/gosod v1.0.3/go.mod h1:BJ2J+oHsQIyIQpnLPjnqFGTMnOZXDbvWtRCSG7jGxs4=
github.com/leaanthony/idgen v1.0.0/go.mod h1:4nBZnt8ml/f/ic/EVQuLxuj817RccT2fyrUaZFxrcVA=
github.com/leaanthony/slicer v1.5.0 h1:aHYTN8xbCCLxJmkNKiLB6tgcMARl4eWmH9/F+S/0HtY=
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
@@ -147,8 +147,8 @@ github.com/valyala/fasthttp v1.28.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfY
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/wailsapp/wails/v2 v2.0.0-beta.2 h1:T17fV+EsjPpl4ZWVOEJ94qkCLhBJ0L6qtLkp4eA9C5M=
github.com/wailsapp/wails/v2 v2.0.0-beta.2/go.mod h1:V1CwD423vqoHslofcQpZ49Q7H1eDIKFCS7paSVBBNLw=
github.com/wailsapp/wails/v2 v2.0.0-beta.3 h1:8vhBbnjpYDF6cCUwKadon7J/98UjcP1nrnptUl70Tfg=
github.com/wailsapp/wails/v2 v2.0.0-beta.3/go.mod h1:aku28riyHF2G5jmx/qtxjLWi7VwpTjhhX/HVLCptWFA=
github.com/wzshiming/ctc v1.2.3/go.mod h1:2tVAtIY7SUyraSk0JxvwmONNPFL4ARavPuEsg5+KA28=
github.com/wzshiming/winseq v0.0.0-20200112104235-db357dc107ae/go.mod h1:VTAq37rkGeV+WOybvZwjXiJOicICdpLCN8ifpISjK20=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=

View File

@@ -151,14 +151,16 @@ func updateToVersion(logger *clilogger.CLILogger, targetVersion *github.Semantic
log.Fatal("Cannot find home directory! Please file a bug report!")
}
sout, serr, err := shell.RunCommand(homeDir, "go", "get", "github.com/wailsapp/wails/v2/cmd/wails@"+desiredVersion)
sout, serr, err := shell.RunCommand(homeDir, "go", "install", "github.com/wailsapp/wails/v2/cmd/wails@"+desiredVersion)
if err != nil {
logger.Println("Failed.")
logger.Println(sout + `\n` + serr)
return err
}
fmt.Println()
logger.Println("\n")
logger.Println("Wails CLI updated to " + desiredVersion)
logger.Println("Make sure you update your project go.mod file to use " + desiredVersion + ":")
logger.Println(" require github.com/wailsapp/wails/v2 " + desiredVersion)
return nil
}

View File

@@ -0,0 +1,15 @@
package internal
import "strings"
// ParseUserTags takes the string form of tags and converts to a slice of strings
func ParseUserTags(tagString string) []string {
userTags := make([]string, 0)
for _, tag := range strings.Split(tagString, " ") {
thisTag := strings.TrimSpace(tag)
if thisTag != "" {
userTags = append(userTags, thisTag)
}
}
return userTags
}

View File

@@ -0,0 +1,3 @@
package internal
var Version = "v2.0.0-beta.8"

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/wailsapp/wails/v2/cmd/wails/internal"
"os"
"github.com/wailsapp/wails/v2/internal/colour"
@@ -24,7 +25,7 @@ func fatal(message string) {
func banner(_ *clir.Cli) string {
return fmt.Sprintf("%s %s\n",
colour.Yellow("Wails CLI"),
colour.DarkRed(version))
colour.DarkRed(internal.Version))
}
func printFooter() {
@@ -35,7 +36,7 @@ func main() {
var err error
app := clir.NewCli("Wails", "Go/HTML Appkit", version)
app := clir.NewCli("Wails", "Go/HTML Appkit", internal.Version)
app.SetBannerFunction(banner)
defer printFooter()
@@ -61,14 +62,14 @@ func main() {
fatal(err.Error())
}
err = update.AddSubcommand(app, os.Stdout, version)
err = update.AddSubcommand(app, os.Stdout, internal.Version)
if err != nil {
fatal(err.Error())
}
command := app.NewSubCommand("version", "The Wails CLI version")
command.Action(func() error {
println(version)
println(internal.Version)
return nil
})

View File

@@ -1,3 +0,0 @@
package main
var version = "v2.0.0-beta.3"

View File

@@ -21,7 +21,7 @@ require (
github.com/leaanthony/debme v1.2.1
github.com/leaanthony/go-ansi-parser v1.0.1
github.com/leaanthony/go-common-file-dialog v1.0.3
github.com/leaanthony/go-webview2 v0.0.0-20210928094513-a94a08b538bd
github.com/leaanthony/go-webview2 v0.0.0-20211007095229-b1759d2e4ec7
github.com/leaanthony/gosod v1.0.3
github.com/leaanthony/idgen v1.0.0
github.com/leaanthony/slicer v1.5.0
@@ -41,7 +41,7 @@ require (
github.com/wzshiming/ctc v1.2.3
github.com/xyproto/xpm v1.2.1
github.com/ztrue/tracerr v0.3.0
golang.org/x/mod v0.4.1 // indirect
golang.org/x/mod v0.4.1
golang.org/x/net v0.0.0-20210510120150-4163338589ed
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6
golang.org/x/tools v0.1.0

View File

@@ -117,6 +117,8 @@ github.com/leaanthony/go-common-file-dialog v1.0.3 h1:O0uGjKnWtdEADGrkg+TyAAbZyl
github.com/leaanthony/go-common-file-dialog v1.0.3/go.mod h1:TGhEc9eSJgRsupZ+iH1ZgAOnEo9zp05cRH2j08RPrF0=
github.com/leaanthony/go-webview2 v0.0.0-20210928094513-a94a08b538bd h1:6m4zZ/esiByaDbzgdvDxjsOaIDgtuG1q2cyhjAi6uAg=
github.com/leaanthony/go-webview2 v0.0.0-20210928094513-a94a08b538bd/go.mod h1:lS5ds4bruPk9d7lzdF/OH31Z0YCerI6MmHNFGsWoUnM=
github.com/leaanthony/go-webview2 v0.0.0-20211007095229-b1759d2e4ec7 h1:qw9f/UqPp2GQ318n8G0Ikawe8GRkdPpUNJMuYeeafGA=
github.com/leaanthony/go-webview2 v0.0.0-20211007095229-b1759d2e4ec7/go.mod h1:lS5ds4bruPk9d7lzdF/OH31Z0YCerI6MmHNFGsWoUnM=
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/idgen v1.0.0 h1:IZreR+JGEzFV4yeVuBZA25gM0keUoFy+RDUldncQ+Jw=

View File

@@ -0,0 +1,105 @@
//go:build bindings
// +build bindings
package appng
import (
"github.com/leaanthony/gosod"
"github.com/wailsapp/wails/v2/internal/binding"
wailsRuntime "github.com/wailsapp/wails/v2/internal/frontend/runtime"
"github.com/wailsapp/wails/v2/internal/frontend/runtime/wrapper"
"github.com/wailsapp/wails/v2/internal/fs"
"github.com/wailsapp/wails/v2/internal/logger"
"github.com/wailsapp/wails/v2/internal/project"
"github.com/wailsapp/wails/v2/pkg/options"
"os"
"path/filepath"
)
// App defines a Wails application structure
type App struct {
logger *logger.Logger
appoptions *options.App
}
func (a *App) Run() error {
// Create binding exemptions - Ugly hack. There must be a better way
bindingExemptions := []interface{}{a.appoptions.OnStartup, a.appoptions.OnShutdown, a.appoptions.OnDomReady}
appBindings := binding.NewBindings(a.logger, a.appoptions.Bind, bindingExemptions)
err := generateBindings(appBindings)
if err != nil {
return err
}
return nil
}
// CreateApp creates the app!
func CreateApp(appoptions *options.App) (*App, error) {
// Set up logger
myLogger := logger.New(appoptions.Logger)
myLogger.SetLogLevel(appoptions.LogLevel)
result := &App{
logger: myLogger,
appoptions: appoptions,
}
return result, nil
}
func generateBindings(bindings *binding.Bindings) error {
cwd, err := os.Getwd()
if err != nil {
return err
}
projectConfig, err := project.Load(cwd)
if err != nil {
return err
}
wrapperDir := filepath.Join(projectConfig.WailsJSDir, "wailsjs", "runtime")
_ = os.RemoveAll(wrapperDir)
extractor := gosod.New(wrapper.RuntimeWrapper)
err = extractor.Extract(wrapperDir, nil)
if err != nil {
return err
}
//ipcdev.js
err = os.WriteFile(filepath.Join(wrapperDir, "ipcdev.js"), wailsRuntime.DesktopIPC, 0755)
if err != nil {
return err
}
//runtimedev.js
err = os.WriteFile(filepath.Join(wrapperDir, "runtimedev.js"), wailsRuntime.RuntimeDesktopJS, 0755)
if err != nil {
return err
}
targetDir := filepath.Join(projectConfig.WailsJSDir, "wailsjs", "go")
err = os.RemoveAll(targetDir)
if err != nil {
return err
}
_ = fs.MkDirs(targetDir)
modelsFile := filepath.Join(targetDir, "models.ts")
err = bindings.WriteTS(modelsFile)
if err != nil {
return err
}
// Write backend method wrappers
bindingsFilename := filepath.Join(targetDir, "bindings.js")
err = bindings.GenerateBackendJS(bindingsFilename, true)
if err != nil {
return err
}
return nil
}

View File

@@ -1,4 +1,4 @@
//go:build darwin
//go:build darwin && !bindings
package appng

View File

@@ -1,4 +1,4 @@
//go:build !dev && !production && darwin
//go:build !dev && !production && !bindings && darwin
package appng

View File

@@ -1,4 +1,4 @@
//go:build !dev && !production && windows
//go:build !dev && !production && !bindings && windows
package appng
@@ -24,7 +24,7 @@ Please use "wails build" or press "OK" to open the documentation on how to use "
"Error",
w32.MB_ICONERROR|w32.MB_OKCANCEL)
if result == 1 {
exec.Command("rundll32", "url.dll,FileProtocolHandler", "https://wails.io").Start()
exec.Command("rundll32", "url.dll,FileProtocolHandler", "https://wails.io/docs/guides/manual-builds").Start()
}
return nil, nil
}

View File

@@ -61,11 +61,16 @@ func CreateApp(appoptions *options.App) (*App, error) {
// Check for CLI Flags
assetdir := flag.String("assetdir", "", "Directory to serve assets")
devServerURL := flag.String("devserverurl", "", "URL of development server")
loglevel := flag.String("loglevel", "debug", "Loglevel to use - Trace, Debug, Info, Warning, Error")
flag.Parse()
if devServerURL != nil && *devServerURL != "" {
ctx = context.WithValue(ctx, "devserverurl", *devServerURL)
}
if assetdir != nil && *assetdir != "" {
ctx = context.WithValue(ctx, "assetdir", *assetdir)
}
if loglevel != nil && *loglevel != "" {
level, err := pkglogger.StringToLogLevel(*loglevel)
if err != nil {
@@ -157,7 +162,7 @@ func generateBindings(bindings *binding.Bindings) error {
// Write backend method wrappers
bindingsFilename := filepath.Join(targetDir, "bindings.js")
err = bindings.GenerateBackendJS(bindingsFilename)
err = bindings.GenerateBackendJS(bindingsFilename, false)
if err != nil {
return err
}

View File

@@ -1,4 +1,4 @@
//go:build windows
//go:build windows && !bindings
package appng

View File

@@ -4,18 +4,19 @@ import (
"bytes"
_ "embed"
"fmt"
"github.com/wailsapp/wails/v2/internal/fs"
"os"
"path/filepath"
"strings"
"github.com/wailsapp/wails/v2/internal/fs"
"github.com/leaanthony/slicer"
)
//go:embed assets/package.json
var packageJSON []byte
func (b *Bindings) GenerateBackendJS(targetfile string) error {
func (b *Bindings) GenerateBackendJS(targetfile string, isDevBindings bool) error {
store := b.db.store
var output bytes.Buffer
@@ -23,8 +24,18 @@ func (b *Bindings) GenerateBackendJS(targetfile string) error {
output.WriteString(`// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
`)
const go = {`)
if isDevBindings {
json, err := b.ToJSON()
if err != nil {
return err
}
output.WriteString("window.wailsbindings = " + json + ";")
output.WriteString("\n")
}
output.WriteString(`const go = {`)
output.WriteString("\n")
var sortedPackageNames slicer.StringSlicer
@@ -93,7 +104,7 @@ const go = {`)
output.WriteString("\n")
})
output.WriteString(fmt.Sprintf(" }\n"))
output.WriteString(fmt.Sprintf(" },\n"))
output.WriteString("\n")
})

View File

@@ -21,63 +21,63 @@ import (
"os"
)
type AssetServer struct {
indexFile []byte
type BrowserAssetServer struct {
runtimeJS []byte
assetdir string
appOptions *options.App
}
func NewAssetServer(assetdir string, bindingsJSON string, appOptions *options.App) (*AssetServer, error) {
result := &AssetServer{
func NewBrowserAssetServer(assetdir string, bindingsJSON string, appOptions *options.App) (*BrowserAssetServer, error) {
result := &BrowserAssetServer{
assetdir: assetdir,
appOptions: appOptions,
}
err := result.init()
if err != nil {
return nil, err
}
var buffer bytes.Buffer
buffer.WriteString(`window.wailsbindings='` + bindingsJSON + `';` + "\n")
buffer.Write(runtime.RuntimeDesktopJS)
result.runtimeJS = buffer.Bytes()
err = result.init()
return result, err
return result, nil
}
func (a *AssetServer) loadFileFromDisk(filename string) ([]byte, error) {
func (a *BrowserAssetServer) loadFileFromDisk(filename string) ([]byte, error) {
return os.ReadFile(filepath.Join(a.assetdir, filename))
}
func (a *AssetServer) init() error {
var err error
a.indexFile, err = a.loadFileFromDisk("index.html")
func (a *BrowserAssetServer) processIndexHTML() ([]byte, error) {
indexHTML, err := a.loadFileFromDisk("index.html")
if err != nil {
return err
return nil, err
}
a.indexFile, err = injectHTML(string(a.indexFile), `<div id="wails-spinner"></div>`)
indexHTML, err = injectHTML(string(indexHTML), `<div id="wails-spinner"></div>`)
if err != nil {
return err
return nil, err
}
a.indexFile, err = injectHTML(string(a.indexFile), `<script src="/wails/ipc.js"></script>`)
wailsOptions, err := extractOptions(indexHTML)
if err != nil {
return err
return nil, err
}
a.indexFile, err = injectHTML(string(a.indexFile), `<script src="/wails/runtime.js"></script>`)
if err != nil {
return err
if wailsOptions.disableRuntimeInjection == false {
indexHTML, err = injectHTML(string(indexHTML), `<script src="/wails/runtime.js"></script>`)
if err != nil {
return nil, err
}
}
return nil
if wailsOptions.disableIPCInjection == false {
indexHTML, err = injectHTML(string(indexHTML), `<script src="/wails/ipc.js"></script>`)
if err != nil {
return nil, err
}
}
return indexHTML, nil
}
func (a *AssetServer) Load(filename string) ([]byte, string, error) {
func (a *BrowserAssetServer) Load(filename string) ([]byte, string, error) {
var content []byte
var err error
switch filename {
case "/":
content = a.indexFile
content, err = a.processIndexHTML()
case "/wails/runtime.js":
content = a.runtimeJS
case "/wails/ipc.js":

View File

@@ -10,13 +10,13 @@ import (
"github.com/wailsapp/wails/v2/internal/frontend/runtime"
"github.com/wailsapp/wails/v2/internal/logger"
"io/fs"
"log"
"path/filepath"
"strings"
)
type DesktopAssetServer struct {
assets debme.Debme
indexFile []byte
runtimeJS []byte
assetdir string
logger *logger.Logger
@@ -106,27 +106,41 @@ func (a *DesktopAssetServer) init(assets embed.FS) error {
if err != nil {
return err
}
indexHTML, err := a.assets.ReadFile("index.html")
if err != nil {
return err
}
a.indexFile, err = injectHTML(string(indexHTML), `<script src="/wails/runtime.js"></script>`)
if err != nil {
return err
}
a.indexFile, err = injectHTML(string(a.indexFile), `<script src="/wails/ipc.js"></script>`)
if err != nil {
return err
}
return nil
}
func (a *DesktopAssetServer) processIndexHTML() ([]byte, error) {
indexHTML, err := a.ReadFile("index.html")
if err != nil {
return nil, err
}
wailsOptions, err := extractOptions(indexHTML)
if err != nil {
log.Fatal(err)
return nil, err
}
if wailsOptions.disableRuntimeInjection == false {
indexHTML, err = injectHTML(string(indexHTML), `<script src="/wails/runtime.js"></script>`)
if err != nil {
return nil, err
}
}
if wailsOptions.disableIPCInjection == false {
indexHTML, err = injectHTML(string(indexHTML), `<script src="/wails/ipc.js"></script>`)
if err != nil {
return nil, err
}
}
return indexHTML, nil
}
func (a *DesktopAssetServer) Load(filename string) ([]byte, string, error) {
var content []byte
var err error
switch filename {
case "/":
content = a.indexFile
content, err = a.processIndexHTML()
case "/wails/runtime.js":
content = a.runtimeJS
case "/wails/ipc.js":

View File

@@ -3,19 +3,86 @@ package assetserver
import (
"bytes"
"fmt"
"golang.org/x/net/html"
"strings"
)
type optionType string
const (
noAutoInject optionType = "noautoinject"
noAutoInjectRuntime optionType = "noautoinjectruntime"
noautoinjectipc optionType = "noautoinjectipc"
)
type Options struct {
disableRuntimeInjection bool
disableIPCInjection bool
}
func newOptions(optionString string) *Options {
var result = &Options{}
optionString = strings.ToLower(optionString)
options := strings.Split(optionString, ",")
for _, option := range options {
switch optionType(strings.TrimSpace(option)) {
case noAutoInject:
result.disableRuntimeInjection = true
result.disableIPCInjection = true
case noautoinjectipc:
result.disableIPCInjection = true
case noAutoInjectRuntime:
result.disableRuntimeInjection = true
}
}
return result
}
func injectHTML(input string, html string) ([]byte, error) {
splits := strings.Split(input, "</body>")
splits := strings.Split(input, "</head>")
if len(splits) != 2 {
return nil, fmt.Errorf("unable to locate a </body> tag in your html")
return nil, fmt.Errorf("unable to locate a </head> tag in your html")
}
var result bytes.Buffer
result.WriteString(splits[0])
result.WriteString(html)
result.WriteString("</body>")
result.WriteString("</head>")
result.WriteString(splits[1])
return result.Bytes(), nil
}
func extractOptions(htmldata []byte) (*Options, error) {
doc, err := html.Parse(bytes.NewReader(htmldata))
if err != nil {
return nil, err
}
var extractor func(*html.Node) *Options
extractor = func(node *html.Node) *Options {
if node.Type == html.ElementNode && node.Data == "meta" {
isWailsOptionsTag := false
wailsOptions := ""
for _, attr := range node.Attr {
if isWailsOptionsTag && attr.Key == "content" {
wailsOptions = attr.Val
}
if attr.Val == "wails-options" {
isWailsOptionsTag = true
}
}
return newOptions(wailsOptions)
}
for child := node.FirstChild; child != nil; child = child.NextSibling {
result := extractor(child)
if result != nil {
return result
}
}
return nil
}
result := extractor(doc)
if result == nil {
result = &Options{}
}
return result, nil
}

View File

@@ -0,0 +1,70 @@
package assetserver
import (
"reflect"
"testing"
)
const realHTML = `<html>
<head>
<title>test3</title>
<meta name="wails-options" content="noautoinject">
<link rel="stylesheet" href="/main.css">
</head>
<body data-wails-drag>
<div class="logo"></div>
<div class="result" id="result">Please enter your name below <20></div>
<div class="input-box" id="input" data-wails-no-drag>
<input class="input" id="name" type="text" autocomplete="off">
<button class="btn" onclick="greet()">Greet</button>
</div>
<script src="/main.js"></script>
</body>
</html>
`
func genMeta(content string) []byte {
return []byte("<html><head><meta name=\"wails-options\" content=\"" + content + "\"></head><body></body></html>")
}
func genOptions(runtime bool, bindings bool) *Options {
return &Options{
disableRuntimeInjection: runtime,
disableIPCInjection: bindings,
}
}
func Test_extractOptions(t *testing.T) {
tests := []struct {
name string
htmldata []byte
want *Options
wantError bool
}{
{"empty", []byte(""), &Options{}, false},
{"bad data", []byte("<"), &Options{}, false},
{"bad options", genMeta("noauto"), genOptions(false, false), false},
{"realhtml", []byte(realHTML), genOptions(true, true), false},
{"noautoinject", genMeta("noautoinject"), genOptions(true, true), false},
{"noautoinjectipc", genMeta("noautoinjectipc"), genOptions(false, true), false},
{"noautoinjectruntime", genMeta("noautoinjectruntime"), genOptions(true, false), false},
{"spaces", genMeta(" noautoinjectruntime "), genOptions(true, false), false},
{"multiple", genMeta("noautoinjectruntime,noautoinjectipc"), genOptions(true, true), false},
{"multiple spaces", genMeta(" noautoinjectruntime, noautoinjectipc "), genOptions(true, true), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := extractOptions(tt.htmldata)
if !tt.wantError && err != nil {
t.Errorf("did not want error but got it")
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("extractOptions() = %v, want %v", got, tt.want)
}
})
}
}

View File

@@ -35,7 +35,7 @@ func GetMimetype(filename string, data []byte) string {
}
if filepath.Ext(filename) == ".js" && strings.HasPrefix(result, "text/plain") {
result = strings.Replace(result, "text/plain", "application/javascript", 1)
result = strings.Replace(result, "text/plain", "text/javascript", 1)
}
if result == "" {

View File

@@ -14,7 +14,7 @@ func TestGetMimetype(t *testing.T) {
}{
// TODO: Add test cases.
{"css", args{"test.css", []byte("body{margin:0;padding:0;background-color:#d579b2}#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;background-color:#ededed}#nav{padding:30px}#nav a{font-weight:700;color:#2c\n3e50}#nav a.router-link-exact-active{color:#42b983}.hello[data-v-4e26ad49]{margin:10px 0}")}, "text/css; charset=utf-8"},
{"js", args{"test.js", []byte("let foo = 'bar'; console.log(foo);")}, "application/javascript; charset=utf-8"},
{"js", args{"test.js", []byte("let foo = 'bar'; console.log(foo);")}, "text/javascript; charset=utf-8"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

View File

@@ -5,6 +5,7 @@ package darwin
import (
"context"
"encoding/json"
"html/template"
"log"
"runtime"
@@ -310,7 +311,7 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
f.logger.Error(err.Error())
return
}
f.ExecJS(`window.wails.EventsNotify('` + string(payload) + `');`)
f.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`)
}
//func (f *Frontend) processRequest(req *edge.ICoreWebView2WebResourceRequest, args *edge.ICoreWebView2WebResourceRequestedEventArgs) {

View File

@@ -11,8 +11,7 @@ import (
"runtime"
"strconv"
"strings"
"github.com/leaanthony/slicer"
"text/template"
"github.com/leaanthony/go-webview2/pkg/edge"
"github.com/leaanthony/winc"
@@ -35,7 +34,8 @@ type Frontend struct {
debug bool
// Assets
assets *assetserver.DesktopAssetServer
assets *assetserver.DesktopAssetServer
startURL string
// main window handle
mainWindow *Window
@@ -57,21 +57,33 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
minWidth: appoptions.MinWidth,
maxHeight: appoptions.MaxHeight,
maxWidth: appoptions.MaxWidth,
}
// Check if we have been given a directory to serve assets from.
// If so, this means we are in dev mode and are serving assets off disk.
// We indicate this through the `servingFromDisk` flag to ensure requests
// aren't cached by WebView2 in dev mode
_assetdir := ctx.Value("assetdir")
if _assetdir != nil {
result.servingFromDisk = true
startURL: "file://wails/",
}
bindingsJSON, err := appBindings.ToJSON()
if err != nil {
log.Fatal(err)
}
_devServerURL := ctx.Value("devserverurl")
if _devServerURL != nil {
devServerURL := _devServerURL.(string)
if len(devServerURL) > 0 && devServerURL != "http://localhost:34115" {
result.startURL = devServerURL
return result
}
}
// Check if we have been given a directory to serve assets from.
// If so, this means we are in dev mode and are serving assets off disk.
// We indicate this through the `servingFromDisk` flag to ensure requests
// aren't cached by WebView2 in dev mode
_assetdir := ctx.Value("assetdir")
if _assetdir != nil {
result.servingFromDisk = true
}
assets, err := assetserver.NewDesktopAssetServer(ctx, appoptions.Assets, bindingsJSON)
if err != nil {
log.Fatal(err)
@@ -264,16 +276,9 @@ func (f *Frontend) setupChromium() {
chromium.MessageCallback = f.processMessage
chromium.WebResourceRequestedCallback = f.processRequest
chromium.NavigationCompletedCallback = f.navigationCompleted
acceleratorsWebviewShouldProcess := slicer.Int([]int{ctrlV, ctrlC, ctrlX, ctrlZ, ctrlA, arrowLeft, arrowRight, arrowUp, arrowDown, keyDel})
chromium.AcceleratorKeyCallback = func(vkey uint) bool {
// We want webview to handle ctrl-C, ctrl-Z, ctrl-v, ctrl-x
if acceleratorsWebviewShouldProcess.Contains(int(vkey)) {
return false
}
// Post keypress
w32.PostMessage(f.mainWindow.Handle(), w32.WM_KEYDOWN, uintptr(vkey), 0)
return true
return false
}
chromium.Embed(f.mainWindow.Handle())
chromium.Resize()
@@ -297,7 +302,7 @@ func (f *Frontend) setupChromium() {
if err != nil {
log.Fatal(err)
}
err = settings.PutIsStatusBarEnabled(false)
err = settings.PutAreBrowserAcceleratorKeysEnabled(false)
if err != nil {
log.Fatal(err)
}
@@ -306,7 +311,7 @@ func (f *Frontend) setupChromium() {
f.WindowSetRGBA(f.frontendOptions.RGBA)
chromium.AddWebResourceRequestedFilter("*", edge.COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL)
chromium.Navigate("file://wails/")
chromium.Navigate(f.startURL)
}
type EventNotify struct {
@@ -324,7 +329,7 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
f.logger.Error(err.Error())
return
}
f.ExecJS(`window.wails.EventsNotify('` + string(payload) + `');`)
f.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`)
}
func (f *Frontend) processRequest(req *edge.ICoreWebView2WebResourceRequest, args *edge.ICoreWebView2WebResourceRequestedEventArgs) {

View File

@@ -33,7 +33,7 @@ type DevWebServer struct {
logger *logger.Logger
appBindings *binding.Bindings
dispatcher frontend.Dispatcher
assetServer *assetserver.AssetServer
assetServer *assetserver.BrowserAssetServer
socketMutex sync.Mutex
websocketClients map[*websocket.Conn]struct{}
menuManager *menumanager.Manager
@@ -93,47 +93,54 @@ func (d *DevWebServer) Run(ctx context.Context) error {
}
}))
_assetdir := ctx.Value("assetdir")
if _assetdir == nil {
return fmt.Errorf("no assetdir provided")
_devServerURL := ctx.Value("devserverurl")
if _devServerURL == "http://localhost:34115" {
// Setup internal dev server
_assetdir := ctx.Value("assetdir")
if _assetdir == nil {
return fmt.Errorf("no assetdir provided")
}
if _assetdir != nil {
assetdir := _assetdir.(string)
bindingsJSON, err := d.appBindings.ToJSON()
if err != nil {
log.Fatal(err)
}
d.assetServer, err = assetserver.NewBrowserAssetServer(assetdir, bindingsJSON, d.appoptions)
if err != nil {
log.Fatal(err)
}
absdir, err := filepath.Abs(assetdir)
if err != nil {
return err
}
d.LogDebug("Serving assets from: %s", absdir)
}
d.server.Get("*", d.loadAsset)
// Start server
go func(server *fiber.App, log *logger.Logger) {
err := server.Listen("localhost:34115")
if err != nil {
log.Error(err.Error())
}
d.LogDebug("Shutdown completed")
}(d.server, d.logger)
d.LogDebug("Serving application at http://localhost:34115")
defer func() {
err := d.server.Shutdown()
if err != nil {
d.logger.Error(err.Error())
}
}()
}
if _assetdir != nil {
assetdir := _assetdir.(string)
bindingsJSON, err := d.appBindings.ToJSON()
if err != nil {
log.Fatal(err)
}
d.assetServer, err = assetserver.NewAssetServer(assetdir, bindingsJSON, d.appoptions)
if err != nil {
log.Fatal(err)
}
absdir, err := filepath.Abs(assetdir)
if err != nil {
return err
}
d.LogDebug("Serving assets from: %s", absdir)
}
d.server.Get("*", d.loadAsset)
// Start server
go func(server *fiber.App, log *logger.Logger) {
err := server.Listen(":34115")
if err != nil {
log.Error(err.Error())
}
d.LogDebug("Shutdown completed")
}(d.server, d.logger)
d.LogDebug("Serving application at http://localhost:34115")
// Launch desktop app
err := d.desktopFrontend.Run(ctx)
d.LogDebug("Starting shutdown")
err2 := d.server.Shutdown()
if err2 != nil {
d.logger.Error(err.Error())
}
return err
}
@@ -358,6 +365,7 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
appBindings: appBindings,
dispatcher: dispatcher,
server: fiber.New(fiber.Config{
ReadTimeout: time.Second * 5,
DisableStartupMessage: true,
}),

View File

@@ -10,25 +10,22 @@ The electron alternative for Go
/* jshint esversion: 6 */
/**
* SendMessage sends the given message to the backend
* WailsInvoke sends the given message to the backend
*
* @param {string} message
*/
// const windows = 0;
// const macos = 1;
// const linux = 2;
(function () {
// Credit: https://stackoverflow.com/a/2631521
let _deeptest = function (s) {
var obj = window[s.shift()];
while (obj && s.length) obj = obj[s.shift()];
return obj;
};
window.WailsInvoke = _deeptest(["chrome", "webview", "postMessage"]) ||
_deeptest(["webkit", "messageHandlers", "external", "postMessage"]);
window.WailsInvoke = function (message) {
// Call Platform specific invoke method
if (PLATFORM === 0) {
window.chrome.webview.postMessage(message);
} else if (PLATFORM === 1) {
window.webkit.messageHandlers.external.postMessage(message);
} else if (PLATFORM === 2) {
console.error("Unsupported Platform");
} else {
if (!window.WailsInvoke) {
console.error("Unsupported Platform");
}
};
})();

View File

@@ -60,21 +60,24 @@ function handleDisconnect() {
connect();
}
// Try to connect to the backend every 1s (default value).
function _connect() {
if (websocket == null) {
websocket = new WebSocket('ws://' + window.location.hostname + ':34115/wails/ipc');
websocket.onopen = handleConnect;
websocket.onerror = function (e) {
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
websocket = null;
return false;
};
}
}
// Try to connect to the backend every .5s
function connect() {
connectTimer = setInterval(function () {
if (websocket == null) {
websocket = new WebSocket('ws://' + window.location.hostname + ':34115/wails/ipc');
websocket.onopen = handleConnect;
websocket.onerror = function (e) {
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
websocket = null;
return false;
};
}
}, 250);
_connect();
connectTimer = setInterval(_connect, 500);
}
function handleMessage(message) {

View File

@@ -1,8 +1,8 @@
//go:build windows
//go:build darwin || windows
package runtime
import _ "embed"
//go:embed ipc_windows.js
//go:embed ipc.js
var DesktopIPC []byte

View File

@@ -0,0 +1 @@
(()=>{(function(){let n=function(o){for(var e=window[o.shift()];e&&o.length;)e=e[o.shift()];return e};window.WailsInvoke=n(["chrome","webview","postMessage"])||n(["webkit","messageHandlers","external","postMessage"]),window.WailsInvoke||console.error("Unsupported Platform")})();})();

View File

@@ -1,8 +0,0 @@
//go:build darwin
package runtime
import _ "embed"
//go:embed ipc_darwin.js
var DesktopIPC []byte

View File

@@ -1 +0,0 @@
(()=>{window.WailsInvoke=function(e){window.webkit.messageHandlers.external.postMessage(e)};})();

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
(()=>{window.WailsInvoke=function(e){window.chrome.webview.postMessage(e)};})();

View File

@@ -5,8 +5,7 @@
"main": "index.js",
"scripts": {
"build": "run-p build:*",
"build:ipc-windows": "esbuild desktop/ipc.js --bundle --minify --outfile=ipc_windows.js --define:PLATFORM=0",
"build:ipc-darwin": "esbuild desktop/ipc.js --bundle --minify --outfile=ipc_darwin.js --define:PLATFORM=1",
"build:ipc-desktop": "esbuild desktop/ipc.js --bundle --minify --outfile=ipc.js",
"build:ipc-dev": "cd dev && npm run build",
"build:runtime-desktop-prod": "esbuild desktop/main.js --bundle --minify --outfile=runtime_prod_desktop.js --define:ENV=1",
"build:runtime-desktop-dev": "esbuild desktop/main.js --bundle --sourcemap=inline --outfile=runtime_dev_desktop.js --define:ENV=0",

View File

@@ -1,4 +1,4 @@
//go:build dev
//go:build dev || bindings || (!dev && !production && !bindings)
package runtime

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,56 @@
package gomod
import (
"fmt"
"github.com/Masterminds/semver"
"golang.org/x/mod/modfile"
)
func GetWailsVersionFromModFile(goModText []byte) (*semver.Version, error) {
file, err := modfile.Parse("", goModText, nil)
if err != nil {
return nil, err
}
for _, req := range file.Require {
if req.Syntax == nil {
continue
}
if len(req.Syntax.Token) < 3 {
continue
}
if req.Syntax.Token[1] == "github.com/wailsapp/wails/v2" {
version := req.Syntax.Token[2]
return semver.NewVersion(version)
}
}
return nil, nil
}
func GoModOutOfSync(goModData []byte, currentVersion string) (bool, error) {
gomodversion, err := GetWailsVersionFromModFile(goModData)
if err != nil {
return false, err
}
result, err := semver.NewVersion(currentVersion)
if err != nil {
return false, fmt.Errorf("Unable to parse Wails version: %s", currentVersion)
}
return !gomodversion.Equal(result), nil
}
func UpdateGoModVersion(goModText []byte, currentVersion string) ([]byte, error) {
file, err := modfile.Parse("", goModText, nil)
if err != nil {
return nil, err
}
err = file.AddRequire("github.com/wailsapp/wails/v2", currentVersion)
if err != nil {
return nil, err
}
return file.Format()
}

View File

@@ -0,0 +1,139 @@
package gomod
import (
"github.com/Masterminds/semver"
"reflect"
"testing"
)
const basic string = `module changeme
go 1.17
require github.com/wailsapp/wails/v2 v2.0.0-beta.8
require (
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fasthttp/websocket v0.0.0-20200320073529-1554a54587ab // indirect
github.com/gabriel-vasile/mimetype v1.3.1 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/gofiber/fiber/v2 v2.17.0 // indirect
github.com/gofiber/websocket/v2 v2.0.8 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/klauspost/compress v1.12.2 // indirect
github.com/leaanthony/debme v1.2.1 // indirect
github.com/leaanthony/go-ansi-parser v1.0.1 // indirect
github.com/leaanthony/go-common-file-dialog v1.0.3 // indirect
github.com/leaanthony/go-webview2 v0.0.0-20211007092718-65d2f028ef2d // indirect
github.com/leaanthony/gosod v1.0.3 // indirect
github.com/leaanthony/slicer v1.5.0 // indirect
github.com/leaanthony/typescriptify-golang-structs v0.1.7 // indirect
github.com/leaanthony/webview2runtime v1.1.0 // indirect
github.com/leaanthony/winc v0.0.0-20210921073452-54963136bf18 // indirect
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f // indirect
github.com/tkrajina/go-reflector v0.5.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.28.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/net v0.0.0-20210510120150-4163338589ed // indirect
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
)
//replace github.com/wailsapp/wails/v2 v2.0.0-beta.8 => C:\Users\leaan\Documents\wails-v2-beta\wails\v2
`
func TestGetWailsVersion(t *testing.T) {
tests := []struct {
name string
goModText []byte
want *semver.Version
wantErr bool
}{
{"basic", []byte(basic), semver.MustParse("v2.0.0-beta.8"), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetWailsVersionFromModFile(tt.goModText)
if (err != nil) != tt.wantErr {
t.Errorf("GetWailsVersion() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetWailsVersion() got = %v, want %v", got, tt.want)
}
})
}
}
const basicUpdated string = `module changeme
go 1.17
require github.com/wailsapp/wails/v2 v2.0.0-beta.8
require (
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fasthttp/websocket v0.0.0-20200320073529-1554a54587ab // indirect
github.com/gabriel-vasile/mimetype v1.3.1 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/gofiber/fiber/v2 v2.17.0 // indirect
github.com/gofiber/websocket/v2 v2.0.8 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/klauspost/compress v1.12.2 // indirect
github.com/leaanthony/debme v1.2.1 // indirect
github.com/leaanthony/go-ansi-parser v1.0.1 // indirect
github.com/leaanthony/go-common-file-dialog v1.0.3 // indirect
github.com/leaanthony/go-webview2 v0.0.0-20211007092718-65d2f028ef2d // indirect
github.com/leaanthony/gosod v1.0.3 // indirect
github.com/leaanthony/slicer v1.5.0 // indirect
github.com/leaanthony/typescriptify-golang-structs v0.1.7 // indirect
github.com/leaanthony/webview2runtime v1.1.0 // indirect
github.com/leaanthony/winc v0.0.0-20210921073452-54963136bf18 // indirect
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f // indirect
github.com/tkrajina/go-reflector v0.5.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.28.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/net v0.0.0-20210510120150-4163338589ed // indirect
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
)
//replace github.com/wailsapp/wails/v2 v2.0.0-beta.8 => C:\Users\leaan\Documents\wails-v2-beta\wails\v2
`
func TestUpdateGoModVersion(t *testing.T) {
type args struct {
goModText []byte
currentVersion string
}
tests := []struct {
name string
args args
want []byte
wantErr bool
}{
{"basic", args{[]byte(basic), "v2.0.0-beta.8"}, []byte(basicUpdated), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := UpdateGoModVersion(tt.args.goModText, tt.args.currentVersion)
if (err != nil) != tt.wantErr {
t.Errorf("UpdateGoModVersion() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("UpdateGoModVersion() got = %v, want %v", string(got), string(tt.want))
}
})
}
}

View File

@@ -69,3 +69,7 @@ func (p *Process) Kill() error {
func (p *Process) PID() int {
return p.cmd.Process.Pid
}
func (p *Process) SetDir(dir string) {
p.cmd.Dir = dir
}

View File

@@ -18,6 +18,7 @@ type Project struct {
BuildCommand string `json:"frontend:build"`
InstallCommand string `json:"frontend:install"`
DevCommand string `json:"frontend:dev"`
// Directory to generate the API Module
WailsJSDir string `json:"wailsjsdir"`
@@ -46,6 +47,12 @@ type Project struct {
// Fully qualified filename
filename string
// The debounce time for hot-reload of the built-in dev server. Default 100
DebounceMS int `json:"debounceMS"`
// The url to use to server assets. Default "https://localhost:34115"
DevServerURL string `json:"devserverurl"`
}
func (p *Project) Save() error {

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"github.com/leaanthony/gosod"
wailsRuntime "github.com/wailsapp/wails/v2/internal/frontend/runtime"
"github.com/wailsapp/wails/v2/internal/frontend/runtime/wrapper"
"io/ioutil"
"os"
@@ -377,7 +378,22 @@ func generateRuntimeWrapper(options *Options) error {
wrapperDir := filepath.Join(options.WailsJSDir, "wailsjs", "runtime")
_ = os.RemoveAll(wrapperDir)
extractor := gosod.New(wrapper.RuntimeWrapper)
return extractor.Extract(wrapperDir, nil)
err := extractor.Extract(wrapperDir, nil)
if err != nil {
return err
}
//ipcdev.js
err = os.WriteFile(filepath.Join(wrapperDir, "ipcdev.js"), wailsRuntime.DesktopIPC, 0755)
if err != nil {
return err
}
//runtimedev.js
err = os.WriteFile(filepath.Join(wrapperDir, "runtimedev.js"), wailsRuntime.RuntimeDesktopJS, 0755)
if err != nil {
return err
}
return nil
}
// NpmInstall runs "npm install" in the given directory

View File

@@ -1,34 +0,0 @@
name: Deploy mirror | 部署镜像
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-deploy:
name: Automatic deployment | 自动部署
runs-on: ubuntu-latest
if: github.repository == 'misitebao/wails-docs'
steps:
- name: Checkout | 切换到部署分支
uses: actions/checkout@v2
with:
ref: "main"
submodules: true
fetch-depth: 0
- name: Build Site | 构建网站
run: |
npm install && npm run build
# - name: Deploy to Server | 部署到服务器
# uses: hengkx/ssh-deploy@v1.0.1
# with:
# HOST: ${{ secrets.DEPLOY_HOST }}
# USERNAME: ${{ secrets.DEPLOY_HOST_USER }}
# PASSWORD: ${{ secrets.DEPLOY_HOST_PASSWORD }}
# SOURCE: "build"
# TARGET: "/www/wwwroot/beta.wails.top"

View File

@@ -22,4 +22,6 @@ Example: `wails init -n "Your Project Name" -t https://github.com/misitebao/wail
## Vue
- [wails-template-vue](https://github.com/misitebao/wails-template-vue) - A template using vue and vue-router
- [wails-vite-vue-ts](https://github.com/codydbentley/wails-vite-vue-ts) - Vue 3 TypeScript with Vite (and instructions to add features)
- [wails-vite-vue-the-works](https://github.com/codydbentley/wails-vite-vue-the-works) - Vue 3 TypeScript with Vite, Vuex, Vue Router, Sass, and ESLint + Prettier

View File

@@ -61,6 +61,15 @@ sidebar_position: 99
<a href="https://github.com/marcus-crane" style="width:50px">
<img src="https://github.com/marcus-crane.png?size=50" width="50"/>
</a>
<a href="https://github.com/codydbentley" style="width:65px">
<img src="https://github.com/codydbentley.png?size=65" width="65"/>
</a>
<a href="https://github.com/bbergshaven" style="width:45px">
<img src="https://github.com/bbergshaven.png?size=45" width="45"/>
</a>
<a href="https://github.com/Gilgames000" style="width:45px">
<img src="https://github.com/Gilgames000.png?size=45" width="45"/>
</a>
`,
}}
/>

View File

@@ -6,16 +6,16 @@ sidebar_position: 1
## Supported Platforms
- Windows 10
- MacOS x64 & arm64 (due October '21)
- Linux (due December '21)
- Windows 10
- MacOS x64 & arm64 (due October '21)
- Linux (due December '21)
## Dependencies
Wails has a number of common dependencies that are required before installation:
- Go 1.17+
- npm (Node 14+)
- Go 1.17+
- npm (Node 14+)
### Go
@@ -23,8 +23,8 @@ Download Go from the [Go Downloads Page](https://golang.org/dl/).
Ensure that you follow the official [Go installation instructions](https://golang.org/doc/install#install). You will also need to ensure that your `PATH` environment variable also includes the path to your `~/go/bin` directory. Restart your terminal and do the following checks:
* Check Go is installed correctly: `go version`
* Check "~/go/bin" is in your PATH variable: `echo $PATH | grep go/bin`
- Check Go is installed correctly: `go version`
- Check "~/go/bin" is in your PATH variable: `echo $PATH | grep go/bin`
### npm
@@ -36,35 +36,33 @@ Run `npm --version` to verify.
You will also need to install platform specific dependencies:
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
<Tabs
defaultValue="Windows"
values={[
{label: 'Windows', value: 'Windows'},
{label: 'MacOS', value: 'MacOS'},
{label: 'Linux', value: 'Linux'},
]}>
<TabItem value="MacOS">
Coming Soon...
</TabItem>
{ label: "Windows", value: "Windows" },
{ label: "MacOS", value: "MacOS" },
{ label: "Linux", value: "Linux" },
]}
>
<TabItem value="MacOS">Coming Soon...</TabItem>
<TabItem value="Windows">
Wails requires that the <a href='https://developer.microsoft.com/en-us/microsoft-edge/webview2/'>WebView2</a> runtime is installed.
Some Windows installations will already have this installed. You can check using the `wails doctor` command (see below).
</TabItem>
<TabItem value="Linux">
Coming Soon...
Wails requires that the <a href="https://developer.microsoft.com/en-us/microsoft-edge/webview2/">WebView2</a>{" "}
runtime is installed. Some Windows installations will already have this installed. You can check using the{" "}
<code>wails doctor</code> command (see below).
</TabItem>
<TabItem value="Linux">Coming Soon...</TabItem>
</Tabs>
## Optional Dependencies
- [UPX](https://upx.github.io/) for compressing your applications.
- [UPX](https://upx.github.io/) for compressing your applications.
## Installing Wails
Run `go install github.com/wailsapp/wails/v2/cmd/wails@v2.0.0-beta.2` to install the Wails CLI.
Run `go install github.com/wailsapp/wails/v2/cmd/wails@v2.0.0-beta.8` to install the Wails CLI.
## System Check

View File

@@ -161,11 +161,20 @@ The second, if given, will be executed in the `frontend` directory to build the
If these 2 keys aren't given, then Wails does absolutely nothing with the frontend. It is only expecting that `embed.FS`.
## Live Reloading
## Built in Dev Server
Running `wails dev` will start a file watcher in your project directory. By default, if any file changes, wails checks
if it was an application file (default: `.go`, configurable with `-e` flag). If it was, then it will rebuild your
application and relaunch it. If the changed file was in the `assetdir` directory, it will issue a reload.
Running `wails dev` will start the built in dev server which will start a file watcher in your project directory. By
default, if any file changes, wails checks if it was an application file (default: `.go`, configurable with `-e` flag).
If it was, then it will rebuild your application and relaunch it. If the changed file was in the `assetdir` directory,
it will issue a reload after a short amount of time.
The dev server uses a technique called "debouncing" which means it doesn't reload straight away,
as there may be multiple files changed in a short amount of time. When a trigger occurs, it waits for a set amount of time
before issuing a reload. If another trigger happens, it resets to the wait time again. By default this value is `100ms`.
If this value doesn't work for your project, it can be configured using the `-debounce` flag. If used, this value will
be saved to your project config and become the default.
## External Dev Server
Some frameworks come with their own live-reloading server, however they will not be able to take advantage of the Wails
Go bindings. In this scenario, it is best to run a watcher script that rebuilds the project into the build directory, which

View File

@@ -0,0 +1,77 @@
# Frontend
## Script Injection
When Wails serves your `index.html`, by default, it will inject 2 script entries into the `<body>` tag to load `/wails/bindings.js`
and `/wails/runtime.js`. These files install the bindings and runtime respectively.
The code below shows where these are injected by default:
```html
<html>
<head>
<title>injection example</title>
<link rel="stylesheet" href="/main.css">
<!-- <script src="/wails/ipc.js"></script> -->
<!-- <script src="/wails/runtime.js"></script> -->
</head>
<body data-wails-drag>
<div class="logo"></div>
<div class="result" id="result">Please enter your name below 👇</div>
<div class="input-box" id="input" data-wails-no-drag>
<input class="input" id="name" type="text" autocomplete="off">
<button class="btn" onclick="greet()">Greet</button>
</div>
<script src="/main.js"></script>
</body>
</html>
```
### Overriding Default Script Injection
To provide more flexibility to developers, there is a meta tag that may be used to customise this behaviour:
```html
<meta name="wails-options" content="[options]">
```
The options are as follows:
| Value | Description |
| -------------------- | ------------------------------------------------- |
| noautoinjectruntime | Disable the autoinjection of `/wails/runtime.js` |
| noautoinjectipc | Disable the autoinjection of `/wails/ipc.js` |
| noautoinject | Disable all autoinjection of scripts |
Multiple options may be used provided they are comma seperated.
This code is perfectly valid and operates the same as the autoinjection version:
```html
<html>
<head>
<title>injection example</title>
<meta name="wails-options" content="noautoinject">
<link rel="stylesheet" href="/main.css">
</head>
<body data-wails-drag>
<div class="logo"></div>
<div class="result" id="result">Please enter your name below 👇</div>
<div class="input-box" id="input" data-wails-no-drag>
<input class="input" id="name" type="text" autocomplete="off">
<button class="btn" onclick="greet()">Greet</button>
</div>
<script src="/wails/ipc.js"></script>
<script src="/wails/runtime.js"></script>
<script src="/main.js"></script>
</body>
</html>
```

View File

@@ -11,12 +11,13 @@ version of the runtime library. Finally, it is possible to bind Go methods to th
Javascript methods that can be called, just as if they were local Javascript methods.
<div className="text--center">
<img src="/img/architecture.svg" width='75%'/>
<img src="/img/architecture.svg" width="75%" />
</div>
## The Main Application
### Overview
The main application consists of a single call to `wails.Run()`. It accepts the
application configuration which describes the size of the application window, the window title,
what assets to use, etc. A basic application might look like this:
@@ -75,12 +76,12 @@ func (b *App) Greet(name string) string {
This example has the following options set:
- `Title` - The text that should appear in the window's title bar
- `Width` & `Height` - The dimensions of the window
- `Assets` - The application's frontend assets
- `OnStartup` - A callback for when the window is created and is about to start loading the frontend assets
- `OnShutdown` - A callback for when the application is about to quit
- `Bind` - A slice of struct instances that we wish to expose to the frontend
- `Title` - The text that should appear in the window's title bar
- `Width` & `Height` - The dimensions of the window
- `Assets` - The application's frontend assets
- `OnStartup` - A callback for when the window is created and is about to start loading the frontend assets
- `OnShutdown` - A callback for when the application is about to quit
- `Bind` - A slice of struct instances that we wish to expose to the frontend
A full list of application options can be found in the [Options Reference](/docs/reference/options).
@@ -94,7 +95,7 @@ there is no requirement on where in the `embed.FS` the files live. It is likely
directory relative to your main application code, such as `frontend/dist`:
```go title="main.go"
// go:embed frontend/dist
//go:embed frontend/dist
var assets embed.FS
```
@@ -117,7 +118,7 @@ Just before the frontend is about to load `index.html`, a callback is made to th
A standard Go context is passed to this method. This context is required when calling the runtime so a standard pattern is to save
a reference to in this method. Just before the application shuts down, the [OnShutdown](/docs/reference/options#OnShutdown) callback is called in the same way,
again with the context. There is also an [OnDomReady](/docs/reference/options#OnDomReady) callback for when the frontend
has completed loading all assets in `index.html` and is equivalent of the [`body onload`](https://www.w3schools.com/jsref/event_onload.asp) event in Javascript.
has completed loading all assets in `index.html` and is equivalent of the [`body onload`](https://www.w3schools.com/jsref/event_onload.asp) event in Javascript.
#### Method Binding
@@ -133,7 +134,7 @@ These methods return a promise. A successful call will result in the first retur
to the resolve handler. An unsuccessful call is when a Go method that has an error type as it's second return value,
passes an error instance back to the caller. This is passed back via the reject handler.
In the example above, `Greet` only returns a `string` so the Javascript call will never reject - unless invalid data
is passed to it.
is passed to it.
All data types are correctly translated between Go and Javascript. Even structs. If you return a struct from a Go call,
it will be returned to your frontend as a Javascript map. Note: If you wish to use structs, you **must** define `json` struct
@@ -148,14 +149,17 @@ section of the [Application Development Guide](/docs/guides/application-developm
## The Frontend
### Overview
The frontend is a collection of files rendered by webkit. It's like a browser and webserver in one.
There is virtually[^1] no limit to which frameworks or libraries you can use. The main points of interaction between
the frontend and your Go code are:
- Calling bound Go methods
- Calling runtime methods
[^1]: There is a very small subset of libraries that use features unsupported in WebViews. There are often alternatives and
workarounds for such cases.
- Calling bound Go methods
- Calling runtime methods
[^1]:
There is a very small subset of libraries that use features unsupported in WebViews. There are often alternatives and
workarounds for such cases.
### Calling bound Go methods
@@ -163,11 +167,11 @@ All bound Go methods are available at `window.go.<package>.<struct>.<method>`. A
the previous section, these return a Promise where a successful call returns a value to the
resolve handler and an error returns a value to the reject handler.
```go title="mycode.js"
window.go.main.App.Greet("Bill").then((result) => {
console.log("The greeting is: " + result);
})
```
```go title="mycode.js"
window.go.main.App.Greet("Bill").then((result) => {
console.log("The greeting is: " + result);
})
```
When running the application in `dev` mode, a javascript module is generated that wraps these
methods with JSDoc annotations. This really help with development, especially as most
@@ -178,19 +182,18 @@ following code:
```js title="bindings.js"
const go = {
"main": {
"App": {
main: {
App: {
/**
* Greet
* @param {Person} arg1 - Go Type: string
* @returns {Promise<string>} - Go Type: string
*/
"Greet": (arg1) => {
Greet: (arg1) => {
return window.go.main.App.Greet(arg1);
},
}
}
},
},
};
export default go;
```
@@ -221,93 +224,97 @@ func (a *App) Greet(p Person) string {
return fmt.Sprintf("Hello %s (Age: %d)!", p.Name, p.Age)
}
```
Our `bindings.js` file has now been updated to reflect the change:
```js title="bindings.js"
const go = {
"main": {
"App": {
main: {
App: {
/**
* Greet
* @param {Person} arg1 - Go Type: main.Person
* @returns {Promise<string>} - Go Type: string
*/
"Greet": (arg1) => {
Greet: (arg1) => {
return window.go.main.App.Greet(arg1);
},
}
}
},
},
};
export default go;
```
Alongside `bindings.js`, there is a file called `models.ts`. This contains our Go structs in TypeScript form:
```ts title="models.ts"
export class Address {
street: string;
postcode: string;
street: string;
postcode: string;
static createFrom(source: any = {}) {
return new Address(source);
}
static createFrom(source: any = {}) {
return new Address(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.street = source["street"];
this.postcode = source["postcode"];
}
constructor(source: any = {}) {
if ("string" === typeof source) source = JSON.parse(source);
this.street = source["street"];
this.postcode = source["postcode"];
}
}
export class Person {
name: string;
age: number;
address?: Address;
name: string;
age: number;
address?: Address;
static createFrom(source: any = {}) {
return new Person(source);
static createFrom(source: any = {}) {
return new Person(source);
}
constructor(source: any = {}) {
if ("string" === typeof source) source = JSON.parse(source);
this.name = source["name"];
this.age = source["age"];
this.address = this.convertValues(source["address"], Address);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.name = source["name"];
this.age = source["age"];
this.address = this.convertValues(source["address"], Address);
if (a.slice) {
return (a as any[]).map((elem) => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
return a;
}
}
```
So long as you have TypeScript as part of your frontend build configuration, you can use these models in
the following way:
```js title="mycode.js"
import go from "./wailsjs/go/bindings";
import {Person} from "./wailsjs/go/models";
import go from "./wailsjs/go/bindings";
import { Person } from "./wailsjs/go/models";
let name = "";
let name = "";
function greet(name) {
let p = new Person();
p.name = name;
p.age = 42;
go.main.App.Greet(p).then((result) => {
console.log(result);
});
}
function greet(name) {
let p = new Person();
p.name = name;
p.age = 42;
go.main.App.Greet(p).then((result) => {
console.log(result);
});
}
```
The combination of JSDoc and TypeScript generated models makes for a powerful development environment.

View File

@@ -131,10 +131,12 @@ Your system is ready for Wails development!
| -loglevel "loglevel"| Loglevel to use - Trace, Debug, Info, Warning, Error | Debug |
| -noreload | Disable automatic reload when assets change | |
| -v | Verbosity level (0 - silent, 1 - standard, 2 - verbose) | 1 |
| -wailsjsdir | The directory to generate the generated Wails JS modules | Value store in `wails.json` |
| -wailsjsdir | The directory to generate the generated Wails JS modules | Value in `wails.json` |
| -debounce | The time to wait for reload after an asset change is detected | 100 (milliseconds) |
| -devserverurl "url" | Use 3rd party dev server url, EG Vite | "http://localhost:34115" |
If the `-assetdir` or `-wailsjsdir` flags are provided on the command line, they are saved in `wails.json`, and become
the defaults for subsequent invocations.
If the `assetdir`, `wailsjsdir`, `debounce` or `devserverurl` flags are provided on the command line, they are saved in
`wails.json`, and become the defaults for subsequent invocations.
Example:

View File

@@ -12,13 +12,16 @@ The project config resides in the `wails.json` file in the project directory. Th
"assetdir": "[Relative path to your assets directory]",
"frontend:install": "[The command to install node dependencies, run in the frontend directory - often `npm install`]",
"frontend:build": "[The command to build the assets, run in the frontend directory - often `npm run build`]",
"frontend:dev": "[This command is run in a separate process on `wails dev`. Useful for 3rd party watchers]",
"wailsjsdir": "[Relative path to the directory that the auto-generated JS modules will be created]",
"version": "[Project config version]",
"outputfilename": "[The name of the binary]"
"outputfilename": "[The name of the binary]",
"debounceMS": 100, // The default time the dev server waits to reload when it detects a vhange in assets
"devserverurl": "[URL to the dev server serving local assets. Default: http://localhost:34115]"
}
```
This file is read by the Wails CLI when running `wails build` or `wails dev`.
The `assetdir` and `wailsjsdir` flags in `wails build/dev` will update the project config and thus become defaults for
subsequent runs.
The `assetdir`, `wailsjsdir`, `debounceMS` and `devserverurl` flags in `wails build/dev` will update the project config
and thus become defaults for subsequent runs.

View File

@@ -9,42 +9,151 @@ authors:
tags: [wails, v2]
---
两年多前,在悉尼的火车上,当我第一次在 Reddit 宣布 Wails 时,我没想到它会引起太多关注。几天后,一位多产的科技视频博主发布了一个教程视频,并给予了正面评价,从那时起,人们对这个项目的兴趣直线上升。
<div class="text--center">
<img
src="/img/wails.png"
width="40%"
style={{ "box-shadow": "rgb(255 255 255 / 20%) 0px 4px 8px 0px, rgb(104 104 104) 0px 6px 20px 0px" }}
/>
</div>
<br />
人们对在他们的 Go 项目中添加 web 前端感到兴奋几乎立即在这个项目推送并超出了我创建这个项目的设想。当时Wails 使用 [webview](https://github.com/webview/webview) 项目来处理前端,
两年多前,在悉尼的火车上,当我第一次在 Reddit 宣布 Wails 时,我没想到它会引起太多关注。几天后,一位多产的科技视频博主发布了一个教程视频,并给予了正面评价,从那时起,人们对该项目的兴趣猛增。
很明显,人们对将 Web 前端添加到他们的 Go 项目感到兴奋几乎立即将项目推动到超出我创建这个项目的设想。当时Wails 使用 [webview](https://github.com/webview/webview) 项目来处理前端,
Windows 的唯一选择是 IE11 渲染器。许多错误报告都因为受到它的限制:糟糕的 JavaScript/CSS 支持并且没有开发工具来调试它。这是一段令人沮丧的开发经历,但我们也没有采取什么措施去纠正它。
很长一段时间以来,我一直坚信微软最终会解决他们的浏览器问题。世界在不断进步,前端开发正在蓬勃发展,而 IE 并没有做到这一点。当微软宣布将 Chromium 作为其新浏览器方向的基础时,
我知道 Wails 能够使用它并将 Windows 开发者的体验提升到下一个水平只是时间问题。
今天,我很高兴地宣布:**适用于 Windows 的 Wails v2 公测啦**!
今天,我很高兴地宣布:**适用于 Windows 的 Wails v2 公测啦**!此版本中有大量内容需要展开来说,所以,请倒一杯茶,咱们坐下来慢慢讲......
- 没有 CGO 依赖我不是在开玩笑_没有依赖 CGO_ 🤯!
- WebView2 chromium 渲染引擎! 终于!
- 不需要在应用程序中附带任何 dll包括`WebView2Loader.dll`。单个二进制文件的构想继续存在
- 不需要打包资源(只需要提供一个 embed.FS就像一个 web 服务器)
- 应用程序菜单支持
- 具有热重载和自动重新构建功能的新开发方式
- 用于控制应用程序窗口的运行时方法
- 现代化的原生对话框
### 没有 CGO 依赖
不,我不是在开玩笑:*没有 CGO 依赖*🤯Windows 的问题在于,与 MacOS 和 Linux 不同,它没有默认编译器
此外CGO 需要一个 mingw 编译器,并且有大量不同的安装选项。删除 CGO 的要求大大简化了设置,并使调试变得非常容易。
虽然我已经付出了相当多的努力来完成这项工作,但大部分功劳应该归功于[John Chadwick](https://github.com/jchv),他不仅启动了几个项目使这成为可能,
而且还对接受这些项目并以此为基础的人持开放态度. 还要归功于[Tad Vizbaras](https://github.com/tadvi),他的[winc](https://github.com/tadvi/winc)项目让我走上了这条道路。
### WebView2 Chromium 渲染引擎
<div class="text--center">
<img
src="/img/devtools.png"
width="75%"
style={{ "box-shadow": "rgb(255 255 255 / 20%) 0px 4px 8px 0px, rgb(104 104 104) 0px 6px 20px 0px" }}
/>
</div>
<br />
最终Windows 开发人员为他们的应用程序获得了一流的渲染引擎!扭曲前端代码以在 Windows 上工作的日子已经一去不复返了。最重要的是,您将获得一流的开发者工具体验!
但是WebView2 组件确实需要将其放置`WebView2Loader.dll`在二进制文件旁边。这使得分发比我们 gophers 习惯的更痛苦。所有使用 WebView2 的解决方案和库(我知道的)都具有这种依赖性。
然而我真的很高兴地宣布Wails 应用程序*没有这样的要求*!感谢[John Chadwick](https://github.com/jchv)的魔法,我们能够将这个 dll 打包在二进制文件中,并让 Windows 加载它,就像它存在于磁盘上一样。
Gophers 欢呼吧!单个二进制文件的设想依然存在!
### 新功能
<div class="text--center">
<img
src="/img/wails-menus.png"
width="60%"
style={{ "box-shadow": "rgb(255 255 255 / 20%) 0px 4px 8px 0px, rgb(104 104 104) 0px 6px 20px 0px" }}
/>
</div>
<br />
有很多对原生菜单支持的请求。Wails 终于让您满意了。应用程序菜单现已可用,并且包括对大多数原生菜单功能的支持。这包括标准菜单项、复选框、单选组、子菜单和分隔符。
在 v1 中有大量的请求,要求能够更好地控制窗口本身。我很高兴地宣布,有专门用于此的新运行时 API。它功能丰富支持多显示器配置。
还有一个改进的对话框 API现在您可以拥有具有丰富配置的现代原生对话框以满足您的所有对话框需求。
现在可以选择随项目生成 IDE 配置。这意味着如果您在受支持的 IDE 中打开您的项目,它已经被配置为构建和调试您的应用程序。目前支持 VSCode但我们希望尽快支持其他 IDE例如 Goland。
<div class="text--center">
<img
src="/img/vscode.png"
width="100%"
style={{ "box-shadow": "rgb(255 255 255 / 20%) 0px 4px 8px 0px, rgb(104 104 104) 0px 6px 20px 0px" }}
/>
</div>
<br />
### 无需打包资源
v1 的一个巨大痛点是需要将整个应用程序压缩为单个 JS 和 CSS 文件。我很高兴地宣布,对于 v2不需要以任何形式打包资源。
想要加载本地图片?使用带有本地`src`路径的`<img>`标签。想使用很酷的字体吗?复制它并在你的 CSS 中添加它的路径。
> 哇,这听起来像一个网络服务器......
是的,它就像一个网络服务器一样工作,但它不是。
> 那么我如何包含我的资源?
您只需将`embed.FS`包含所有资产的单个文件传递到您的应用程序配置中。他们甚至不需要在顶级目录中——Wails 会为你解决这个问题。
### 全新的开发体验
<div class="text--center">
<img
src="/img/browser.png"
width="60%"
style={{ "box-shadow": "rgb(255 255 255 / 20%) 0px 4px 8px 0px, rgb(104 104 104) 0px 6px 20px 0px" }}
/>
</div>
<br />
现在不需要打包资源,它启用了全新的开发体验。新`wails dev`命令将构建并运行您的应用程序,但它不使用`embed.FS`中的资源,而是直接从磁盘加载它们。
它还提供了附加功能:
- 热重载 - 对前端资产的任何更改都将触发并自动重载应用程序前端
- 自动重新构建 - 对 Go 代码的任何更改都将重新构建并重新启动您的应用程序
除此之外,网络服务器将在端口 34115 上启动。这将为您的应用程序提供连接到它的任何浏览器。所有连接的 Web 浏览器都会响应系统事件,例如资产更改时的热重载。
在 Go 中,我们习惯于在应用程序中处理结构。将结构发送到我们的前端并将它们用作我们应用程序中的状态通常很有用。在 v1 中,这是一个非常手动的过程,对开发人员来说有点负担。
我很高兴地宣布,在 v2 中,任何在开发模式下运行的应用程序都将自动为所有结构生成 Typescript 模型,这些结构是绑定方法的输入或输出参数。这实现了两个世界之间数据模型的无缝交换。
除此之外,还会动态生成另一个 JS 模块来包装您的所有绑定方法。这为您的方法提供了 JSDoc在您的 IDE 中提供代码完成和提示。当您在自动生成的包含 Go 代码的模块中点击 Tab 时自动导入数据模型,这真的很酷!
### 远程模板
<div class="text--center">
<img
src="/img/remote.png"
width="60%"
style={{ "box-shadow": "rgb(255 255 255 / 20%) 0px 4px 8px 0px, rgb(104 104 104) 0px 6px 20px 0px" }}
/>
</div>
<br />
让应用程序快速启动并运行一直是 Wails 项目的一个关键目标。当我们推出时我们试图涵盖当时的很多现代框架react、vue 和 angular。前端开发的世界非常自以为是快速发展且难以掌握
结果,我们发现我们的基本模板很快就过时了,这导致了维护问题。这也意味着我们没有用于最新和最伟大技术堆栈的酷炫现代模板。
在 v2 中,我希望通过让您能够自己创建和托管模板来增强社区的能力,而不是依赖于 Wails 项目。所以现在您可以使用社区支持的模板创建项目!
我希望这将激励开发人员创建一个充满活力的项目模板生态系统。我对我们的开发者社区可以创造的东西感到非常兴奋!
### 结语
Wails v2 代表了该项目的新基础。此版本的目的是获得有关新方式的反馈,并在完整版本发布之前解决所有错误。欢迎提出您的意见。请直接反馈到 [v2 测试版](https://github.com/wailsapp/wails/discussions/828)讨论板。
为了达到这一点,经历了许多曲折和坎坷。部分原因是早期的技术决策需要改变,另一部分原因是我们花时间构建的一些核心问题的变通方式已经在上游得到了解决:Go 的 embed 特性就是一个很好的例子。幸运的是,一切都刚刚好,今天我们有了我们所能拥有的最好的解决方案。我相信等待是值得的 - 这在两个月前是完全不可能的。
为了达到这一点,经历了许多曲折和坎坷。部分原因是早期的技术决策需要改变,另一部分原因是我们花时间构建的一些核心问题的变通方式已经在上游得到了解决Go 的 embed 特性就是一个很好的例子。幸运的是,一切都刚刚好,今天我们有了我们所能拥有的最好的解决方案。我相信等待是值得的 - 这在两个月前是完全不可能的。
我还需要特别感谢 :pray: 以下人员,因为没有他们,这个版本就不会存在:
- [Misitebao](https://github.com/misitebao) - 中文翻译的绝对主力和和令人难以置信的漏洞发现者。
- [Misitebao](https://github.com/misitebao) - 中文翻译的主要人员和和令人难以置信的漏洞发现者。
- [John Chadwick](https://github.com/jchv) - 他在 [go-webview2](https://github.com/jchv/go-webview2) 和 [go-winloader](https://github.com/jchv/go-winloader) 方面的出色工作使 Windows 版本成为可能。
- [Tad Vizbaras](https://github.com/tadvi) - 他的 winc 项目是走向纯粹的 Go Wails 的第一步。
- [Tad Vizbaras](https://github.com/tadvi) - 他的[winc](https://github.com/tadvi/winc)项目是走向纯粹的 Go Wails 的第一步。
- [Mat Ryer](https://github.com/matryer) - 他的支持、鼓励和反馈确实推动了项目向前发展。
最后,我还要特别感谢包括[JetBrains](https://www.jetbrains.com?from=Wails)在内的所有项目[赞助商](/docs/credits#sponsors),他们的幕后支持以多种方式推动了该项目。
我期待看到在项目的下一个激动人心的阶段人们用 Wails 构建什么!
对了,最后一件事:如果您或您的公司发现 Wails 有用,可以考虑[赞助该项目](https://github.com/sponsors/leaanthony)。谢谢!
Lea.
PSMacOS 和 Linux 用户不必感到被冷落了——移植到这个新基础上的工作正在积极进行中,大部分复杂的工作已经完成。坚持下去。。。
PSMacOS 和 Linux 用户不必感到被忽略了——移植到这个新基础上的工作正在积极进行中,大部分复杂的工作已经完成。坚持下去...
PPS如果您或您的公司发现 Wails 有用,可以考虑[赞助该项目](https://github.com/sponsors/leaanthony)。谢谢!

View File

@@ -26,5 +26,9 @@
"sidebar.tutorialSidebar.category.Community": {
"message": "社区交流",
"description": "The label for category Community in sidebar tutorialSidebar"
},
"sidebar.tutorialSidebar.category.Showcase": {
"message": "项目展示",
"description": "The label for category Showcase in sidebar tutorialSidebar"
}
}

View File

@@ -8,9 +8,9 @@ sidebar_position: 1
## 概述
Wails 是一个可让使用 Go 和 Web 技术编写桌面应用的项目。
Wails 是一个可让使用 Go 和 Web 技术编写桌面应用的项目。
将它看作为轻量快速的 “Electron for Go”。 可以结合丰富现代前端技术轻松构建具有灵活性和强大功能的 Go 应用程序。
将它看作为轻量快速的 “Electron for Go”。 可以使用 Go 的灵活性和强大功能,结合丰富现代前端轻松构建应用程序。
Wails 一点也不弱!这是 [xbar](https://xbarapp.com) - 一个使用 Wails 编写的 MacOS 桌面应用。它使用 Mac 的系统原生菜单,支持浅色和深色桌面主题,主窗口使用半透明,使其具有原生应用的
“冰霜” 效果。
@@ -21,12 +21,13 @@ Wails 一点也不弱!这是 [xbar](https://xbarapp.com) - 一个使用 Wails
## 原生元素
Wails 使用专门的库来处理原生元素,例如窗口、菜单、对话框等,因此可以构建美观、功能丰富的桌面应用程序。 它不嵌入浏览器,因此性能高。相反,它使用平台的原生渲染引擎。在 Windows 上,是基于 Chromium 构建的新
Microsoft Webview2 库。
Wails 使用专门的库来处理原生元素,例如窗口、菜单、对话框等,因此可以构建美观、功能丰富的桌面应用程序。
**它不嵌入浏览器**,因此性能高。相反,它使用平台的原生渲染引擎。在 Windows 上,是基于 Chromium 构建的新 Microsoft Webview2 库。
## Go 和 Javascript 互操作
Wails 自动使的 Go 方法可用于 Javascript因此可以从前端按名称调用它们!它甚至会生成 Go 方法使用的结构的 Typescript 版本,因此可以在 Go 和 Javascript 之间传递相同的数据结构。
Wails 自动使的 Go 方法可用于 Javascript因此可以从前端按名称调用它们!它甚至会生成 Go 方法使用的结构的 Typescript 版本,因此可以在 Go 和 Javascript 之间传递相同的数据结构。
## 运行时库
@@ -36,21 +37,21 @@ Wails 为 Go 和 Javascript 提供了一个运行时库,可以处理现代应
### 自动重新构建
在“dev”模式下运行的应用程序时Wails 会将的应用程序构建为原生桌面应用程序,但会从磁盘读取的资源。它将检测的 Go 代码的任何更改,并自动重新构建和重新启动的应用程序。
在“dev”模式下运行的应用程序时Wails 会将的应用程序构建为原生桌面应用程序,但会从磁盘读取的资源。它将检测的 Go 代码的任何更改,并自动重新构建和重新启动的应用程序。
### 自动重新加载
当检测到的应用程序资源发生更改时,正在运行的应用程序将“重新加载”,几乎立即反馈的更改。
当检测到的应用程序资源发生更改时,正在运行的应用程序将“重新加载”,几乎立即反馈的更改。
### 在浏览器中开发的应用程序
### 在浏览器中开发的应用程序
如果更喜欢在浏览器中调试和开发,那么我们可以满足的需求。正在运行的应用程序还有一个网络服务器,它将在连接到它的任何浏览器中运行的应用程序。当的资源在磁盘上发生变化时,它会刷新。
如果更喜欢在浏览器中调试和开发,那么 Wails 可以满足的需求。正在运行的应用程序还有一个网络服务器,它将在连接到它的任何浏览器中运行的应用程序。当的资源在磁盘上发生变化时,它会刷新。
## 生成原生二进制文件
准备好完成应用程序的最终构建时CLI 会将其编译为单个可执行文件,并将所有资源打包到其中。在 Windows 和 MacOS
上,可以创建用于分发的原生包。使用打包后生成的资源图标、info.plist、清单文件等项目的一部分,可以自定义,让完全控制应用程序的构建方式。
准备好完成应用程序的最终构建时CLI 会将其编译为单个可执行文件,并将所有资源打包到其中。在 Windows 和 MacOS
上,可以创建用于分发的原生包。使用打包工具后生成的资源图标、info.plist、清单文件等项目的一部分,可以自定义,让完全控制应用程序的构建方式。
## 工具
Wails CLI 提供了一种简单的方法来生成、构建和打包你的应用程序。可以从许多入门模板中进行选择,以快速启动和运行!
Wails CLI 提供了一种简单的方法来生成、构建和打包您的应用程序。它将完成创建图标的繁重工作,使用最佳设置编译您的应用程序,并提供可分发的、可用于生产的二进制文件。可以从许多入门模板中进行选择,以快速启动和运行!

View File

@@ -1,21 +0,0 @@
---
sidebar_position: 50
---
# 社区模板
此页面用作社区支持的模板列表。请提交一个包含您的模板的 PR点击页面底部的`编辑此页`)。要构建您自己的模板,请参考[模板](/docs/guides/templates)指南。
要使用这些模板,请运行 `wails init -n "你的项目名" -t [下面的链接]`
示例:`wails init -n "Your Project Name" -t https://github.com/misitebao/wails-template-vue`
:::warning 注意
仅安装你信任的远程模板。 如果你不确定某个模板,请检查 `package.json` 中运行的脚本和安装的模块。 **Wails 项目对第 3 方模板不承担任何责任!**
:::
## Vue
- [wails-template-vue](https://github.com/misitebao/wails-template-vue) - 基于 Vue 和 Vue-Router 的 Wails 模板

View File

@@ -1,4 +1,4 @@
{
"label": "Community",
"position": 5
"position": 50
}

View File

@@ -0,0 +1,10 @@
# EncryptEasy
<p style={{"text-align": "center"}}>
<img src="/img/showcase/encrypteasy.jpg"></img><br/>
</p>
**[EncryptEasy](https://www.encrypteasy.app) is a simple and easy to use PGP encryption tool, managing all your and your contacts keys. Encryption should be simple. Developed with Wails.**
Encrypting messages using PGP is the industry standard. Everyone has a private and a public key. Your private key, well, needs to be kept private so only you can read messages. Your public key is distributed to anyone who wants to send you secret, encrypted messages. Managing keys, encrypting messages and decrypting messages should be a smooth experience. EncryptEasy is all about making it easy.

View File

@@ -0,0 +1,23 @@
# FileHound Export Utility
<p style={{"text-align": "center"}}>
<img src="/img/showcase/filehound.jpg"></img><br/>
</p>
[FileHound Export Utility](https://www.filehound.co.uk/) FileHound is a cloud document management platform made for secure file retention, business process automation and SmartCapture capabilities.
The FileHound Export Utility allows FileHound Administrators the ability to run a secure document and data extraction tasks for alternative back-up and recovery purposes. This application will download all documents and/or meta data saved in FileHound based on the filters you choose. The metadata will be exported in both JSON and XML formats.
Backend built with:
Go 1.15
Wails 1.11.0
go-sqlite3 1.14.6
go-linq 3.2
Frontend with:
Vue 2.6.11
Vuex 3.4.0
Typescript
Tailwind 1.9.6

View File

@@ -0,0 +1,9 @@
# Molley Wallet
<p style={{"text-align": "center"}}>
<img src="/img/showcase/mollywallet.png"></img><br/>
</p>
[Molly Wallet](https://github.com/grvlle/constellation_wallet/) the official $DAG wallet of the Constellation Network. It'll let users interact with the Hypergraph Network in various ways, not limited to producing $DAG transactions.

View File

@@ -0,0 +1,9 @@
# Optimus
<p style={{"text-align": "center"}}>
<img src="/img/showcase/optimus.png"></img><br/>
</p>
[Optimus](https://github.com/splode/optimus) is a desktop image optimization application. It supports conversion and compression between WebP, JPEG, and PNG image formats.

View File

@@ -0,0 +1,9 @@
# Portfall
<p style={{"text-align": "center"}}>
<img src="/img/showcase/portfall.gif"></img><br/>
</p>
[Portfall](https://github.com/rekon-oss/portfall) - A desktop k8s port-forwarding portal for easy access to all your cluster UIs

View File

@@ -0,0 +1,9 @@
# Surge
<p style={{"text-align": "center"}}>
<img src="/img/showcase/surge.png"></img><br/>
</p>
[Surge](https://surge.rule110.io/) is a p2p filesharing app designed to utilize blockchain technologies to enable 100% anonymous file transfers. Surge is end-to-end encrypted, decentralized and open source.

View File

@@ -0,0 +1,9 @@
# Wally
<p style={{"text-align": "center"}}>
<img src="/img/showcase/wally.png"></img><br/>
</p>
[Wally](https://ergodox-ez.com/pages/wally) is the official firmware flasher for [Ergodox](https://ergodox-ez.com/) keyboards. It looks great and is a fantastic example of what you can achieve with Wails: the ability to combine the power of Go and the rich graphical tools of the web development world.

View File

@@ -0,0 +1,10 @@
# Wombat
<p style={{"text-align": "center"}}>
<img src="/img/showcase/wombat.png"></img><br/>
</p>
[Wombat](https://github.com/rogchap/wombat) is a cross platform gRPC client.

View File

@@ -6,7 +6,7 @@ sidebar_position: 1
此页面用作社区支持的模板列表。请提交一个包含您的模板的 PR点击页面底部的`编辑此页`)。要构建您自己的模板,请参考[模板](/docs/guides/templates)指南。
要使用这些模板,请运行 `wails init -n "的项目名" -t [下面的链接]`
要使用这些模板,请运行 `wails init -n "的项目名" -t [下面的链接]`
示例:`wails init -n "Your Project Name" -t https://github.com/misitebao/wails-template-vue`
@@ -14,10 +14,12 @@ sidebar_position: 1
**Wails 项目不维护也不对第 3 方模板负责**
如果不确定某个模板,请检查 `package.json` 中运行的脚本和安装的模块。
如果不确定某个模板,请检查 `package.json` 中运行的脚本和安装的模块。
:::
## Vue
- [wails-template-vue](https://github.com/misitebao/wails-template-vue) - 基于 Vue 和 Vue-Router 的 Wails 模板
- [wails-vite-vue-ts](https://github.com/codydbentley/wails-vite-vue-ts) - 使用 Vite 的 Vue 3 TypeScript(以及添加功能的说明)
- [wails-vite-vue-the-works](https://github.com/codydbentley/wails-vite-vue-the-works) - 使用 Vite, Vuex, Vue Router, Sass, 和 ESLint + Prettier 的 Vue 3 TypeScript

View File

@@ -5,7 +5,7 @@ sidebar_position: 99
# 荣誉墙
- [Lea Anthony](https://github.com/leaanthony) - 项目所有者,首席开发人员
- [Misitebao](https://github.com/misitebao) - 中文文档Windows 测试,寻找漏洞
- [Misitebao](https://github.com/misitebao) - 中文文档Windows 测试,漏洞发现者
- [Travis McLane](https://github.com/tmclane) - 处理交叉编译相关工作, MacOS 平台的测试
- [Byron Chris](https://github.com/bh90210) - Linux 发行版指导Linux 平台的测试
@@ -61,6 +61,12 @@ sidebar_position: 99
<a href="https://github.com/marcus-crane" style="width:50px">
<img src="https://github.com/marcus-crane.png?size=50" width="50"/>
</a>
<a href="https://github.com/codydbentley" style="width:65px">
<img src="https://github.com/codydbentley.png?size=65" width="65"/>
</a>
<a href="https://github.com/bbergshaven" style="width:45px">
<img src="https://github.com/bbergshaven.png?size=45" width="45"/>
</a>
`,
}}
/>

View File

@@ -1,4 +1,4 @@
{
"label": "Getting Started",
"position": 2
"position": 10
}

View File

@@ -1,14 +1,21 @@
---
title: 编译的项目
title: 编译的项目
sidebar_position: 6
---
# 编译的项目
# 编译的项目
从项目目录,运行`wails build`。 这将编译的项目并将构建的二进制文件保存在 `build/bin` 目录中。
从项目目录,运行`wails build`。 这将编译的项目并将构建的可用于生产的二进制文件保存在 `build/bin` 目录中。
如果运行二进制文件,应该会看到默认应用程序:
如果运行二进制文件,应该会看到默认应用程序:
待定
<div class="text--center">
<img
src="/img/defaultproject.png"
width="50%"
style={{ "box-shadow": "rgb(255 255 255 / 20%) 0px 4px 8px 0px, rgb(104 104 104) 0px 6px 20px 0px" }}
/>
</div>
<br />
有关编译选项的更多详细信息,请参阅[构建命令](/docs/reference/cli#构建)。

View File

@@ -1,15 +1,15 @@
---
title: 开发的应用程序
title: 开发的应用程序
sidebar_position: 5
---
# 开发的应用程序
# 开发的应用程序
可以通过运行`wails dev`从项目目录在开发模式下运行的应用程序。这将执行以下操作:
可以通过运行`wails dev`从项目目录在开发模式下运行的应用程序。这将执行以下操作:
- 构建的应用程序并运行它
- 构建的应用程序并运行它
- 监听 Go 文件中的修改并在更改时重新构建/重新运行
- 设置将通过浏览器为的应用程序提供服务的[网络服务器](http://localhost:34115)。这允许使用喜欢的浏览器扩展。甚至可以从控制台调用 Go 代码。
- 设置将通过浏览器为的应用程序提供服务的[网络服务器](http://localhost:34115)。这允许使用喜欢的浏览器扩展。甚至可以从控制台调用 Go 代码。
首先,在项目目录中运行`wails dev`。可以在[此处](/docs/reference/cli#开发)找到有关这方面的更多信息。

View File

@@ -7,13 +7,13 @@ sidebar_position: 2
## 项目生成
现在 CLI 已安装,可以使用该`wails init`命令生成一个新项目。
现在 CLI 已安装,可以使用该`wails init`命令生成一个新项目。
为了快速启动和运行,可以通过运行`wails init -n myproject`生成一个默认项目。这将创建一个名为`myproject`的目录,并使用默认模板填充它。
为了快速启动和运行,可以通过运行`wails init -n myproject`生成一个默认项目。这将创建一个名为`myproject`的目录,并使用默认模板填充它。
其他项目模板也可用,可以使用 `wails init -l`列出。
可以使用 `wails init -l`列出其他可用模板
要查看其他可用选项,可以运行 `wails init -help`。 更多详细信息可以在 [初始化命令](/docs/reference/cli#初始化)中找到。
要查看其他可用选项,可以运行 `wails init -help`。 更多详细信息可以在 [初始化命令](/docs/reference/cli#初始化)中找到。
## 项目布局
@@ -26,6 +26,8 @@ Wails 项目具有以下布局:
│ ├── darwin/
│ └── windows/
├── frontend/
├── go.mod
├── go.sum
├── main.go
└── wails.json
```
@@ -39,7 +41,11 @@ Wails 项目具有以下布局:
- `/build/darwin/` - Mac 特定的项目文件
- `/build/windows/` - Windows 特定的项目文件
- `/wails.json` - 项目配置
- `/go.mod` - Go 模块文件
- `/go.sum` - Go 模块校验文件
`frontend`目录没有特定于 Wails 的内容,可以是您选择的任何前端项目。
`build`目录在构建过程中使用。这些文件可以更新以自定义您的构建。如果文件从构建目录中删除,将重新生成默认版本。
`go.mod`中的默认模块名称是“changeme”。您应该将其更改为更合适的内容。

View File

@@ -1,5 +1,4 @@
---
title: 安装
sidebar_position: 1
---
@@ -15,27 +14,27 @@ sidebar_position: 1
Wails 有许多安装前需要的常见依赖项:
- Go 1.16+
- npm LTS
- Go 1.17+
- npm (Node 14+)
### Go
[Go 下载页面](https://golang.org/dl/) 下载 Go。
从[Go 下载页面](https://golang.org/dl/)下载 Go。
确保遵守官方的 [Go 安装说明](https://golang.org/doc/install#install)。还需要确保的 `PATH` 环境变量包含的 `~/go/bin` 目录路径。 重启终端并执行以下命令检查:
确保遵守官方的[Go 安装说明](https://golang.org/doc/install#install)。还需要确保的 `PATH` 环境变量包含的 `~/go/bin` 目录路径。 重启终端并执行以下命令检查:
- 检查 Go 是否安装正确: `go version`
- 检查 "~/go/bin" 是否在的 PATH 变量中: `echo $PATH | grep go/bin`
- 检查 "~/go/bin" 是否在的 PATH 变量中: `echo $PATH | grep go/bin`
### npm
[Node 下载页面](https://nodejs.org/en/download/) 下载 Npm。最好使用最新版本因为这是我们通常会测试的版本。
从[Node 下载页面](https://nodejs.org/en/download/)下载 Npm。最好使用最新版本因为这是我们通常会测试的版本。
运行 `npm --version` 进行校验。
## 平台指定依赖关系
还需要安装指定平台的依赖项:
还需要安装指定平台的依赖项:
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
@@ -51,7 +50,7 @@ import TabItem from "@theme/TabItem";
<TabItem value="Windows">
Wails 要求安装
<a href="https://developer.microsoft.com/zh-cn/microsoft-edge/webview2/">WebView2</a>
运行时。一些 Windows 已经默认安装了这个。可以使用 <code>wails doctor</code>
运行时。一些 Windows 已经默认安装了这个。可以使用 <code>wails doctor</code>
命令进行检查(见下文)。
</TabItem>
<TabItem value="MacOS">即将推出...</TabItem>
@@ -60,12 +59,12 @@ import TabItem from "@theme/TabItem";
## 可选依赖
- [UPX](https://upx.github.io/) 用于压缩的应用程序。
- [UPX](https://upx.github.io/) 用于压缩的应用程序。
## 安装 Wails
运行 `go install github.com/wailsapp/wails/v2/cmd/wails@v2.0.0-beta.1` 安装 Wails CLI。
运行 `go install github.com/wailsapp/wails/v2/cmd/wails@v2.0.0-beta.8` 安装 Wails CLI。
## 系统检查
运行 `wails doctor` 将检查是否安装了正确的依赖项。如果没有,它会就缺少的内容提供建议并帮助纠正任何问题。
运行 `wails doctor` 将检查是否安装了正确的依赖项。如果没有,它会就缺少的内容提供建议并帮助纠正任何问题。

View File

@@ -1,4 +1,4 @@
{
"label": "Guides",
"position": 4
"position": 50
}

View File

@@ -1,7 +1,3 @@
---
sidebar_position: 1
---
# 应用开发
使用 Wails 开发应用程序没有硬性规定,但有一些基本准则。
@@ -140,7 +136,7 @@ func main() {
## 资源
Wails v2 处理资源的方式的伟大之处在于它没有!唯一需要给 Wails 的是一个 `embed.FS` 如何做到这一点完全取决于。您可以像 vanilla 模板一样使用 vanilla html/css/js 文件。可能有一些复杂的构建系统,但这并不影响。
Wails v2 处理资源的方式的伟大之处在于它没有!唯一需要给 Wails 的是一个 `embed.FS` 如何做到这一点完全取决于。您可以像 vanilla 模板一样使用 vanilla html/css/js 文件。可能有一些复杂的构建系统,但这并不影响。
当运行`wails build`时,它会检查项目根目录的`wails.json`文件。文件中有 2 个字段会被读取:

View File

@@ -1,7 +1,3 @@
---
sidebar_position: 99
---
# 参与贡献
这个页面是关于如何贡献 Wails 项目的指南。

View File

@@ -1,7 +1,3 @@
---
sidebar_position: 10
---
# 无边框应用
Wails 支持无边框应用程序。这可以通过使用[应用程序参数选项](/docs/reference/options#应用程序参数选项)中的[无边框](/docs/reference/options#无边框)字段来实现。

View File

@@ -0,0 +1,72 @@
# 前端
## 脚本注入
当 Wails 为您的`index.html`提供服务时,默认情况下,它会将 2 个脚本注入`<body>`标签以加载`/wails/bindings.js`和`/wails/runtime.js`。 这些文件分别安装绑定和运行时。
下面的代码显示了这些默认注入的位置:
```html
<html>
<head>
<title>injection example</title>
<link rel="stylesheet" href="/main.css" />
<!-- <script src="/wails/ipc.js"></script> -->
<!-- <script src="/wails/runtime.js"></script> -->
</head>
<body data-wails-drag>
<div class="logo"></div>
<div class="result" id="result">Please enter your name below 👇</div>
<div class="input-box" id="input" data-wails-no-drag>
<input class="input" id="name" type="text" autocomplete="off" />
<button class="btn" onclick="greet()">Greet</button>
</div>
<script src="/main.js"></script>
</body>
</html>
```
### 覆盖默认脚本注入
为了给开发人员提供更大的灵活性,有一个`meta`标签可用于自定义此行为:
```html
<meta name="wails-options" content="[options]" />
```
选项如下:
| 值 | 描述 |
| ------------------- | -------------------------------- |
| noautoinjectruntime | 禁用自动注入 `/wails/runtime.js` |
| noautoinjectipc | 禁用自动注入 `/wails/ipc.js` |
| noautoinject | 禁用所有脚本自动注入 |
可以使用多个选项,前提是它们以逗号分隔。
此代码完全有效并且与自动注入版本的操作相同:
```html
<html>
<head>
<title>injection example</title>
<meta name="wails-options" content="noautoinject" />
<link rel="stylesheet" href="/main.css" />
</head>
<body data-wails-drag>
<div class="logo"></div>
<div class="result" id="result">Please enter your name below 👇</div>
<div class="input-box" id="input" data-wails-no-drag>
<input class="input" id="name" type="text" autocomplete="off" />
<button class="btn" onclick="greet()">Greet</button>
</div>
<script src="/wails/ipc.js"></script>
<script src="/wails/runtime.js"></script>
<script src="/main.js"></script>
</body>
</html>
```

View File

@@ -0,0 +1,107 @@
# 集成开发环境
Wails 旨在提供出色的开发体验。为此,我们现在支持生成 IDE 特定配置以提供更顺畅的项目设置。
目前,我们支持[Visual Studio Code](https://code.visualstudio.com/),但我们希望尽快支持其他 IDE例如 Goland。
## Visual Studio Code
<p className="text--center">
<img src="/img/vscode.png" style={{ width: "75%" }}></img>
</p>
使用`-ide vscode`标志生成项目时IDE 文件将与其他项目文件一起创建。这些文件放置在`.vscode`目录中,并为调试应用程序提供正确的配置。
生成的 2 个文件是`tasks.json`和`launch.json`. 以下是为默认 vanilla 项目生成的文件:
```json title="tasks.json"
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}"
},
"command": "go",
"args": ["build", "-tags", "dev", "-gcflags", "all=-N -l", "-o", "build/bin/myproject.exe"]
}
]
}
```
```json title="launch.json"
{
"version": "0.2.0",
"configurations": [
{
"name": "Wails: Debug myproject",
"type": "go",
"request": "launch",
"mode": "exec",
"program": "${workspaceFolder}/build/bin/myproject.exe",
"preLaunchTask": "build",
"cwd": "${workspaceFolder}",
"env": {},
"args": ["-assetdir", "frontend/src"]
}
]
}
```
### 配置安装和构建步骤
`tasks.json`文件对于默认项目很简单,因为不需要`npm install`或`npm run build`的步骤。对于具有前端构建步骤的项目,例如 svelte 模板,我们需要编辑`tasks.json`以添加安装和构建步骤:
```json title="tasks.json"
{
"version": "2.0.0",
"tasks": [
{
"label": "npm install",
"type": "npm",
"script": "install",
"options": {
"cwd": "${workspaceFolder}/frontend"
},
"presentation": {
"clear": true,
"panel": "shared",
"showReuseMessage": false
},
"problemMatcher": []
},
{
"label": "npm run build",
"type": "npm",
"script": "build",
"options": {
"cwd": "${workspaceFolder}/frontend"
},
"presentation": {
"clear": true,
"panel": "shared",
"showReuseMessage": false
},
"problemMatcher": []
},
{
"label": "build",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}"
},
"command": "go",
"args": ["build", "-tags", "dev", "-gcflags", "all=-N -l", "-o", "build/bin/vscode.exe"],
"dependsOn": ["npm install", "npm run build"]
}
]
}
```
:::info 功能改善
在未来,我们希望生成一个自动包含安装和构建步骤的`tasks.json`。
:::

View File

@@ -1,7 +1,3 @@
---
sidebar_position: 20
---
# 手动构建
Wails CLI 为项目做了很多繁重的工作,但有时需要手动构建项目。本文档将讨论 CLI 执行的不同操作以及如何以不同方式实现这一点。

View File

@@ -1,8 +1,3 @@
---
title: 从 v1 迁移
sidebar_position: 98
---
# 从 v1 迁移
## 概述
@@ -126,9 +121,9 @@ func (a *App) startup(ctx context.Context) {
这意味着生成单个 JS 和 CSS 文件的责任在于开发人员。这本质上需要使用繁琐的打包程序,例如 webpack。
在 v2 中Wails 不对的前端资源做任何预设,就像网络服务器一样。的所有应用程序资源都作为`embed.FS`.
在 v2 中Wails 不对的前端资源做任何预设,就像网络服务器一样。的所有应用程序资源都作为`embed.FS`.
**这意味着不需要打包的资源、将图像编码为 Base64 或尝试使用奇葩的打包配置来使用自定义字体。**
**这意味着不需要打包的资源、将图像编码为 Base64 或尝试使用奇葩的打包工具配置来使用自定义字体。**
在启动时Wails 将扫描给定的`embed.FS`的`index.html`并将其位置用作所有其他应用程序资源的根路径 - 就像网络服务器一样。
@@ -161,7 +156,7 @@ func main() {
}
```
当然,如果愿意,也可以使用打包。唯一的要求是在 Wails 中使用`embed.FS`,将最终的程序资源目录传递给[应用程序参数选项](/docs/reference/options#应用程序参数选项)的`Assets`键。
当然,如果愿意,也可以使用打包工具。唯一的要求是在 Wails 中使用`embed.FS`,将最终的程序资源目录传递给[应用程序参数选项](/docs/reference/options#应用程序参数选项)的`Assets`键。
### 项目配置

View File

@@ -1,7 +1,3 @@
---
sidebar_position: 15
---
# 模板
Wails 从预先创建的模板生成项目。在 v1 中,这是一组难以维护的项目,这些项目可能会过时。在 v2 中,为了增强社区的能力,为模板添加了一些新功能:
@@ -79,7 +75,7 @@ Renaming package-lock.json -> package-lock.tmpl.json...
- 一旦文件准备完毕,就可以通过运行命令来测试它:`wails init -n my-vue3-project -t .\wails-vue3-template\`
- 要测试新项目,请运行:`cd my-vue3-project` then `wails build`
- 项目编译完成后,运行它:`.\build\bin\my-vue3-project.exe`
- 应该有了一个功能齐全的 Vue3 应用程序:
- 应该有了一个功能齐全的 Vue3 应用程序:
<div className="text--center">
<img src="/img/vue3-template.png" width="50%" />

View File

@@ -1,7 +1,3 @@
---
sidebar_position: 2
---
# Windows 系统
此页面包含了在 Windows 上开发 Wails 应用程序相关的其他指南。

View File

@@ -1,21 +1,23 @@
---
title: 它如何工作
sidebar_position: 3
sidebar_position: 20
---
# 它如何工作?
Wails 应用程序是一个标准的 Go 应用程序,带有一个 webkit 前端。Wails 应用程序的架构是:
Wails 应用程序是一个带有一个 webkit 前端的标准的 Go 应用程序。 应用程序的 Go 部分由应用程序代码和一个运行时库组成,
该库提供了许多有用的操作,例如控制应用程序窗口。 前端是一个 webkit 窗口,将显示前端资源。 前端还可以使用运行时库的 Javascript 版本。
最后,可以将 Go 方法绑定到前端,这些将显示为可以调用的 Javascript 方法,就像它们是原生 Javascript 方法一样。
<div className="text--center">
<img src="/img/architecture.svg" width="75%" />
</div>
## 后端
## 主应用程序
### 概述
主应用程序,通常称为“后端”,由对`wails.Run()`的调用组成. 它接收应用程序配置,该配置说明应用程序应该有多大尺寸,标题栏应该显示什么,使用什么资源等。一个基本应用程序可能看起来像这样
主应用程序由对`wails.Run()`的调用组成. 它接受描述应用程序窗口大小、窗口标题、要使用的资源等的应用程序配置。基本应用程序可能如下所示
```go title="main.go"
package main
@@ -82,12 +84,12 @@ func (b *App) Greet(name string) string {
#### 资源
`Assets` 选项是必须的,因为不能拥有没有前端资源的 Wails 应用程序。这些资源可以是希望在 Web 应用程序中找到的任何文件 - html、js、css、svg、png 等。
不需要生成资源包- 纯文件即可。当应用程序启动时,它将尝试从的资源中加载`index.html`,并且那时起前端基本上将作为浏览器工作。值得注意的是 embed.FS
文件所在的位置没有要求。嵌入路径很可能使用了相对于的主应用程序代码的嵌套目录,例如 `frontend/dist`
`Assets` 选项是必须的,因为不能拥有没有前端资源的 Wails 应用程序。这些资源可以是希望在 Web 应用程序中找到的任何文件 - html、js、css、svg、png 等。
**不需要生成资源包**- 纯文件即可。当应用程序启动时,它将尝试从的资源中加载`index.html`,并且那时起前端基本上将作为浏览器工作。值得注意的是 embed.FS
文件所在的位置没有要求。嵌入路径很可能使用了相对于的主应用程序代码的嵌套目录,例如 `frontend/dist`
```go title="main.go"
// go:embed frontend/dist
//go:embed frontend/dist
var assets embed.FS
```
@@ -95,23 +97,30 @@ var assets embed.FS
由于生产二进制文件使用中包含在`embed.FS`的文件,因此应用程序不需要附带任何外部文件。
在`dev`模式下,资源从磁盘加载,任何更改都会导致“实时重新加载”。资源的位置需要传递给`dev`命令,并且很可能与嵌入路径相同。更多细节可以在[应用程序开发指南](/docs/guides/application-development)中找到
当使用`wails dev`命令在”dev“模式下,资源从磁盘加载,任何更改都会导致“实时重新加载”。资源的位置需要使用`-assetdir`传递给`wails dev`命令,并且很可能与嵌入路径相同
希望`embed.FS`将来我们可以从它本身计算出来。更多细节可以在[应用程序开发指南](/docs/guides/application-development)中找到。
#### 应用程序生命周期回调
在即将加载前端`index.html`之前,对 [应用启动回调](/docs/reference/options#应用启动回调) 中提供的函数进行回调。一个标准的 Go 上下文被传递给这个方法。
调用运行时需要此上下文,因此标准模式是保存此时对它的引用。在应用程序关闭之前,以同样的方式调用 [应用退出回调](/docs/reference/options#应用退出回调) 回调,
再次使用上下文。当前端加载所有资源时,还有一个 [前端 Dom 加载完成回调](/docs/reference/options#前端-dom-加载完成回调) 回调。
再次使用上下文。当前端完成加载`index.html`中所有资源时,还有一个 [前端 Dom 加载完成回调](/docs/reference/options#前端-dom-加载完成回调) 回调,相当于 Javascript 中的`body onload`事件
#### 方法绑定
`Bind`选项是 Wails 应用程序中最重要的参数选项之一。它指定向前端暴露哪些结构方法。当应用程序启动时,它会检查 `Bind` 中列出的结构实例,确定哪些方法是公开的(以大写字母开头),并将生成前端可以调用的那些方法的 Javascript 版本。
`Bind`选项是 Wails 应用程序中最重要的参数选项之一。它指定向前端暴露哪些结构方法。当应用程序启动时,它会检查 `Bind` 中列出的结构实例,
确定哪些方法是公开的(以大写字母开头),并将生成前端可以调用的那些方法的 Javascript 版本。
这些方法位于前端 `window.go.<packagename>.<struct>.<method>`。在上面的例子中,我们绑定 `app`,它有一个公开方法 `Greet`。这可以通过在 `Javascript` 中用 `window.go.main.App.Greet`调用。这些方法返回一个 Promise。成功的调用将导致 Go 调用的第一个返回值被传递给 resolve 处理程序。一个不成功的调用是将一个 Go 方法的第二个错误类型返回值传递回调用者。这是通过`reject`传回的。在上面的例子中Greet 只返回一个字符串,所以 `Javascript` 调用永远不会`reject` - 除非将无效数据传递给它。
这些方法位于前端 `window.go.<packagename>.<struct>.<method>`。在上面的例子中,我们绑定 `app`,它有一个公开方法 `Greet`。
这可以通过在 `Javascript` 中用 `window.go.main.App.Greet`调用。这些方法返回一个 Promise。成功的调用将导致 Go 调用的第一个返回值被传递给 resolve 处理程序。
一个不成功的调用是将一个 Go 方法的第二个错误类型返回值传递回调用者。这是通过`reject`传回的。在上面的例子中Greet 只返回一个字符串,
所以 `Javascript` 调用永远不会`reject` - 除非将无效数据传递给它。
所有数据类型都在 Go 和 Javascript 之间正确转换。包括结构体。如果从 Go 调用返回一个结构体,它将作为 `Javascript` Map 返回到的前端。注意:如果你想使用结构体,你必须为你的结构体字段定义`json` 标签!也可以将结构体发送回 Go。任何作为期望结构的参数传递的 Javascript Map 都将转换为该结构类型。为了使这个过程更容易,在 `dev`模式下,会生成一个 TypeScript 模块,定义绑定方法中使用的所有结构类型。使用此模块,可以构建原生 Javascript 对象并将其发送到 Go 代码。
所有数据类型都在 Go 和 Javascript 之间正确转换。包括结构体。如果从 Go 调用返回一个结构体,它将作为 `Javascript` Map 返回到的前端。
注意:如果您想使用结构体,您必须为您的结构体字段定义`json` 标签!也可以将结构体发送回 Go。任何作为期望结构的参数传递的 Javascript Map 都将转换为该结构类型。
为了使这个过程更容易,在 `dev`模式下,会生成一个 TypeScript 模块,定义绑定方法中使用的所有结构类型。使用此模块,可以构建原生 Javascript 对象并将其发送到 Go 代码。
关绑定的更多信息可以在[绑定示例](/docs/guides/application-development#binding-methods)页面中找到。
绑定的更多信息可以在[应用程序开发指南](/docs/guides/application-development)的[绑定方法](/docs/guides/application-development#绑定方法)一节中找到。
## 前端
@@ -126,7 +135,8 @@ var assets embed.FS
### 调用绑定的 Go 方法
所有绑定的 Go 方法都可以在`window.go.<package>.<struct>.<method>`调用. 如上一节所述,这些方法返回一个 Promise其中成功调用将值返回给 resolve 处理程序,错误将值返回给 reject 处理程序。
所有绑定的 Go 方法都可以在`window.go.<package>.<struct>.<method>`调用. 如上一节所述,这些方法返回一个 Promise
其中成功调用将值返回给 resolve 处理程序,错误将值返回给 reject 处理程序。
```go title="mycode.js"
window.go.main.App.Greet("Bill").then((result) => {
@@ -251,7 +261,7 @@ export class Person {
}
```
只要将 TypeScript 作为前端构建配置的一部分,就可以通过以下方式使用这些模型:
只要将 TypeScript 作为前端构建配置的一部分,就可以通过以下方式使用这些模型:
```js title="mycode.js"
import go from "./wailsjs/go/bindings";

View File

@@ -1,4 +1,4 @@
{
"label": "Reference",
"position": 3
"position": 40
}

View File

@@ -21,7 +21,7 @@ Wails CLI 有许多用于管理项目的命令。所有命令都以此方式运
| -l | 可用项目模板列表 | |
| -q | 禁止输出到控制台 | |
| -t "template name" | 要使用的项目模板。这可能是在 github 上托管的远程模板的 URL 的名称。 | vanilla |
| -ide | 生成 IDE 项目文件 | |
| -ide | 生成 IDE 项目文件 | |
| -f | 强制构建应用 | false |
示例:
@@ -41,13 +41,13 @@ Wails CLI 有许多用于管理项目的命令。所有命令都以此方式运
**Wails 项目不维护也不对第 3 方模板负责**
如果不确定某个模板,请检查 `package.json` 中运行的脚本和安装的模块。
如果不确定某个模板,请检查 `package.json` 中运行的脚本和安装的模块。
:::
## 构建
`wails build`用于将的项目编译为生产可用的二进制文件。
`wails build`用于将的项目编译为生产可用的二进制文件。
| 标志 | 描述 | 默认 |
| :------------------- | :----------------------------------------------------- | :------- |
@@ -68,7 +68,7 @@ Wails CLI 有许多用于管理项目的命令。所有命令都以此方式运
## 诊断检查
`wails doctor` 将运行诊断程序以确保的系统已准备好进行开发。
`wails doctor` 将运行诊断程序以确保的系统已准备好进行开发。
示例:
@@ -103,15 +103,15 @@ Your system is ready for Wails development!
## 开发
`wails dev` 用于以 "实时开发" 模式运行的应用。这意味着:
`wails dev` 用于以 "实时开发" 模式运行的应用。这意味着:
- 应用程序被编译并自动运行
- 一个观察者被启动,如果它检测到的 go 文件的变化,它将触发的开发应用程序的重新构建
- 启动一个网络服务器`http://localhost:34115`,通过 http 为的应用程序(不仅仅是前端)提供服务。这允许使用喜欢的浏览器开发扩展
- 一个观察者被启动,如果它检测到的 go 文件的变化,它将触发的开发应用程序的重新构建
- 启动一个网络服务器`http://localhost:34115`,通过 http 为的应用程序(不仅仅是前端)提供服务。这允许使用喜欢的浏览器开发扩展
- 所有应用程序资源都从磁盘加载。如果它们被更改,应用程序将自动重新加载(而不是重新构建)。所有连接的浏览器也将重新加载
- 生成的 JS 模块提供以下内容:
- 带有自动生成的 JSDoc 的 Go 方法的 Javascript 包装器,提供代码提示
- 的 Go 结构体的 TypeScript 版本,可以构造并传递给的后端方法
- 的 Go 结构体的 TypeScript 版本,可以构造并传递给的后端方法
- 生成第二个 JS 模块,为运行时提供包装器 + TS 声明
| 标志 | 描述 | 默认 |

Some files were not shown because too many files have changed in this diff Show More