From 54a401106bf5cd561e5304f922f402593c656a78 Mon Sep 17 00:00:00 2001 From: misitebao Date: Thu, 23 Sep 2021 02:08:58 +0800 Subject: [PATCH] [v2]feat: optimize the content of the default template --- .../templates/templates/svelte/app.tmpl.go | 5 ++ .../svelte/frontend/package.tmpl.json | 5 +- .../templates/templates/svelte/main.go.tmpl | 52 ------------------ .../templates/templates/svelte/main.tmpl.go | 54 +++++++++++++++++++ .../templates/templates/svelte/template.json | 4 +- .../templates/svelte/wails.tmpl.json | 4 +- .../templates/templates/vanilla/app.tmpl.go | 5 ++ .../templates/templates/vanilla/main.tmpl.go | 18 ++++--- .../templates/templates/vanilla/template.json | 4 +- .../templates/vanilla/wails.tmpl.json | 2 +- 10 files changed, 84 insertions(+), 69 deletions(-) delete mode 100644 v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/main.go.tmpl create mode 100644 v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/main.tmpl.go diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/app.tmpl.go index fab5aa32c..92697ab80 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/app.tmpl.go @@ -21,6 +21,11 @@ func (b *App) startup(ctx context.Context) { b.ctx = ctx } +// domReady is called after the front-end dom has been loaded +func (b App) domReady(ctx context.Context) { + // Add your action here +} + // shutdown is called at application termination func (b *App) shutdown(ctx context.Context) { // Perform your teardown here diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/package.tmpl.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/package.tmpl.json index 26be8a557..a49448c62 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/package.tmpl.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/package.tmpl.json @@ -23,5 +23,6 @@ }, "dependencies": { "sirv-cli": "^1.0.0" - } -,"author":"{{.AuthorName}}"} \ No newline at end of file + }, + "author": "{{.AuthorName}}" +} diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/main.go.tmpl b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/main.go.tmpl deleted file mode 100644 index 70a98b54a..000000000 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/main.go.tmpl +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( -"embed" -"log" - -"github.com/wailsapp/wails/v2/pkg/options/windows" - -"github.com/wailsapp/wails/v2" -"github.com/wailsapp/wails/v2/pkg/logger" -"github.com/wailsapp/wails/v2/pkg/options" -) - -//go:embed frontend/dist -var assets embed.FS - -func main() { - - // Create application with options - app := NewApp() - - err := wails.Run(&options.App{ -Title: "", -Width: 800, -Height: 600, -MinWidth: 400, -MinHeight: 400, -MaxWidth: 1280, -MaxHeight: 1024, -DisableResize: false, -Fullscreen: false, -Frameless: false, -StartHidden: false, -HideWindowOnClose: false, -RGBA: 0x000000FF, -Assets: assets, -Windows: &windows.Options{ -WebviewIsTransparent: true, -WindowIsTranslucent: true, -DisableWindowIcon: true, -}, -LogLevel: logger.DEBUG, -OnStartup: app.startup, -OnShutdown: app.shutdown, -Bind: []interface{}{ -app, -}, -}) -if err != nil { -log.Fatal(err) -} -} diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/main.tmpl.go new file mode 100644 index 000000000..20072c4c1 --- /dev/null +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/main.tmpl.go @@ -0,0 +1,54 @@ +package main + +import ( + "embed" + "log" + + "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/windows" +) + +//go:embed frontend/dist +var assets embed.FS + +func main() { + // Create an instance of the app structure + app := NewApp() + + // Create application with options + err := wails.Run(&options.App{ + Title: "{{.ProjectName}}", + Width: 720, + Height: 570, + MinWidth: 720, + MinHeight: 570, + MaxWidth: 1280, + MaxHeight: 740, + DisableResize: false, + Fullscreen: false, + Frameless: false, + StartHidden: false, + HideWindowOnClose: false, + RGBA: &options.RGBA{255, 255, 255, 255}, + Assets: assets, + LogLevel: logger.DEBUG, + OnStartup: app.startup, + OnDomReady: app.domReady, + OnShutdown: app.shutdown, + Bind: []interface{}{ + app, + }, + // Windows platform specific options + Windows: &windows.Options{ + WebviewIsTransparent: false, + WindowIsTranslucent: false, + DisableWindowIcon: false, + }, + }) + + if err != nil { + log.Fatal(err) + } +} diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/template.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/template.json index 912015c79..f04858241 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/template.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/template.json @@ -1,7 +1,7 @@ { "name": "Basic Svelte + Rollup", "shortname": "svelte", - "author": "Lea Anthony", + "author": "Lea Anthony ", "description": "Svelte template using rollup to bundle css, images and fonts", "helpurl": "https://github.com/wailsapp/wails" -} \ No newline at end of file +} diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/wails.tmpl.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/wails.tmpl.json index 16e81d970..b8d08108d 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/wails.tmpl.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/wails.tmpl.json @@ -2,10 +2,10 @@ "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "assetdir": "frontend/dist", - "frontend:build": "npm run build", "frontend:install": "npm install", + "frontend:build": "npm run build", "author": { "name": "{{.AuthorName}}", "email": "{{.AuthorEmail}}" } -} \ No newline at end of file +} diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/app.tmpl.go index 52b8cea63..1c47f5588 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/app.tmpl.go @@ -21,6 +21,11 @@ func (b *App) startup(ctx context.Context) { b.ctx = ctx } +// domReady is called after the front-end dom has been loaded +func (b App) domReady(ctx context.Context) { + // Add your action here +} + // shutdown is called at application termination func (b *App) shutdown(ctx context.Context) { // Perform your teardown here diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/main.tmpl.go index 2c27fa686..56ccd7e6d 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/main.tmpl.go @@ -14,10 +14,10 @@ import ( var assets embed.FS func main() { - - // Create application with options + // Create an instance of the app structure app := NewApp() + // Create application with options err := wails.Run(&options.App{ Title: "{{.ProjectName}}", Width: 720, @@ -33,17 +33,19 @@ func main() { HideWindowOnClose: false, RGBA: &options.RGBA{255, 255, 255, 255}, Assets: assets, + LogLevel: logger.DEBUG, + OnStartup: app.startup, + OnDomReady: app.domReady, + OnShutdown: app.shutdown, + Bind: []interface{}{ + app, + }, + // Windows platform specific options Windows: &windows.Options{ WebviewIsTransparent: false, WindowIsTranslucent: false, DisableWindowIcon: false, }, - LogLevel: logger.DEBUG, - OnStartup: app.startup, - OnShutdown: app.shutdown, - Bind: []interface{}{ - app, - }, }) if err != nil { diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/template.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/template.json index 66a1d3edb..f235e50e7 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/template.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/template.json @@ -1,7 +1,7 @@ { "name": "Vanilla HTML/JS/CSS", "shortname": "vanilla", - "author": "Lea Anthony", + "author": "Lea Anthony ", "description": "A simple template using only HTML/CSS/JS", "helpurl": "https://github.com/wailsapp/wails" -} \ No newline at end of file +} diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/wails.tmpl.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/wails.tmpl.json index 1a1aa9b20..0f6a23103 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/wails.tmpl.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/wails.tmpl.json @@ -6,4 +6,4 @@ "name": "{{.AuthorName}}", "email": "{{.AuthorEmail}}" } -} \ No newline at end of file +}