Add System to kitchensink

This commit is contained in:
Lea Anthony
2020-10-23 11:46:12 +11:00
parent 5a85a6e4f9
commit e6036d31cf
11 changed files with 127 additions and 17 deletions

View File

@@ -135,9 +135,9 @@
}
},
"@wails/runtime": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.0.9.tgz",
"integrity": "sha512-BeApNQnMjwC/gi7skz1iB3wEJU8gKSontX4BujqxhYSBaGmnIFK6uHEOqjd+UHHuIGyMoIa2m4bdNdVdyjrGMQ==",
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.0.10.tgz",
"integrity": "sha512-YXIBJOT0G09YwVhRA2GJoHkwr8uEnk8kvviu5jUiq8XLFnAB2Ff+9rgVLoae+Zyi+bdTxTypYKUbpxUiF6ZkDA==",
"dev": true
},
"alphanum-sort": {
@@ -2976,9 +2976,9 @@
"dev": true
},
"rollup": {
"version": "2.32.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.32.0.tgz",
"integrity": "sha512-0FIG1jY88uhCP2yP4CfvtKEqPDRmsUwfY1kEOOM+DH/KOGATgaIFd/is1+fQOxsvh62ELzcFfKonwKWnHhrqmw==",
"version": "2.32.1",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.32.1.tgz",
"integrity": "sha512-Op2vWTpvK7t6/Qnm1TTh7VjEZZkN8RWgf0DHbkKzQBwNf748YhXbozHVefqpPp/Fuyk/PQPAnYsBxAEtlMvpUw==",
"dev": true,
"requires": {
"fsevents": "~2.1.2"
@@ -3413,9 +3413,9 @@
}
},
"svelte": {
"version": "3.29.0",
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.29.0.tgz",
"integrity": "sha512-f+A65eyOQ5ujETLy+igNXtlr6AEjAQLYd1yJE1VwNiXMQO5Z/Vmiy3rL+zblV/9jd7rtTTWqO1IcuXsP2Qv0OA==",
"version": "3.29.4",
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.29.4.tgz",
"integrity": "sha512-oW0fGHlyFFMvzRtIvOs84b0fOc0gmZNQcL5Is3hxuTpvaYX3pfd8oHy4KnOvbq4Ca6SG6AHdRMk7OhApTo0NqA==",
"dev": true
},
"svelte-highlight": {

View File

@@ -11,19 +11,19 @@
"@rollup/plugin-commonjs": "^11.0.0",
"@rollup/plugin-node-resolve": "^7.0.0",
"@rollup/plugin-url": "^5.0.1",
"@wails/runtime": "^1.0.9",
"@wails/runtime": "^1.0.10",
"focus-visible": "^5.2.0",
"halfmoon": "^1.1.1",
"postcss": "^8.1.2",
"postcss-import": "^12.0.1",
"rollup": "^2.32.0",
"rollup": "^2.32.1",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-postcss": "^3.1.8",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-terser": "^5.1.2",
"sirv-cli": "^0.4.4",
"svelte": "^3.0.0",
"svelte": "^3.29.4",
"svelte-highlight": "^0.6.2",
"svelte-preprocess": "^4.5.1"
},

View File

@@ -25,6 +25,7 @@
'Browser',
'File System',
'Window',
'System'
];
</script>

View File

@@ -2,11 +2,12 @@
import {selectedPage} from './Store';
import TitlePage from './pages/TitlePage.svelte';
import Logging from './pages/logging/Logging.svelte';
import Events from './pages/events/Events.svelte';
import Browser from './pages/browser/Browser.svelte';
import Logging from './pages/Logging/Logging.svelte';
import Events from './pages/Events/Events.svelte';
import Browser from './pages/Browser/Browser.svelte';
import Dialog from './pages/Dialog/Dialog.svelte';
import System from './pages/System/System.svelte';
</script>
<h4 class="title">{$selectedPage || "" }</h4>
@@ -15,6 +16,8 @@
{#if $selectedPage == "Logging"} <Logging></Logging> {/if}
{#if $selectedPage == "Events"} <Events></Events> {/if}
{#if $selectedPage == "Browser"} <Browser></Browser> {/if}
{#if $selectedPage == "Dialog"} <Dialog></Dialog> {/if}
{#if $selectedPage == "System"} <System></System> {/if}
</div>
<style>

View File

@@ -0,0 +1,50 @@
<script>
import CodeBlock from '../../../components/CodeBlock.svelte';
import CodeSnippet from '../../../components/CodeSnippet.svelte';
import FakeTerm from '../../../components/FakeTerm.svelte';
import jsCode from './code.jsx';
import goCode from './code.go';
import { writable } from 'svelte/store';
import { System } from '@wails/runtime';
import description from './description.txt';
var isJs = false;
$: lang = isJs ? 'Javascript' : 'Go';
var id = "Platform";
let output = writable("");
function log(message) {
output.update( (current) => {
current += message;
return current;
});
}
function getPlatform() {
if( isJs ) {
log("Platform from JS runtime: " + System.Platform() + "\n");
} else {
backend.main.System.Platform().then( (platformFromGo) => {
log("Platform from Go runtime: " + platformFromGo + "\n");
})
}
}
$: 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)';
</script>
<CodeBlock bind:isJs={isJs} {jsCode} {goCode} {description} title="Platform()" {id} showRun=true>
<div class="browser-form">
<form data-wails-no-drag class="mw-full">
<input class="btn btn-primary" type="button" on:click="{getPlatform}" value="Fetch platform using {lang} runtime">
<CodeSnippet bind:isJs={isJs} jsCode={testcodeJs} goCode={testcodeGo}></CodeSnippet>
<FakeTerm text={$output} style="height: 100px; overflow: scroll"></FakeTerm>
</form>
</div>
</CodeBlock>

View File

@@ -0,0 +1,14 @@
package main
import (
wails "github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/internal/runtime"
)
type MyStruct struct {
runtime *wails.Runtime
}
func (l *MyStruct) ShowPlatformHelp() {
l.runtime.Browser.Open("https://wails.app/gettingstarted/" + runtime.System.Platform())
}

View File

@@ -0,0 +1,6 @@
import { System, Browser } from '@wails/runtime';
function showPlatformHelp() {
// Do things
Browser.Open("https://wails.app/gettingstarted/" + System.Platform());
}

View File

@@ -0,0 +1 @@
System.Platform() returns the platform that the application in running on. It uses the same values as Go's <code>runtime.GOOS</code>

View File

@@ -0,0 +1,11 @@
<script>
import Platform from "./Platform/Platform.svelte";
</script>
<div>
The Wails runtime offers the ability to query system information through the <code>runtime.System</code> component.
<br/>
<Platform></Platform>
</div>

View File

@@ -27,6 +27,7 @@ func main() {
app.Bind(&Events{})
app.Bind(&Logger{})
app.Bind(&Browser{})
app.Bind(&System{})
app.Run()
}

View File

@@ -0,0 +1,23 @@
package main
import (
wails "github.com/wailsapp/wails/v2"
)
// System struct
type System struct {
runtime *wails.Runtime
}
// WailsInit is called at application startup
func (l *System) WailsInit(runtime *wails.Runtime) error {
// Perform your setup here
l.runtime = runtime
return nil
}
// Platform will return the runtime platform value
func (l *System) Platform() string {
// Perform your setup here
return l.runtime.System.Platform()
}