mirror of
https://github.com/taigrr/wails.git
synced 2026-04-10 09:01:32 -07:00
Compare commits
33 Commits
bugfix/syn
...
feature/wi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fc572eea0 | ||
|
|
fe2c5e8611 | ||
|
|
422ee22d0c | ||
|
|
22f94cfdb6 | ||
|
|
5d754f40de | ||
|
|
c9b26c6352 | ||
|
|
6f0696631f | ||
|
|
fefb54de12 | ||
|
|
b4224066f7 | ||
|
|
3d9ef75488 | ||
|
|
79ecb0704e | ||
|
|
8154887824 | ||
|
|
39ae91a250 | ||
|
|
861f5f2a1c | ||
|
|
89ed00d6ed | ||
|
|
1e1834158b | ||
|
|
214fcf03b9 | ||
|
|
82ac4f1358 | ||
|
|
8b7cd03428 | ||
|
|
4d2b4fec45 | ||
|
|
bc0478b2b2 | ||
|
|
d59849b952 | ||
|
|
806821ad49 | ||
|
|
a4cc95351f | ||
|
|
f86996705b | ||
|
|
254aa664d7 | ||
|
|
c8371ee824 | ||
|
|
02e0250555 | ||
|
|
e1b025cab6 | ||
|
|
626854f1b7 | ||
|
|
98468d1c4d | ||
|
|
1062aeb136 | ||
|
|
aa93e5d8d2 |
@@ -33,3 +33,5 @@ Wails is what it is because of the time and effort given by these great people.
|
|||||||
* [artem](https://github.com/Unix4ever)
|
* [artem](https://github.com/Unix4ever)
|
||||||
* [Tim Kipp](https://github.com/timkippdev)
|
* [Tim Kipp](https://github.com/timkippdev)
|
||||||
* [Dmitry Gomzyakov](https://github.com/kyoto44)
|
* [Dmitry Gomzyakov](https://github.com/kyoto44)
|
||||||
|
* [Arthur Wiebe](https://github.com/artooro)
|
||||||
|
* [Ilgıt Yıldırım](https://github.com/ilgityildirim)
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
<a href="https://houndci.com"><img src="https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg"/></a>
|
<a href="https://houndci.com"><img src="https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg"/></a>
|
||||||
<a href="https://github.com/avelino/awesome-go" rel="nofollow"><img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" alt="Awesome"></a>
|
<a href="https://github.com/avelino/awesome-go" rel="nofollow"><img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" alt="Awesome"></a>
|
||||||
<a href="https://github.com/wailsapp/wails/workflows/release/badge.svg?branch=master" rel="nofollow"><img src="https://github.com/wailsapp/wails/workflows/release/badge.svg?branch=master" alt="Release Pipelines"></a>
|
<a href="https://github.com/wailsapp/wails/workflows/release/badge.svg?branch=master" rel="nofollow"><img src="https://github.com/wailsapp/wails/workflows/release/badge.svg?branch=master" alt="Release Pipelines"></a>
|
||||||
<a href="https://github.com/wailsapp/wails/workflows/latest-pre/badge.svg?branch=masterr" rel="nofollow"><img src="https://github.com/wailsapp/wails/workflows/latest-pre/badge.svg?branch=master" alt="Pre-Release Pipelines"></a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
The traditional method of providing web interfaces to Go programs is via a built-in web server. Wails offers a different approach: it provides the ability to wrap both Go code and a web frontend into a single binary. Tools are provided to make this easy for you by handling project creation, compilation and bundling. All you have to do is get creative!
|
The traditional method of providing web interfaces to Go programs is via a built-in web server. Wails offers a different approach: it provides the ability to wrap both Go code and a web frontend into a single binary. Tools are provided to make this easy for you by handling project creation, compilation and bundling. All you have to do is get creative!
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ func ldFlags(po *ProjectOptions, buildMode string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add windows flags
|
// Add windows flags
|
||||||
if po.Platform == "windows" && buildMode == BuildModeProd {
|
if po.Platform == "windows" {
|
||||||
ldflags += "-H windowsgui "
|
ldflags += "-H windowsgui "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const routes: Routes = [];
|
|||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
RouterModule.forRoot(routes)
|
RouterModule.forRoot(routes,{useHash:true})
|
||||||
],
|
],
|
||||||
exports: [RouterModule]
|
exports: [RouterModule]
|
||||||
})
|
})
|
||||||
|
|||||||
4
cmd/templates/svelte/frontend/.gitignore
vendored
Normal file
4
cmd/templates/svelte/frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/node_modules/
|
||||||
|
/public/build/
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
90
cmd/templates/svelte/frontend/README.md
Normal file
90
cmd/templates/svelte/frontend/README.md
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
*Looking for a shareable component template? Go here --> [sveltejs/component-template](https://github.com/sveltejs/component-template)*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# svelte app
|
||||||
|
|
||||||
|
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template.
|
||||||
|
|
||||||
|
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx degit sveltejs/template svelte-app
|
||||||
|
cd svelte-app
|
||||||
|
```
|
||||||
|
|
||||||
|
*Note that you will need to have [Node.js](https://nodejs.org) installed.*
|
||||||
|
|
||||||
|
|
||||||
|
## Get started
|
||||||
|
|
||||||
|
Install the dependencies...
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd svelte-app
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
...then start [Rollup](https://rollupjs.org):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes.
|
||||||
|
|
||||||
|
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`.
|
||||||
|
|
||||||
|
|
||||||
|
## Building and running in production mode
|
||||||
|
|
||||||
|
To create an optimised version of the app:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com).
|
||||||
|
|
||||||
|
|
||||||
|
## Single-page app mode
|
||||||
|
|
||||||
|
By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere.
|
||||||
|
|
||||||
|
If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json:
|
||||||
|
|
||||||
|
```js
|
||||||
|
"start": "sirv public --single"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deploying to the web
|
||||||
|
|
||||||
|
### With [Vercel](https://vercel.com)
|
||||||
|
|
||||||
|
Install `vercel` if you haven't already:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install -g vercel
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, from within your project folder:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd public
|
||||||
|
vercel deploy --name my-project
|
||||||
|
```
|
||||||
|
|
||||||
|
### With [surge](https://surge.sh/)
|
||||||
|
|
||||||
|
Install `surge` if you haven't already:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install -g surge
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, from within your project folder:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
surge public my-project.surge.sh
|
||||||
|
```
|
||||||
31
cmd/templates/svelte/frontend/package.json.template
Normal file
31
cmd/templates/svelte/frontend/package.json.template
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"name": "{{.NPMProjectName}}",
|
||||||
|
"author": "{{.Author.Name}}<{{.Author.Email}}>",
|
||||||
|
"scripts": {
|
||||||
|
"build": "rollup -c",
|
||||||
|
"dev": "rollup -c -w",
|
||||||
|
"start": "sirv public"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.11.6",
|
||||||
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
||||||
|
"@babel/plugin-transform-runtime": "^7.11.5",
|
||||||
|
"@babel/preset-env": "^7.11.5",
|
||||||
|
"@rollup/plugin-commonjs": "^14.0.0",
|
||||||
|
"@rollup/plugin-image": "^2.0.5",
|
||||||
|
"@rollup/plugin-node-resolve": "^8.0.0",
|
||||||
|
"core-js": "^3.6.5",
|
||||||
|
"rollup": "^2.3.4",
|
||||||
|
"rollup-plugin-babel": "^4.4.0",
|
||||||
|
"rollup-plugin-livereload": "^2.0.0",
|
||||||
|
"rollup-plugin-polyfill": "^3.0.0",
|
||||||
|
"rollup-plugin-svelte": "^6.0.0",
|
||||||
|
"rollup-plugin-terser": "^7.0.0",
|
||||||
|
"svelte": "^3.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"sirv-cli": "^1.0.0",
|
||||||
|
"@wailsapp/runtime": "^1.0.10",
|
||||||
|
"svelte-simple-modal": "^0.6.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
cmd/templates/svelte/frontend/public/favicon.png
Normal file
BIN
cmd/templates/svelte/frontend/public/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
17
cmd/templates/svelte/frontend/public/index.html
Normal file
17
cmd/templates/svelte/frontend/public/index.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8'>
|
||||||
|
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||||
|
|
||||||
|
<title>Svelte app</title>
|
||||||
|
|
||||||
|
<link rel='icon' type='image/png' href='/favicon.png'>
|
||||||
|
<link rel='stylesheet' href='/build/bundle.css'>
|
||||||
|
|
||||||
|
<script defer src='/build/bundle.js'></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
110
cmd/templates/svelte/frontend/rollup.config.js
Normal file
110
cmd/templates/svelte/frontend/rollup.config.js
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import svelte from 'rollup-plugin-svelte';
|
||||||
|
import resolve from '@rollup/plugin-node-resolve';
|
||||||
|
import commonjs from '@rollup/plugin-commonjs';
|
||||||
|
import livereload from 'rollup-plugin-livereload';
|
||||||
|
import { terser } from 'rollup-plugin-terser';
|
||||||
|
import image from '@rollup/plugin-image';
|
||||||
|
import babel from 'rollup-plugin-babel';
|
||||||
|
import polyfill from 'rollup-plugin-polyfill';
|
||||||
|
|
||||||
|
const production = !process.env.ROLLUP_WATCH;
|
||||||
|
|
||||||
|
function serve() {
|
||||||
|
let server;
|
||||||
|
|
||||||
|
function toExit() {
|
||||||
|
if (server) server.kill(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
writeBundle() {
|
||||||
|
if (server) return;
|
||||||
|
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
|
||||||
|
stdio: ['ignore', 'inherit', 'inherit'],
|
||||||
|
shell: true
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('SIGTERM', toExit);
|
||||||
|
process.on('exit', toExit);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
input: 'src/main.js',
|
||||||
|
output: {
|
||||||
|
sourcemap: true,
|
||||||
|
format: 'iife',
|
||||||
|
name: 'app',
|
||||||
|
file: 'public/build/bundle.js'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
image(),
|
||||||
|
svelte({
|
||||||
|
// enable run-time checks when not in production
|
||||||
|
dev: !production,
|
||||||
|
// we'll extract any component CSS out into
|
||||||
|
// a separate file - better for performance
|
||||||
|
css: css => {
|
||||||
|
css.write('bundle.css');
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
// If you have external dependencies installed from
|
||||||
|
// npm, you'll most likely need these plugins. In
|
||||||
|
// some cases you'll need additional configuration -
|
||||||
|
// consult the documentation for details:
|
||||||
|
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
||||||
|
resolve({
|
||||||
|
browser: true,
|
||||||
|
dedupe: ['svelte', 'svelte/transition', 'svelte/internal']
|
||||||
|
}),
|
||||||
|
commonjs(),
|
||||||
|
|
||||||
|
// In dev mode, call `npm run start` once
|
||||||
|
// the bundle has been generated
|
||||||
|
!production && serve(),
|
||||||
|
|
||||||
|
// Watch the `public` directory and refresh the
|
||||||
|
// browser on changes when not in production
|
||||||
|
!production && livereload('public'),
|
||||||
|
|
||||||
|
// Credit: https://blog.az.sg/posts/svelte-and-ie11/
|
||||||
|
babel({
|
||||||
|
extensions: [ '.js', '.jsx', '.es6', '.es', '.mjs', '.svelte', '.html' ],
|
||||||
|
runtimeHelpers: true,
|
||||||
|
exclude: [ 'node_modules/@babel/**', 'node_modules/core-js/**' ],
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
'@babel/preset-env',
|
||||||
|
{
|
||||||
|
targets: '> 0.25%, not dead, IE 11',
|
||||||
|
modules: false,
|
||||||
|
spec: true,
|
||||||
|
useBuiltIns: 'usage',
|
||||||
|
forceAllTransforms: true,
|
||||||
|
corejs: 3,
|
||||||
|
},
|
||||||
|
|
||||||
|
]
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
'@babel/plugin-syntax-dynamic-import',
|
||||||
|
[
|
||||||
|
'@babel/plugin-transform-runtime',
|
||||||
|
{
|
||||||
|
useESModules: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
polyfill(['@webcomponents/webcomponentsjs']),
|
||||||
|
|
||||||
|
// If we're building for production (npm run build
|
||||||
|
// instead of npm run dev), minify
|
||||||
|
production && terser()
|
||||||
|
],
|
||||||
|
watch: {
|
||||||
|
clearScreen: false
|
||||||
|
}
|
||||||
|
};
|
||||||
69
cmd/templates/svelte/frontend/src/App.svelte
Normal file
69
cmd/templates/svelte/frontend/src/App.svelte
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Modal from 'svelte-simple-modal';
|
||||||
|
import HelloWorld from './components/HelloWorld.svelte'
|
||||||
|
import logo from './logo.png';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<div class="App">
|
||||||
|
<header class="App-header">
|
||||||
|
<Modal>
|
||||||
|
<img src={logo} class="App-logo" alt="logo" />
|
||||||
|
<p>Welcome to your new <code>wails/svelte</code> project.</p>
|
||||||
|
<HelloWorld/>
|
||||||
|
</Modal>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:global(body) {
|
||||||
|
margin: 0;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
|
||||||
|
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
||||||
|
sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-logo {
|
||||||
|
height: 40vmin;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: no-preference) {
|
||||||
|
.App-logo {
|
||||||
|
animation: App-logo-spin infinite 20s linear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-header {
|
||||||
|
background-color: #282c34;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: calc(10px + 2vmin);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes App-logo-spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<script>
|
||||||
|
import { getContext } from 'svelte';
|
||||||
|
import ModalContent from './ModalContent.svelte'
|
||||||
|
|
||||||
|
const { open } = getContext('simple-modal');
|
||||||
|
|
||||||
|
const handleOpenModal = () => {
|
||||||
|
window.backend.basic().then((result) => {
|
||||||
|
open(ModalContent, { message: result });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<p><button on:click={handleOpenModal}>Hello</button></p>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<style></style>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
export let message;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{message}
|
||||||
|
</p>
|
||||||
BIN
cmd/templates/svelte/frontend/src/logo.png
Normal file
BIN
cmd/templates/svelte/frontend/src/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 301 KiB |
13
cmd/templates/svelte/frontend/src/main.js
Normal file
13
cmd/templates/svelte/frontend/src/main.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import App from './App.svelte';
|
||||||
|
|
||||||
|
import * as Wails from '@wailsapp/runtime';
|
||||||
|
|
||||||
|
let app;
|
||||||
|
|
||||||
|
Wails.Init(() => {
|
||||||
|
app = new App({
|
||||||
|
target: document.body,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default app;
|
||||||
5
cmd/templates/svelte/go.mod.template
Normal file
5
cmd/templates/svelte/go.mod.template
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module {{.BinaryName}}
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/wailsapp/wails {{.WailsVersion}}
|
||||||
|
)
|
||||||
27
cmd/templates/svelte/main.go.template
Normal file
27
cmd/templates/svelte/main.go.template
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/leaanthony/mewn"
|
||||||
|
"github.com/wailsapp/wails"
|
||||||
|
)
|
||||||
|
|
||||||
|
func basic() string {
|
||||||
|
return "World!"
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
js := mewn.String("./frontend/public/build/bundle.js")
|
||||||
|
css := mewn.String("./frontend/public/build/bundle.css")
|
||||||
|
|
||||||
|
app := wails.CreateApp(&wails.AppConfig{
|
||||||
|
Width: 1024,
|
||||||
|
Height: 768,
|
||||||
|
Title: "{{.Name}}",
|
||||||
|
JS: js,
|
||||||
|
CSS: css,
|
||||||
|
Colour: "#131313",
|
||||||
|
})
|
||||||
|
|
||||||
|
app.Bind(basic)
|
||||||
|
app.Run()
|
||||||
|
}
|
||||||
14
cmd/templates/svelte/template.json
Executable file
14
cmd/templates/svelte/template.json
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "Svelte",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"shortdescription": "A basic Svelte template",
|
||||||
|
"description": "A basic Svelte template",
|
||||||
|
"install": "npm install",
|
||||||
|
"build": "npm run build",
|
||||||
|
"author": "Tim Kipp <timkipp.22.developer@gmail.com>",
|
||||||
|
"created": "2020-09-06 13:06:10.469848 -0700 PDT m=+213.578828559",
|
||||||
|
"frontenddir": "frontend",
|
||||||
|
"serve": "npm run dev",
|
||||||
|
"bridge": "src",
|
||||||
|
"wailsdir": ""
|
||||||
|
}
|
||||||
@@ -2,29 +2,33 @@
|
|||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
|
color: black;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
background-color: rgb(254,254,254);
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
display: block;
|
display: block;
|
||||||
width:100%;
|
width:100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 3rem;
|
margin-top: 1rem;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
background-color: white;
|
||||||
|
color: black;
|
||||||
#newCounter {
|
|
||||||
color: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.result {
|
.result {
|
||||||
margin-top: 3rem;
|
margin-top: 1rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const runtime = require('@wailsapp/runtime');
|
|||||||
// Main entry point
|
// Main entry point
|
||||||
function start() {
|
function start() {
|
||||||
|
|
||||||
var mystore = wails.Store.New('Counter');
|
var mystore = runtime.Store.New('Counter');
|
||||||
|
|
||||||
// Ensure the default app div is 100% wide/high
|
// Ensure the default app div is 100% wide/high
|
||||||
var app = document.getElementById('app');
|
var app = document.getElementById('app');
|
||||||
@@ -36,12 +36,12 @@ function start() {
|
|||||||
mystore.set(newValue);
|
mystore.set(newValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
mystore.subscribe( (state) => {
|
mystore.subscribe( function(state) {
|
||||||
document.getElementById('counter').innerText = state;
|
document.getElementById('counter').innerText = state;
|
||||||
});
|
});
|
||||||
|
|
||||||
mystore.set(0);
|
mystore.set(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
// We provide our entrypoint as a callback for runtime.Init
|
// We provide our entrypoint as a callback for runtime.Init
|
||||||
runtime.Init(start);
|
runtime.Init(start);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
// Version - Wails version
|
// Version - Wails version
|
||||||
const Version = "v1.7.2-pre5"
|
const Version = "v1.8.0"
|
||||||
|
|||||||
@@ -1431,6 +1431,13 @@ struct webview_priv
|
|||||||
style = WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
|
style = WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scale
|
||||||
|
// Credit: https://github.com/webview/webview/issues/54#issuecomment-379528243
|
||||||
|
HDC hDC = GetDC(NULL);
|
||||||
|
w->width = GetDeviceCaps(hDC, 88)*w->width/96.0;
|
||||||
|
w->height = GetDeviceCaps(hDC, 90)*w->height/96.0;
|
||||||
|
ReleaseDC(NULL, hDC);
|
||||||
|
|
||||||
rect.left = 0;
|
rect.left = 0;
|
||||||
rect.top = 0;
|
rect.top = 0;
|
||||||
rect.right = w->width;
|
rect.right = w->width;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@wailsapp/runtime",
|
"name": "@wailsapp/runtime",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"description": "Wails Javascript runtime library",
|
"description": "Wails Javascript runtime library",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"types": "runtime.d.ts",
|
"types": "runtime.d.ts",
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type Store struct {
|
|||||||
data reflect.Value
|
data reflect.Value
|
||||||
dataType reflect.Type
|
dataType reflect.Type
|
||||||
eventPrefix string
|
eventPrefix string
|
||||||
callbacks []func(interface{})
|
callbacks []reflect.Value
|
||||||
runtime *Runtime
|
runtime *Runtime
|
||||||
notifySynchronously bool
|
notifySynchronously bool
|
||||||
|
|
||||||
@@ -143,10 +143,13 @@ func (s *Store) notify() {
|
|||||||
// Execute callbacks
|
// Execute callbacks
|
||||||
for _, callback := range s.callbacks {
|
for _, callback := range s.callbacks {
|
||||||
|
|
||||||
|
// Build args
|
||||||
|
args := []reflect.Value{s.data}
|
||||||
|
|
||||||
if s.notifySynchronously {
|
if s.notifySynchronously {
|
||||||
callback(s.data)
|
callback.Call(args)
|
||||||
} else {
|
} else {
|
||||||
go callback(s.data)
|
go callback.Call(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -184,11 +187,50 @@ func (s *Store) Set(data interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// callbackCheck ensures the given function to Subscribe() is
|
||||||
|
// of the correct signature. Absolutely cannot wait for
|
||||||
|
// generics to land rather than writing this nonsense.
|
||||||
|
func (s *Store) callbackCheck(callback interface{}) error {
|
||||||
|
|
||||||
|
// Get type
|
||||||
|
callbackType := reflect.TypeOf(callback)
|
||||||
|
|
||||||
|
// Check callback is a function
|
||||||
|
if callbackType.Kind() != reflect.Func {
|
||||||
|
return fmt.Errorf("invalid value given to store.Subscribe(). Expected 'func(%s)'", s.dataType.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check input param
|
||||||
|
if callbackType.NumIn() != 1 {
|
||||||
|
return fmt.Errorf("invalid number of parameters given in callback function. Expected 1")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check input data type
|
||||||
|
if callbackType.In(0) != s.dataType {
|
||||||
|
return fmt.Errorf("invalid type for input parameter given in callback function. Expected %s, got %s", s.dataType.String(), callbackType.In(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check output param
|
||||||
|
if callbackType.NumOut() != 0 {
|
||||||
|
return fmt.Errorf("invalid number of return parameters given in callback function. Expected 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Subscribe will subscribe to updates to the store by
|
// Subscribe will subscribe to updates to the store by
|
||||||
// providing a callback. Any updates to the store are sent
|
// providing a callback. Any updates to the store are sent
|
||||||
// to the callback
|
// to the callback
|
||||||
func (s *Store) Subscribe(callback func(interface{})) {
|
func (s *Store) Subscribe(callback interface{}) {
|
||||||
s.callbacks = append(s.callbacks, callback)
|
|
||||||
|
err := s.callbackCheck(callback)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
callbackFunc := reflect.ValueOf(callback)
|
||||||
|
|
||||||
|
s.callbacks = append(s.callbacks, callbackFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// updaterCheck ensures the given function to Update() is
|
// updaterCheck ensures the given function to Update() is
|
||||||
@@ -244,5 +286,8 @@ func (s *Store) Update(updater interface{}) {
|
|||||||
results := reflect.ValueOf(updater).Call(args)
|
results := reflect.ValueOf(updater).Call(args)
|
||||||
|
|
||||||
// We will only have 1 result. Set the store to it
|
// We will only have 1 result. Set the store to it
|
||||||
s.Set(results[0].Interface())
|
err = s.Set(results[0].Interface())
|
||||||
|
if err != nil && s.errorHandler != nil {
|
||||||
|
s.errorHandler(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user