From 912d7cf34b68fe98bacb99140e329df27736cd7f Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sun, 1 May 2022 10:18:38 +1000 Subject: [PATCH] Add startup method to templates by default --- .../initialise/templates/base/app.tmpl.go | 6 + .../initialise/templates/base/main.tmpl.go | 10 +- .../templates/templates/lit-ts/app.tmpl.go | 6 + .../templates/lit-ts/frontend/tsconfig.json | 16 +- .../lit-ts/frontend/tsconfig.node.json | 4 +- .../templates/templates/lit-ts/main.tmpl.go | 10 +- .../templates/templates/lit/app.tmpl.go | 6 + .../templates/lit/frontend/src/favicon.svg | 29 ++- .../templates/templates/lit/main.tmpl.go | 10 +- .../templates/templates/preact-ts/app.tmpl.go | 6 + .../preact-ts/frontend/src/preact.d.ts | 1 + .../preact-ts/frontend/tsconfig.json | 16 +- .../preact-ts/frontend/tsconfig.node.json | 4 +- .../preact-ts/frontend/vite.config.ts | 2 +- .../templates/preact-ts/main.tmpl.go | 10 +- .../templates/templates/preact/app.tmpl.go | 6 + .../templates/preact/frontend/vite.config.js | 2 +- .../templates/templates/preact/main.tmpl.go | 10 +- .../templates/templates/react-ts/app.tmpl.go | 6 + .../templates/react-ts/frontend/tsconfig.json | 16 +- .../react-ts/frontend/tsconfig.node.json | 4 +- .../react-ts/frontend/vite.config.ts | 2 +- .../templates/templates/react-ts/main.tmpl.go | 10 +- .../templates/templates/react/app.tmpl.go | 6 + .../templates/react/frontend/vite.config.js | 2 +- .../templates/templates/react/main.tmpl.go | 10 +- .../templates/templates/svelte-ts/app.tmpl.go | 6 + .../frontend/.vscode/extensions.json | 4 +- .../templates/svelte-ts/frontend/README.md | 34 +--- .../svelte-ts/frontend/tsconfig.json | 13 +- .../svelte-ts/frontend/tsconfig.node.json | 4 +- .../svelte-ts/frontend/vite.config.ts | 4 +- .../templates/svelte-ts/main.tmpl.go | 10 +- .../templates/templates/svelte/app.tmpl.go | 6 + .../templates/svelte/frontend/README.md | 3 +- .../svelte/frontend/src/assets/fonts/OFL.txt | 186 +++++++++--------- .../templates/svelte/frontend/vite.config.js | 4 +- .../templates/templates/svelte/main.tmpl.go | 10 +- .../templates/vanilla-ts/app.tmpl.go | 6 + .../vanilla-ts/frontend/tsconfig.json | 9 +- .../templates/vanilla-ts/main.tmpl.go | 10 +- .../templates/templates/vanilla/app.tmpl.go | 6 + .../templates/templates/vanilla/main.tmpl.go | 10 +- .../templates/templates/vue-ts/app.tmpl.go | 6 + .../vue-ts/frontend/.vscode/extensions.json | 4 +- .../templates/vue-ts/frontend/README.md | 16 +- .../templates/vue-ts/frontend/src/env.d.ts | 8 +- .../vue-ts/frontend/tsconfig.node.json | 4 +- .../templates/vue-ts/frontend/vite.config.ts | 2 +- .../templates/templates/vue-ts/main.tmpl.go | 10 +- .../templates/templates/vue/app.tmpl.go | 6 + .../vue/frontend/.vscode/extensions.json | 4 +- .../templates/vue/frontend/README.md | 6 +- .../templates/templates/vue/main.tmpl.go | 10 +- v2/internal/frontend/runtime/ipc_websocket.js | 8 +- .../frontend/runtime/runtime_dev_desktop.js | 2 +- 56 files changed, 318 insertions(+), 303 deletions(-) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/base/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/base/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/base/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/base/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/base/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/base/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/base/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/base/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/frontend/tsconfig.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/frontend/tsconfig.json index 342653e17..91a731fd8 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/frontend/tsconfig.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/frontend/tsconfig.json @@ -1,11 +1,7 @@ { "compilerOptions": { "module": "esnext", - "lib": [ - "es2017", - "dom", - "dom.iterable" - ], + "lib": ["es2017", "dom", "dom.iterable"], "declaration": true, "emitDeclarationOnly": true, "outDir": "./types", @@ -22,12 +18,6 @@ "useDefineForClassFields": false, "skipLibCheck": true }, - "include": [ - "src/**/*.ts" - ], - "references": [ - { - "path": "./tsconfig.node.json" - } - ] + "include": ["src/**/*.ts"], + "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/frontend/tsconfig.node.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/frontend/tsconfig.node.json index fe874096b..e993792cb 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/frontend/tsconfig.node.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/frontend/tsconfig.node.json @@ -4,7 +4,5 @@ "module": "esnext", "moduleResolution": "node" }, - "include": [ - "vite.config.ts" - ] + "include": ["vite.config.ts"] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit-ts/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/frontend/src/favicon.svg b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/frontend/src/favicon.svg index 5e7e66781..de4aeddc1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/frontend/src/favicon.svg +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/frontend/src/favicon.svg @@ -1,18 +1,15 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/lit/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/src/preact.d.ts b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/src/preact.d.ts index e69de29bb..ac79d62a4 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/src/preact.d.ts +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/src/preact.d.ts @@ -0,0 +1 @@ +import JSX = preact.JSX diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/tsconfig.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/tsconfig.json index d6f1807ef..0a24dec18 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/tsconfig.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/tsconfig.json @@ -2,11 +2,7 @@ "compilerOptions": { "target": "ESNext", "useDefineForClassFields": true, - "lib": [ - "DOM", - "DOM.Iterable", - "ESNext" - ], + "lib": ["DOM", "DOM.Iterable", "ESNext"], "allowJs": false, "skipLibCheck": true, "esModuleInterop": false, @@ -22,12 +18,6 @@ "jsxFactory": "h", "jsxFragmentFactory": "Fragment" }, - "include": [ - "src" - ], - "references": [ - { - "path": "./tsconfig.node.json" - } - ] + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/tsconfig.node.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/tsconfig.node.json index fe874096b..e993792cb 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/tsconfig.node.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/tsconfig.node.json @@ -4,7 +4,5 @@ "module": "esnext", "moduleResolution": "node" }, - "include": [ - "vite.config.ts" - ] + "include": ["vite.config.ts"] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/vite.config.ts b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/vite.config.ts index 25845ba4b..e3bdaffe8 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/vite.config.ts +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/frontend/vite.config.ts @@ -1,4 +1,4 @@ -import {defineConfig} from 'vite' +import { defineConfig } from 'vite' import preact from '@preact/preset-vite' // https://vitejs.dev/config/ diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact-ts/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/frontend/vite.config.js b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/frontend/vite.config.js index 25845ba4b..e3bdaffe8 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/frontend/vite.config.js +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/frontend/vite.config.js @@ -1,4 +1,4 @@ -import {defineConfig} from 'vite' +import { defineConfig } from 'vite' import preact from '@preact/preset-vite' // https://vitejs.dev/config/ diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/preact/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/tsconfig.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/tsconfig.json index 823e83d11..3d0a51a86 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/tsconfig.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/tsconfig.json @@ -2,11 +2,7 @@ "compilerOptions": { "target": "ESNext", "useDefineForClassFields": true, - "lib": [ - "DOM", - "DOM.Iterable", - "ESNext" - ], + "lib": ["DOM", "DOM.Iterable", "ESNext"], "allowJs": false, "skipLibCheck": true, "esModuleInterop": false, @@ -20,12 +16,6 @@ "noEmit": true, "jsx": "react-jsx" }, - "include": [ - "src" - ], - "references": [ - { - "path": "./tsconfig.node.json" - } - ] + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/tsconfig.node.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/tsconfig.node.json index fe874096b..e993792cb 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/tsconfig.node.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/tsconfig.node.json @@ -4,7 +4,5 @@ "module": "esnext", "moduleResolution": "node" }, - "include": [ - "vite.config.ts" - ] + "include": ["vite.config.ts"] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/vite.config.ts b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/vite.config.ts index 49550655a..b1b5f91e5 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/vite.config.ts +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/frontend/vite.config.ts @@ -1,4 +1,4 @@ -import {defineConfig} from 'vite' +import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/react-ts/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/react/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/react/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/react/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/react/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/react/frontend/vite.config.js b/v2/cmd/wails/internal/commands/initialise/templates/templates/react/frontend/vite.config.js index 49550655a..b1b5f91e5 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/react/frontend/vite.config.js +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/react/frontend/vite.config.js @@ -1,4 +1,4 @@ -import {defineConfig} from 'vite' +import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/react/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/react/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/react/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/react/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/.vscode/extensions.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/.vscode/extensions.json index b869ef8e2..bdef82015 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/.vscode/extensions.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/.vscode/extensions.json @@ -1,5 +1,3 @@ { - "recommendations": [ - "svelte.svelte-vscode" - ] + "recommendations": ["svelte.svelte-vscode"] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/README.md b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/README.md index e4ecb2286..4ef762ffe 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/README.md +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/README.md @@ -4,14 +4,11 @@ This template should help get you started developing with Svelte and TypeScript ## Recommended IDE Setup -[VS Code](https://code.visualstudio.com/) -+ [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). +[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). ## Need an official Svelte framework? -Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its -serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, -and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. +Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. ## Technical considerations @@ -21,40 +18,27 @@ and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. - It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app. `vite dev` and `vite build` wouldn't work in a SvelteKit environment, for example. -This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account -the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the -other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte -project. +This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project. -Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been -structured similarly to SvelteKit so that it is easy to migrate. +Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate. **Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?** -Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash -references keeps the default TypeScript setting of accepting type information from the entire workspace, while also -adding `svelte` and `vite/client` type information. +Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information. **Why include `.vscode/extensions.json`?** -Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to -install the recommended extension upon opening the project. +Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project. **Why enable `allowJs` in the TS template?** -While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of -JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: -not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing -JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant. +While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant. **Why is HMR not preserving my local component state?** -HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` -and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the -details [here](https://github.com/rixo/svelte-hmr#svelte-hmr). +HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr). -If you have state that's important to retain within a component, consider creating an external store which would not be -replaced by HMR. +If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR. ```ts // store.ts diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/tsconfig.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/tsconfig.json index 7d91f5a99..96bfd81aa 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/tsconfig.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/tsconfig.json @@ -16,15 +16,6 @@ "checkJs": true, "isolatedModules": true }, - "include": [ - "src/**/*.d.ts", - "src/**/*.ts", - "src/**/*.js", - "src/**/*.svelte" - ], - "references": [ - { - "path": "./tsconfig.node.json" - } - ] + "include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"], + "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/tsconfig.node.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/tsconfig.node.json index fe874096b..e993792cb 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/tsconfig.node.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/tsconfig.node.json @@ -4,7 +4,5 @@ "module": "esnext", "moduleResolution": "node" }, - "include": [ - "vite.config.ts" - ] + "include": ["vite.config.ts"] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/vite.config.ts b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/vite.config.ts index d37616f9a..401b4d4bd 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/vite.config.ts +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/frontend/vite.config.ts @@ -1,5 +1,5 @@ -import {defineConfig} from 'vite' -import {svelte} from '@sveltejs/vite-plugin-svelte' +import { defineConfig } from 'vite' +import { svelte } from '@sveltejs/vite-plugin-svelte' // https://vitejs.dev/config/ export default defineConfig({ diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte-ts/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, 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 07f559997..af53038a1 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 @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/README.md b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/README.md index 13038462d..50ea7ed3b 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/README.md +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/README.md @@ -4,8 +4,7 @@ This template should help get you started developing with Svelte in Vite. ## Recommended IDE Setup -[VS Code](https://code.visualstudio.com/) -+ [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). +[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). ## Need an official Svelte framework? diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/src/assets/fonts/OFL.txt b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/src/assets/fonts/OFL.txt index bad763db1..9cac04ce8 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/src/assets/fonts/OFL.txt +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/src/assets/fonts/OFL.txt @@ -1,93 +1,93 @@ -Copyright 2016 The Nunito Project Authors (contact@sansoxygen.com), - -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. +Copyright 2016 The Nunito Project Authors (contact@sansoxygen.com), + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/vite.config.js b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/vite.config.js index d37616f9a..401b4d4bd 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/vite.config.js +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/frontend/vite.config.js @@ -1,5 +1,5 @@ -import {defineConfig} from 'vite' -import {svelte} from '@sveltejs/vite-plugin-svelte' +import { defineConfig } from 'vite' +import { svelte } from '@sveltejs/vite-plugin-svelte' // https://vitejs.dev/config/ export default defineConfig({ 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 index abf01197e..c60affe67 100644 --- 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 @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/frontend/tsconfig.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/frontend/tsconfig.json index 62645742d..fbd022532 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/frontend/tsconfig.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/frontend/tsconfig.json @@ -3,10 +3,7 @@ "target": "ESNext", "useDefineForClassFields": true, "module": "ESNext", - "lib": [ - "ESNext", - "DOM" - ], + "lib": ["ESNext", "DOM"], "moduleResolution": "Node", "strict": true, "sourceMap": true, @@ -19,7 +16,5 @@ "noImplicitReturns": true, "skipLibCheck": true }, - "include": [ - "src" - ] + "include": ["src"] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/main.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/main.tmpl.go index abf01197e..c60affe67 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/main.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla-ts/main.tmpl.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, 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 07f559997..af53038a1 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 @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) 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 abf01197e..c60affe67 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 @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" ) @@ -15,10 +16,11 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "{{.ProjectName}}", - Width: 1024, - Height: 768, - Assets: assets, + Title: "{{.ProjectName}}", + Width: 1024, + Height: 768, + Assets: assets, + OnStartup: app.startup, Bind: []interface{}{ app, }, diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/app.tmpl.go b/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/app.tmpl.go index 07f559997..af53038a1 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/app.tmpl.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/app.tmpl.go @@ -15,6 +15,12 @@ func NewApp() *App { return &App{} } +// startup is called when the app starts. The context is saved +// so we can call the runtime methods +func (a *App) startup(ctx context.Context) { + a.ctx = ctx +} + // Greet returns a greeting for the given name func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/frontend/.vscode/extensions.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/frontend/.vscode/extensions.json index f9679ed90..3dc5b08bc 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/frontend/.vscode/extensions.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/frontend/.vscode/extensions.json @@ -1,5 +1,3 @@ { - "recommendations": [ - "johnsoncodehk.volar" - ] + "recommendations": ["johnsoncodehk.volar"] } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/frontend/README.md b/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/frontend/README.md index db4b47357..e43251672 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/frontend/README.md +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vue-ts/frontend/README.md @@ -1,24 +1,16 @@ # Vue 3 + TypeScript + Vite -This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue -3 `