From 54a401106bf5cd561e5304f922f402593c656a78 Mon Sep 17 00:00:00 2001 From: misitebao Date: Thu, 23 Sep 2021 02:08:58 +0800 Subject: [PATCH 1/2] [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 fab5aa32..92697ab8 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 26be8a55..a49448c6 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 70a98b54..00000000 --- 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 00000000..20072c4c --- /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 912015c7..f0485824 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 16e81d97..b8d08108 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 52b8cea6..1c47f558 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 2c27fa68..56ccd7e6 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 66a1d3ed..f235e50e 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 1a1aa9b2..0f6a2310 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 +} From 23d53253f9eee149077d5c1597e2f2be9b2f762d Mon Sep 17 00:00:00 2001 From: misitebao Date: Thu, 23 Sep 2021 02:11:12 +0800 Subject: [PATCH 2/2] [v2]feat: optimize the template content of the template command --- .../generate/template/base/app.tmpl.go | 6 ++ .../template/base/frontend/dist/index.html | 10 +-- .../template/base/frontend/dist/main.css | 87 ++++++++++++------- .../template/base/frontend/dist/main.js | 21 +++-- .../template/base/frontend/package.tmpl.json | 12 +++ .../generate/template/base/main.tmpl.go | 33 +++++-- .../generate/template/base/wails.tmpl.json | 5 +- 7 files changed, 122 insertions(+), 52 deletions(-) create mode 100644 v2/cmd/wails/internal/commands/generate/template/base/frontend/package.tmpl.json 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 70e0f1ce..dd540dcd 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 @@ -17,9 +17,15 @@ func NewApp() *App { // startup is called at application startup func (a *App) startup(ctx context.Context) { + // Perform your setup here a.ctx = ctx } +// domReady is called after the front-end dom has been loaded +func (a App) domReady(ctx context.Context) { + // Add your action here +} + // 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/frontend/dist/index.html b/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/index.html index 001ed725..7f516f7f 100644 --- a/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/index.html +++ b/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/index.html @@ -5,12 +5,12 @@ - -
- - + +
Please enter your name below 👇
+
+ +
-
diff --git a/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/main.css b/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/main.css index 150d0486..af641246 100644 --- a/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/main.css +++ b/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/main.css @@ -1,47 +1,72 @@ - html { - text-align: center; - color: white; - background-color: rgba(0, 0, 0, 1); + background-color: rgba(33, 37, 43, 1); + text-align: center; + color: white; } body { - color: white; - font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; - margin: 0; + margin: 0; + color: white; + font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", + "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", + sans-serif; } @font-face { - font-family: 'Nunito'; - font-style: normal; - font-weight: 400; - src: local(''), - url('assets/fonts/nunito-v16-latin-regular.woff2') format('woff2') + font-family: "Nunito"; + font-style: normal; + font-weight: 400; + src: local(""), + url("assets/fonts/nunito-v16-latin-regular.woff2") format("woff2"); } -#result { - margin-top: 1rem; +.logo { + display: block; + width: 35%; + height: 35%; + margin: auto; + padding: 15% 0 0; + background-position: center; + background-repeat: no-repeat; + background-image: url("./assets/images/logo-dark.svg"); +} +.result { + height: 20px; + line-height: 20px; + margin: 1.5rem auto; +} +.input-box .btn { + width: 60px; + height: 30px; + line-height: 30px; + border-radius: 3px; + border: none; + margin: 0 0 0 20px; + padding: 0 8px; + cursor: pointer; +} +.input-box .btn:hover { + background-image: linear-gradient(to top, #cfd9df 0%, #e2ebf0 100%); + color: #333333; } -button { - -webkit-appearance: default-button; - padding: 6px; +.input-box .input { + border: none; + border-radius: 3px; + outline: none; + height: 30px; + line-height: 30px; + padding: 0 10px; + background-color: rgba(240, 240, 240, 1); + -webkit-font-smoothing: antialiased; } -#name { - border-radius: 3px; - outline: none; - height: 20px; - -webkit-font-smoothing: antialiased; +.input-box .input:hover { + border: none; + background-color: rgba(255, 255, 255, 1); } -#logo { - width: 40%; - height: 40%; - padding-top: 20%; - margin: auto; - display: block; - background-position: center; - background-repeat: no-repeat; - background-image: url("./assets/images/logo-dark.svg"); +.input-box .input:focus { + border: none; + background-color: rgba(255, 255, 255, 1); } diff --git a/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/main.js b/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/main.js index fda8cc7d..db404e45 100644 --- a/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/main.js +++ b/v2/cmd/wails/internal/commands/generate/template/base/frontend/dist/main.js @@ -5,12 +5,19 @@ nameElement.focus(); // Setup the greet function window.greet = function () { - // Get name - let name = nameElement.value; + // Get name + let name = nameElement.value; - // Call App.Greet(name) - window.go.main.App.Greet(name).then((result) => { - // Update result with data back from App.Greet() - document.getElementById("result").innerText = result; - }); + // Call App.Greet(name) + window.go.main.App.Greet(name).then((result) => { + // Update result with data back from App.Greet() + document.getElementById("result").innerText = result; + }); }; + +nameElement.onkeydown = function (e) { + console.log(e) + if (e.keyCode == 13) { + window.greet() + } +} \ No newline at end of file diff --git a/v2/cmd/wails/internal/commands/generate/template/base/frontend/package.tmpl.json b/v2/cmd/wails/internal/commands/generate/template/base/frontend/package.tmpl.json new file mode 100644 index 00000000..01780288 --- /dev/null +++ b/v2/cmd/wails/internal/commands/generate/template/base/frontend/package.tmpl.json @@ -0,0 +1,12 @@ +{ + "name": "{{.ProjectName}}", + "version": "1.0.0", + "description": "", + "main": "", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "" + }, + "keywords": [], + "author": "{{.AuthorName}}" +} 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 9cfd556a..4bec207b 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 @@ -5,28 +5,49 @@ import ( "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 application with options + // Create an instance of the app structure app := NewApp() + // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + // 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/generate/template/base/wails.tmpl.json b/v2/cmd/wails/internal/commands/generate/template/base/wails.tmpl.json index 82aa8f45..b8d08108 100644 --- a/v2/cmd/wails/internal/commands/generate/template/base/wails.tmpl.json +++ b/v2/cmd/wails/internal/commands/generate/template/base/wails.tmpl.json @@ -2,11 +2,10 @@ "name": "{{.ProjectName}}", "outputfilename": "{{.BinaryName}}", "assetdir": "frontend/dist", - "html": "frontend/dist/index.html", - "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 +}