From 0422921dc749026842fe47f67c4cba7cd7a73c4a Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 20 Nov 2020 14:45:35 +1100 Subject: [PATCH] Misc documentation updates --- .../frontend/src/components/CodeBlock.svelte | 2 +- .../src/pages/System/Platform/Platform.svelte | 4 +- .../frontend/src/pages/Window/Window/code.go | 39 +++++++++++++++++-- .../frontend/src/pages/Window/Window/code.jsx | 19 ++------- .../src/pages/browser/Browser/code.jsx | 17 ++------ .../src/pages/events/OnMultiple/code.jsx | 10 ++--- 6 files changed, 50 insertions(+), 41 deletions(-) diff --git a/v2/test/kitchensink/frontend/src/components/CodeBlock.svelte b/v2/test/kitchensink/frontend/src/components/CodeBlock.svelte index 35138a82..deb62fb7 100644 --- a/v2/test/kitchensink/frontend/src/components/CodeBlock.svelte +++ b/v2/test/kitchensink/frontend/src/components/CodeBlock.svelte @@ -61,7 +61,7 @@ {/if} -
+
{showCode?'▼':'▶'} Example Code diff --git a/v2/test/kitchensink/frontend/src/pages/System/Platform/Platform.svelte b/v2/test/kitchensink/frontend/src/pages/System/Platform/Platform.svelte index 2bbaaafd..c226846a 100644 --- a/v2/test/kitchensink/frontend/src/pages/System/Platform/Platform.svelte +++ b/v2/test/kitchensink/frontend/src/pages/System/Platform/Platform.svelte @@ -31,8 +31,8 @@ } } - $: testcodeJs = "import { runtime } from '@wails/runtime';\nruntime.Log.Info('Platform from JS runtime: ' + runtime.System.Platform);"; - $: testcodeGo = '// runtime is given through WailsInit()\nruntime.Log.Info("Platform from Go runtime: " + runtime.System.Platform)'; + $: testcodeJs = "import { runtime } from '@wails/runtime';\nruntime.Log.Info('Platform from JS runtime: ' + runtime.System.Platform());"; + $: testcodeGo = '// runtime is given through WailsInit()\nruntime.Log.Info("Platform from Go runtime: " + runtime.System.Platform())'; diff --git a/v2/test/kitchensink/frontend/src/pages/Window/Window/code.go b/v2/test/kitchensink/frontend/src/pages/Window/Window/code.go index 055ed2ef..e7b93fa3 100644 --- a/v2/test/kitchensink/frontend/src/pages/Window/Window/code.go +++ b/v2/test/kitchensink/frontend/src/pages/Window/Window/code.go @@ -1,11 +1,44 @@ package main -import wails "github.com/wailsapp/wails/v2" +import ( + "image" + "os" + + wails "github.com/wailsapp/wails/v2" + "github.com/wailsapp/wails/v2/internal/runtime" +) type MyStruct struct { runtime *wails.Runtime + image *runtime.Store } -func (l *MyStruct) ShowHelp() { - l.runtime.Browser.Open("https://www.youtube.com/watch?v=dQw4w9WgXcQ") +func (n *Notepad) WailsInit(runtime *wails.Runtime) error { + n.runtime = runtime + n.image = runtime.Store.New("mainimage") + return nil +} + +func (n *MyStruct) LoadImage(filename string) error { + + // Load filedata + f, err := os.Open(filename) + if err != nil { + return err + } + defer f.Close() + + img, fmtName, err := image.DecodeConfig(f) + if err != nil { + return err + } + + // Sync the image data with the frontend + n.image.Set(img) + + // Get the size of the image + n.runtime.Window.SetSize(img.Width, img.Height) + + // Place window in center + n.runtime.Window.Center() } diff --git a/v2/test/kitchensink/frontend/src/pages/Window/Window/code.jsx b/v2/test/kitchensink/frontend/src/pages/Window/Window/code.jsx index 652c2823..f80bf637 100644 --- a/v2/test/kitchensink/frontend/src/pages/Window/Window/code.jsx +++ b/v2/test/kitchensink/frontend/src/pages/Window/Window/code.jsx @@ -1,17 +1,6 @@ -import { Log } from '@wails/runtime'; +import { Window } from '@wails/runtime'; -function doSomeOperation() { - // Do things - let value = doSomething(); - Log.Print("A raw message"); - Log.Trace("I got: " + value); - Log.Debug("A debug message"); - Log.Info("An Info message"); - Log.Warning("A Warning message"); - Log.Error("An Error message"); -} - -function abort() { - // Do some things - Log.Fatal("I accidentally the whole application!"); +function resize(imageWidth, imageHeight) { + Window.SetSize(imageWidth, imageHeight); + Window.Center(); } \ No newline at end of file diff --git a/v2/test/kitchensink/frontend/src/pages/browser/Browser/code.jsx b/v2/test/kitchensink/frontend/src/pages/browser/Browser/code.jsx index 652c2823..d4600d1f 100644 --- a/v2/test/kitchensink/frontend/src/pages/browser/Browser/code.jsx +++ b/v2/test/kitchensink/frontend/src/pages/browser/Browser/code.jsx @@ -1,17 +1,6 @@ -import { Log } from '@wails/runtime'; +import { Browser } from '@wails/runtime'; -function doSomeOperation() { - // Do things - let value = doSomething(); - Log.Print("A raw message"); - Log.Trace("I got: " + value); - Log.Debug("A debug message"); - Log.Info("An Info message"); - Log.Warning("A Warning message"); - Log.Error("An Error message"); -} - -function abort() { +function showHelp() { // Do some things - Log.Fatal("I accidentally the whole application!"); + Browser.Open("https://www.youtube.com/watch?v=dQw4w9WgXcQ") } \ No newline at end of file diff --git a/v2/test/kitchensink/frontend/src/pages/events/OnMultiple/code.jsx b/v2/test/kitchensink/frontend/src/pages/events/OnMultiple/code.jsx index 9bc9ae42..d6157fc8 100644 --- a/v2/test/kitchensink/frontend/src/pages/events/OnMultiple/code.jsx +++ b/v2/test/kitchensink/frontend/src/pages/events/OnMultiple/code.jsx @@ -1,8 +1,6 @@ import { Events } from '@wails/runtime'; -let notes = []; - -// Do some things -Events.On("notes loaded", (newNotes) => { - notes = newNotes; -}); +// Respond to the unlock event 3 times +Events.OnMultiple("unlock", (password) => { + // Check password +}, 3);