mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 13:19:00 -07:00
Compare commits
1 Commits
feature/go
...
bugfix/syn
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddcaf58a90 |
@@ -33,5 +33,3 @@ Wails is what it is because of the time and effort given by these great people.
|
||||
* [artem](https://github.com/Unix4ever)
|
||||
* [Tim Kipp](https://github.com/timkippdev)
|
||||
* [Dmitry Gomzyakov](https://github.com/kyoto44)
|
||||
* [Arthur Wiebe](https://github.com/artooro)
|
||||
* [Ilgıt Yıldırım](https://github.com/ilgityildirim)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<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/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>
|
||||
|
||||
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!
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"github.com/leaanthony/spinner"
|
||||
)
|
||||
|
||||
const xgoVersion = "1.0.1"
|
||||
|
||||
var fs = NewFSHelper()
|
||||
|
||||
// ValidateFrontendConfig checks if the frontend config is valid
|
||||
@@ -92,17 +90,16 @@ func InitializeCrossCompilation(verbose bool) error {
|
||||
}
|
||||
|
||||
var packSpinner *spinner.Spinner
|
||||
msg := fmt.Sprintf("Pulling wailsapp/xgo:%s docker image... (may take a while)", xgoVersion)
|
||||
if !verbose {
|
||||
packSpinner = spinner.New(msg)
|
||||
packSpinner = spinner.New("Pulling wailsapp/xgo:latest docker image... (may take a while)")
|
||||
packSpinner.SetSpinSpeed(50)
|
||||
packSpinner.Start()
|
||||
} else {
|
||||
println(msg)
|
||||
println("Pulling wailsapp/xgo:latest docker image... (may take a while)")
|
||||
}
|
||||
|
||||
err := NewProgramHelper(verbose).RunCommandArray([]string{"docker",
|
||||
"pull", fmt.Sprintf("wailsapp/xgo:%s", xgoVersion)})
|
||||
"pull", "wailsapp/xgo:latest"})
|
||||
|
||||
if err != nil {
|
||||
if packSpinner != nil {
|
||||
@@ -117,7 +114,7 @@ func InitializeCrossCompilation(verbose bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuildDocker builds the project using the cross compiling wailsapp/xgo:<xgoVersion> container
|
||||
// BuildDocker builds the project using the cross compiling wailsapp/xgo:latest container
|
||||
func BuildDocker(binaryName string, buildMode string, projectOptions *ProjectOptions) error {
|
||||
var packSpinner *spinner.Spinner
|
||||
if buildMode == BuildModeBridge {
|
||||
@@ -149,24 +146,18 @@ func BuildDocker(binaryName string, buildMode string, projectOptions *ProjectOpt
|
||||
"-e", "FLAG_RACE=false",
|
||||
"-e", "FLAG_BUILDMODE=default",
|
||||
"-e", "FLAG_TRIMPATH=false",
|
||||
"-e", fmt.Sprintf("TARGETS=%s/%s", projectOptions.Platform, projectOptions.Architecture),
|
||||
"-e", fmt.Sprintf("TARGETS=%s", projectOptions.Platform+"/"+projectOptions.Architecture),
|
||||
"-e", "GOPROXY=",
|
||||
"-e", "GO111MODULE=on",
|
||||
"wailsapp/xgo:latest",
|
||||
".",
|
||||
} {
|
||||
buildCommand.Add(arg)
|
||||
}
|
||||
|
||||
if projectOptions.GoPath != "" {
|
||||
buildCommand.Add("-v")
|
||||
buildCommand.Add(fmt.Sprintf("%s:/go", projectOptions.GoPath))
|
||||
}
|
||||
|
||||
buildCommand.Add(fmt.Sprintf("wailsapp/xgo:%s", xgoVersion))
|
||||
buildCommand.Add(".")
|
||||
|
||||
compileMessage := fmt.Sprintf(
|
||||
"Packing + Compiling project for %s/%s using docker image wailsapp/xgo:%s",
|
||||
projectOptions.Platform, projectOptions.Architecture, xgoVersion)
|
||||
"Packing + Compiling project for %s/%s using docker image wailsapp/xgo:latest",
|
||||
projectOptions.Platform, projectOptions.Architecture)
|
||||
|
||||
if buildMode == BuildModeDebug {
|
||||
compileMessage += " (Debug Mode)"
|
||||
@@ -225,6 +216,10 @@ func BuildNative(binaryName string, forceRebuild bool, buildMode string, project
|
||||
buildCommand.Add("go")
|
||||
|
||||
buildCommand.Add("build")
|
||||
if buildMode == BuildModeBridge {
|
||||
// Ignore errors
|
||||
buildCommand.Add("-i")
|
||||
}
|
||||
|
||||
if binaryName != "" {
|
||||
// Alter binary name based on OS
|
||||
|
||||
@@ -162,7 +162,6 @@ type ProjectOptions struct {
|
||||
Platform string
|
||||
Architecture string
|
||||
LdFlags string
|
||||
GoPath string
|
||||
}
|
||||
|
||||
// Defaults sets the default project template
|
||||
|
||||
@@ -5,7 +5,7 @@ const routes: Routes = [];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forRoot(routes,{useHash:true})
|
||||
RouterModule.forRoot(routes)
|
||||
],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
|
||||
4
cmd/templates/svelte/frontend/.gitignore
vendored
4
cmd/templates/svelte/frontend/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/node_modules/
|
||||
/public/build/
|
||||
|
||||
.DS_Store
|
||||
@@ -1,90 +0,0 @@
|
||||
*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
|
||||
```
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB |
@@ -1,17 +0,0 @@
|
||||
<!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>
|
||||
@@ -1,110 +0,0 @@
|
||||
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
|
||||
}
|
||||
};
|
||||
@@ -1,69 +0,0 @@
|
||||
|
||||
|
||||
<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>
|
||||
@@ -1,18 +0,0 @@
|
||||
<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>
|
||||
@@ -1,7 +0,0 @@
|
||||
<script>
|
||||
export let message;
|
||||
</script>
|
||||
|
||||
<p>
|
||||
{message}
|
||||
</p>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 301 KiB |
@@ -1,13 +0,0 @@
|
||||
import App from './App.svelte';
|
||||
|
||||
import * as Wails from '@wailsapp/runtime';
|
||||
|
||||
let app;
|
||||
|
||||
Wails.Init(() => {
|
||||
app = new App({
|
||||
target: document.body,
|
||||
});
|
||||
});
|
||||
|
||||
export default app;
|
||||
@@ -1,5 +0,0 @@
|
||||
module {{.BinaryName}}
|
||||
|
||||
require (
|
||||
github.com/wailsapp/wails {{.WailsVersion}}
|
||||
)
|
||||
@@ -1,27 +0,0 @@
|
||||
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()
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"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,33 +2,29 @@
|
||||
html,
|
||||
body {
|
||||
background-color: white;
|
||||
color: black;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
input {
|
||||
background-color: rgb(254,254,254);
|
||||
color: black;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: block;
|
||||
width:100%;
|
||||
text-align: center;
|
||||
margin-top: 1rem;
|
||||
margin-top: 3rem;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
button {
|
||||
font-size: 1rem;
|
||||
background-color: white;
|
||||
color: black;
|
||||
}
|
||||
|
||||
#newCounter {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.result {
|
||||
margin-top: 1rem;
|
||||
margin-top: 3rem;
|
||||
text-align: center;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ const runtime = require('@wailsapp/runtime');
|
||||
// Main entry point
|
||||
function start() {
|
||||
|
||||
var mystore = runtime.Store.New('Counter');
|
||||
var mystore = wails.Store.New('Counter');
|
||||
|
||||
// Ensure the default app div is 100% wide/high
|
||||
var app = document.getElementById('app');
|
||||
@@ -36,12 +36,12 @@ function start() {
|
||||
mystore.set(newValue);
|
||||
};
|
||||
|
||||
mystore.subscribe( function(state) {
|
||||
mystore.subscribe( (state) => {
|
||||
document.getElementById('counter').innerText = state;
|
||||
});
|
||||
|
||||
|
||||
mystore.set(0);
|
||||
};
|
||||
|
||||
// We provide our entrypoint as a callback for runtime.Init
|
||||
runtime.Init(start);
|
||||
runtime.Init(start);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
|
||||
// Version - Wails version
|
||||
const Version = "v1.8.1-pre1"
|
||||
const Version = "v1.7.2-pre5"
|
||||
|
||||
@@ -26,7 +26,6 @@ func init() {
|
||||
var packageApp = false
|
||||
var forceRebuild = false
|
||||
var debugMode = false
|
||||
var gopath = ""
|
||||
var typescriptFilename = ""
|
||||
var verbose = false
|
||||
var platform = ""
|
||||
@@ -43,8 +42,7 @@ func init() {
|
||||
BoolFlag("d", "Build in Debug mode", &debugMode).
|
||||
BoolFlag("verbose", "Verbose output", &verbose).
|
||||
StringFlag("t", "Generate Typescript definitions to given file (at runtime)", &typescriptFilename).
|
||||
StringFlag("ldflags", "Extra options for -ldflags", &ldflags).
|
||||
StringFlag("gopath", "Specify your GOPATH location. Mounted to /go during cross-compilation.", &gopath)
|
||||
StringFlag("ldflags", "Extra options for -ldflags", &ldflags)
|
||||
|
||||
var b strings.Builder
|
||||
for _, plat := range getSupportedPlatforms() {
|
||||
@@ -99,7 +97,6 @@ func init() {
|
||||
|
||||
// Add ldflags
|
||||
projectOptions.LdFlags = ldflags
|
||||
projectOptions.GoPath = gopath
|
||||
|
||||
// Validate config
|
||||
// Check if we have a frontend
|
||||
|
||||
@@ -1431,13 +1431,6 @@ struct webview_priv
|
||||
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.top = 0;
|
||||
rect.right = w->width;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wailsapp/runtime",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.0",
|
||||
"description": "Wails Javascript runtime library",
|
||||
"main": "main.js",
|
||||
"types": "runtime.d.ts",
|
||||
|
||||
@@ -45,7 +45,7 @@ type Store struct {
|
||||
data reflect.Value
|
||||
dataType reflect.Type
|
||||
eventPrefix string
|
||||
callbacks []reflect.Value
|
||||
callbacks []func(interface{})
|
||||
runtime *Runtime
|
||||
notifySynchronously bool
|
||||
|
||||
@@ -143,13 +143,10 @@ func (s *Store) notify() {
|
||||
// Execute callbacks
|
||||
for _, callback := range s.callbacks {
|
||||
|
||||
// Build args
|
||||
args := []reflect.Value{s.data}
|
||||
|
||||
if s.notifySynchronously {
|
||||
callback.Call(args)
|
||||
callback(s.data)
|
||||
} else {
|
||||
go callback.Call(args)
|
||||
go callback(s.data)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -187,50 +184,11 @@ func (s *Store) Set(data interface{}) error {
|
||||
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
|
||||
// providing a callback. Any updates to the store are sent
|
||||
// to the callback
|
||||
func (s *Store) Subscribe(callback interface{}) {
|
||||
|
||||
err := s.callbackCheck(callback)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
callbackFunc := reflect.ValueOf(callback)
|
||||
|
||||
s.callbacks = append(s.callbacks, callbackFunc)
|
||||
func (s *Store) Subscribe(callback func(interface{})) {
|
||||
s.callbacks = append(s.callbacks, callback)
|
||||
}
|
||||
|
||||
// updaterCheck ensures the given function to Update() is
|
||||
@@ -286,13 +244,5 @@ func (s *Store) Update(updater interface{}) {
|
||||
results := reflect.ValueOf(updater).Call(args)
|
||||
|
||||
// We will only have 1 result. Set the store to it
|
||||
err = s.Set(results[0].Interface())
|
||||
if err != nil && s.errorHandler != nil {
|
||||
s.errorHandler(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the value of the data that's kept in the current state / Store
|
||||
func (s *Store) Get() interface{} {
|
||||
return s.data.Interface()
|
||||
s.Set(results[0].Interface())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user