From a971751dabf2f1cb47e43d9babf5b131bc6b0865 Mon Sep 17 00:00:00 2001 From: Misitebao Date: Sun, 27 Feb 2022 17:40:55 +0800 Subject: [PATCH] feat(cli): optimized template generation (#1166) * feat(cli): update base template configuration * feat: optimize template project script (https://github.com/wailsapp/wails/issues/1165) --- .../generate/template/base/app.tmpl.go | 7 ++++ .../base/{go.mod.tmpl => go.tmpl.mod} | 0 .../generate/template/base/main.tmpl.go | 41 ++++++++++++++++--- .../generate/template/base/package.json | 16 -------- .../template/base/scripts/build-macos-arm.sh | 9 ++++ .../base/scripts/build-macos-intel.sh | 9 ++++ .../template/base/scripts/build-macos.sh | 9 ++++ .../template/base/scripts/build-windows.sh | 9 ++++ .../generate/template/base/scripts/build.sh | 9 ++++ .../base/scripts/install-wails-cli.sh | 14 +++++++ 10 files changed, 101 insertions(+), 22 deletions(-) rename v2/cmd/wails/internal/commands/generate/template/base/{go.mod.tmpl => go.tmpl.mod} (100%) delete mode 100644 v2/cmd/wails/internal/commands/generate/template/base/package.json create mode 100644 v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos-arm.sh create mode 100644 v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos-intel.sh create mode 100644 v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos.sh create mode 100644 v2/cmd/wails/internal/commands/generate/template/base/scripts/build-windows.sh create mode 100644 v2/cmd/wails/internal/commands/generate/template/base/scripts/build.sh create mode 100644 v2/cmd/wails/internal/commands/generate/template/base/scripts/install-wails-cli.sh diff --git a/v2/cmd/wails/internal/commands/generate/template/base/app.tmpl.go b/v2/cmd/wails/internal/commands/generate/template/base/app.tmpl.go index dd540dcd..97ab5861 100644 --- a/v2/cmd/wails/internal/commands/generate/template/base/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/generate/template/base/app.tmpl.go @@ -26,6 +26,13 @@ func (a App) domReady(ctx context.Context) { // Add your action here } +// beforeClose is called when the application is about to quit, +// either by clicking the window close button or calling runtime.Quit. +// Returning true will cause the application to continue, false will continue shutdown as normal. +func (a *App) beforeClose(ctx context.Context) (prevent bool) { + return false +} + // shutdown is called at application termination func (a *App) shutdown(ctx context.Context) { // Perform your teardown here diff --git a/v2/cmd/wails/internal/commands/generate/template/base/go.mod.tmpl b/v2/cmd/wails/internal/commands/generate/template/base/go.tmpl.mod similarity index 100% rename from v2/cmd/wails/internal/commands/generate/template/base/go.mod.tmpl rename to v2/cmd/wails/internal/commands/generate/template/base/go.tmpl.mod diff --git a/v2/cmd/wails/internal/commands/generate/template/base/main.tmpl.go b/v2/cmd/wails/internal/commands/generate/template/base/main.tmpl.go index 096fd5fb..8fca28aa 100644 --- a/v2/cmd/wails/internal/commands/generate/template/base/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/generate/template/base/main.tmpl.go @@ -7,23 +7,27 @@ import ( "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/logger" "github.com/wailsapp/wails/v2/pkg/options" + "github.com/wailsapp/wails/v2/pkg/options/mac" "github.com/wailsapp/wails/v2/pkg/options/windows" ) //go:embed frontend/dist var assets embed.FS +//go:embed build/appicon.png +var icon []byte + func main() { // Create an instance of the app structure app := NewApp() // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - // MinWidth: 720, - // MinHeight: 570, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + MinWidth: 1024, + MinHeight: 768, // MaxWidth: 1280, // MaxHeight: 740, DisableResize: false, @@ -31,12 +35,16 @@ func main() { Frameless: false, StartHidden: false, HideWindowOnClose: false, - RGBA: &options.RGBA{255, 255, 255, 255}, + RGBA: &options.RGBA{R: 255, G: 255, B: 255, A: 255}, Assets: assets, + Menu: nil, + Logger: nil, LogLevel: logger.DEBUG, OnStartup: app.startup, OnDomReady: app.domReady, + OnBeforeClose: app.beforeClose, OnShutdown: app.shutdown, + WindowStartState: options.Normal, Bind: []interface{}{ app, }, @@ -45,6 +53,27 @@ func main() { WebviewIsTransparent: false, WindowIsTranslucent: false, DisableWindowIcon: false, + // DisableFramelessWindowDecorations: false, + WebviewUserDataPath: "", + }, + // Mac platform specific options + Mac: &mac.Options{ + TitleBar: &mac.TitleBar{ + TitlebarAppearsTransparent: true, + HideTitle: false, + HideTitleBar: false, + FullSizeContent: false, + UseToolbar: false, + HideToolbarSeparator: true, + }, + Appearance: mac.NSAppearanceNameDarkAqua, + WebviewIsTransparent: true, + WindowIsTranslucent: true, + About: &mac.AboutInfo{ + Title: "{{.ProjectName}}", + Message: "", + Icon: icon, + }, }, }) diff --git a/v2/cmd/wails/internal/commands/generate/template/base/package.json b/v2/cmd/wails/internal/commands/generate/template/base/package.json deleted file mode 100644 index 5d372575..00000000 --- a/v2/cmd/wails/internal/commands/generate/template/base/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "{{.ProjectName}}", - "author": "", - "private": true, - "scripts": { - "install": "go install github.com/wailsapp/wails/v2/cmd/wails@latest", - "build": "wails build --clean", - "build:macos": "npm run build -- --platform darwin/universal", - "build:macos-arm": "npm run build -- --platform darwin/arm64", - "build:macos-intel": "npm run build -- --platform darwin", - "build:windows": "npm run build -- --platform windows/amd64" - }, - "workspaces": [ - "frontend" - ] -} \ No newline at end of file diff --git a/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos-arm.sh b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos-arm.sh new file mode 100644 index 00000000..bc6ee0ac --- /dev/null +++ b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos-arm.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +echo -e "Start running the script..." +cd ../ + +echo -e "Start building the app for macos platform..." +wails build --clean --platform darwin/arm64 + +echo -e "End running the script!" diff --git a/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos-intel.sh b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos-intel.sh new file mode 100644 index 00000000..f359f633 --- /dev/null +++ b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos-intel.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +echo -e "Start running the script..." +cd ../ + +echo -e "Start building the app for macos platform..." +wails build --clean --platform darwin + +echo -e "End running the script!" diff --git a/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos.sh b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos.sh new file mode 100644 index 00000000..d61531fd --- /dev/null +++ b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-macos.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +echo -e "Start running the script..." +cd ../ + +echo -e "Start building the app for macos platform..." +wails build --clean --platform darwin/universal + +echo -e "End running the script!" diff --git a/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-windows.sh b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-windows.sh new file mode 100644 index 00000000..47b77897 --- /dev/null +++ b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build-windows.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +echo -e "Start running the script..." +cd ../ + +echo -e "Start building the app for windows platform..." +wails build --clean --platform windows/amd64 + +echo -e "End running the script!" diff --git a/v2/cmd/wails/internal/commands/generate/template/base/scripts/build.sh b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build.sh new file mode 100644 index 00000000..20ab7eb2 --- /dev/null +++ b/v2/cmd/wails/internal/commands/generate/template/base/scripts/build.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +echo -e "Start running the script..." +cd ../ + +echo -e "Start building the app..." +wails build --clean + +echo -e "End running the script!" diff --git a/v2/cmd/wails/internal/commands/generate/template/base/scripts/install-wails-cli.sh b/v2/cmd/wails/internal/commands/generate/template/base/scripts/install-wails-cli.sh new file mode 100644 index 00000000..7539d8e3 --- /dev/null +++ b/v2/cmd/wails/internal/commands/generate/template/base/scripts/install-wails-cli.sh @@ -0,0 +1,14 @@ +#! /bin/bash + +echo -e "Start running the script..." +cd ../ + +echo -e "Current Go version: \c" +go version + +echo -e "Install the Wails command line tool..." +go install github.com/wailsapp/wails/v2/cmd/wails@latest + +echo -e "Successful installation!" + +echo -e "End running the script!"