mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
Add System to kitchensink
This commit is contained in:
18
v2/test/kitchensink/frontend/package-lock.json
generated
18
v2/test/kitchensink/frontend/package-lock.json
generated
@@ -135,9 +135,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@wails/runtime": {
|
"@wails/runtime": {
|
||||||
"version": "1.0.9",
|
"version": "1.0.10",
|
||||||
"resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.0.9.tgz",
|
"resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.0.10.tgz",
|
||||||
"integrity": "sha512-BeApNQnMjwC/gi7skz1iB3wEJU8gKSontX4BujqxhYSBaGmnIFK6uHEOqjd+UHHuIGyMoIa2m4bdNdVdyjrGMQ==",
|
"integrity": "sha512-YXIBJOT0G09YwVhRA2GJoHkwr8uEnk8kvviu5jUiq8XLFnAB2Ff+9rgVLoae+Zyi+bdTxTypYKUbpxUiF6ZkDA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"alphanum-sort": {
|
"alphanum-sort": {
|
||||||
@@ -2976,9 +2976,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"rollup": {
|
"rollup": {
|
||||||
"version": "2.32.0",
|
"version": "2.32.1",
|
||||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.32.0.tgz",
|
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.32.1.tgz",
|
||||||
"integrity": "sha512-0FIG1jY88uhCP2yP4CfvtKEqPDRmsUwfY1kEOOM+DH/KOGATgaIFd/is1+fQOxsvh62ELzcFfKonwKWnHhrqmw==",
|
"integrity": "sha512-Op2vWTpvK7t6/Qnm1TTh7VjEZZkN8RWgf0DHbkKzQBwNf748YhXbozHVefqpPp/Fuyk/PQPAnYsBxAEtlMvpUw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"fsevents": "~2.1.2"
|
"fsevents": "~2.1.2"
|
||||||
@@ -3413,9 +3413,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"svelte": {
|
"svelte": {
|
||||||
"version": "3.29.0",
|
"version": "3.29.4",
|
||||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.29.0.tgz",
|
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.29.4.tgz",
|
||||||
"integrity": "sha512-f+A65eyOQ5ujETLy+igNXtlr6AEjAQLYd1yJE1VwNiXMQO5Z/Vmiy3rL+zblV/9jd7rtTTWqO1IcuXsP2Qv0OA==",
|
"integrity": "sha512-oW0fGHlyFFMvzRtIvOs84b0fOc0gmZNQcL5Is3hxuTpvaYX3pfd8oHy4KnOvbq4Ca6SG6AHdRMk7OhApTo0NqA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"svelte-highlight": {
|
"svelte-highlight": {
|
||||||
|
|||||||
@@ -11,19 +11,19 @@
|
|||||||
"@rollup/plugin-commonjs": "^11.0.0",
|
"@rollup/plugin-commonjs": "^11.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^7.0.0",
|
"@rollup/plugin-node-resolve": "^7.0.0",
|
||||||
"@rollup/plugin-url": "^5.0.1",
|
"@rollup/plugin-url": "^5.0.1",
|
||||||
"@wails/runtime": "^1.0.9",
|
"@wails/runtime": "^1.0.10",
|
||||||
"focus-visible": "^5.2.0",
|
"focus-visible": "^5.2.0",
|
||||||
"halfmoon": "^1.1.1",
|
"halfmoon": "^1.1.1",
|
||||||
"postcss": "^8.1.2",
|
"postcss": "^8.1.2",
|
||||||
"postcss-import": "^12.0.1",
|
"postcss-import": "^12.0.1",
|
||||||
"rollup": "^2.32.0",
|
"rollup": "^2.32.1",
|
||||||
"rollup-plugin-livereload": "^1.0.0",
|
"rollup-plugin-livereload": "^1.0.0",
|
||||||
"rollup-plugin-postcss": "^3.1.8",
|
"rollup-plugin-postcss": "^3.1.8",
|
||||||
"rollup-plugin-string": "^3.0.0",
|
"rollup-plugin-string": "^3.0.0",
|
||||||
"rollup-plugin-svelte": "^5.0.3",
|
"rollup-plugin-svelte": "^5.0.3",
|
||||||
"rollup-plugin-terser": "^5.1.2",
|
"rollup-plugin-terser": "^5.1.2",
|
||||||
"sirv-cli": "^0.4.4",
|
"sirv-cli": "^0.4.4",
|
||||||
"svelte": "^3.0.0",
|
"svelte": "^3.29.4",
|
||||||
"svelte-highlight": "^0.6.2",
|
"svelte-highlight": "^0.6.2",
|
||||||
"svelte-preprocess": "^4.5.1"
|
"svelte-preprocess": "^4.5.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
'Browser',
|
'Browser',
|
||||||
'File System',
|
'File System',
|
||||||
'Window',
|
'Window',
|
||||||
|
'System'
|
||||||
];
|
];
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
import {selectedPage} from './Store';
|
import {selectedPage} from './Store';
|
||||||
import TitlePage from './pages/TitlePage.svelte';
|
import TitlePage from './pages/TitlePage.svelte';
|
||||||
import Logging from './pages/logging/Logging.svelte';
|
import Logging from './pages/Logging/Logging.svelte';
|
||||||
import Events from './pages/events/Events.svelte';
|
import Events from './pages/Events/Events.svelte';
|
||||||
import Browser from './pages/browser/Browser.svelte';
|
import Browser from './pages/Browser/Browser.svelte';
|
||||||
|
import Dialog from './pages/Dialog/Dialog.svelte';
|
||||||
|
import System from './pages/System/System.svelte';
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h4 class="title">{$selectedPage || "" }</h4>
|
<h4 class="title">{$selectedPage || "" }</h4>
|
||||||
@@ -15,6 +16,8 @@
|
|||||||
{#if $selectedPage == "Logging"} <Logging></Logging> {/if}
|
{#if $selectedPage == "Logging"} <Logging></Logging> {/if}
|
||||||
{#if $selectedPage == "Events"} <Events></Events> {/if}
|
{#if $selectedPage == "Events"} <Events></Events> {/if}
|
||||||
{#if $selectedPage == "Browser"} <Browser></Browser> {/if}
|
{#if $selectedPage == "Browser"} <Browser></Browser> {/if}
|
||||||
|
{#if $selectedPage == "Dialog"} <Dialog></Dialog> {/if}
|
||||||
|
{#if $selectedPage == "System"} <System></System> {/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
@@ -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())
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { System, Browser } from '@wails/runtime';
|
||||||
|
|
||||||
|
function showPlatformHelp() {
|
||||||
|
// Do things
|
||||||
|
Browser.Open("https://wails.app/gettingstarted/" + System.Platform());
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
11
v2/test/kitchensink/frontend/src/pages/System/System.svelte
Normal file
11
v2/test/kitchensink/frontend/src/pages/System/System.svelte
Normal 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>
|
||||||
|
|
||||||
@@ -27,6 +27,7 @@ func main() {
|
|||||||
app.Bind(&Events{})
|
app.Bind(&Events{})
|
||||||
app.Bind(&Logger{})
|
app.Bind(&Logger{})
|
||||||
app.Bind(&Browser{})
|
app.Bind(&Browser{})
|
||||||
|
app.Bind(&System{})
|
||||||
|
|
||||||
app.Run()
|
app.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
23
v2/test/kitchensink/system.go
Normal file
23
v2/test/kitchensink/system.go
Normal 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()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user