mirror of
https://github.com/wavetermdev/wails.git
synced 2026-04-22 15:26:15 -07:00
Compare commits
151 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8553f43080 | |||
| 587681bb8d | |||
| afbf80ea4a | |||
| c180d7dccb | |||
| c20aabc8f8 | |||
| 4cccb628c9 | |||
| 5d487347d4 | |||
| fe8b7ac5c9 | |||
| 732c70777b | |||
| 753c5fd337 | |||
| 2dad29673d | |||
| 5e466893cf | |||
| c15fd822c1 | |||
| 42b1c0befa | |||
| 6ef8744e02 | |||
| cf916c8e8b | |||
| cdc1d4be3e | |||
| 1c5284db3e | |||
| 073cdc3a55 | |||
| fd9363e842 | |||
| 3051628fa2 | |||
| cac97e8652 | |||
| 2ccabc772b | |||
| ff91241592 | |||
| 2257b1cab1 | |||
| bdcf98fc15 | |||
| 3025a94a77 | |||
| d971495ad3 | |||
| a4b1f469e9 | |||
| b18f04b30d | |||
| 94e9447e1c | |||
| 03c479c890 | |||
| c95a3a795e | |||
| 1d8e99d846 | |||
| 8e909fc9f4 | |||
| 3bc86a4f50 | |||
| 2c7913c202 | |||
| d1c57ddb5f | |||
| 9ffb517183 | |||
| 27f852ac6a | |||
| 20c0b48634 | |||
| 6cf01b4239 | |||
| 3ae88f8822 | |||
| 5994eb605f | |||
| 9694dc57aa | |||
| b5b78fddee | |||
| c905185467 | |||
| 47ca7879cd | |||
| 6202b3bf3e | |||
| ea94c2de1f | |||
| eb0d4bc42f | |||
| b323c3db20 | |||
| 1670ac6567 | |||
| c941176018 | |||
| a060d9dcc0 | |||
| ba208dce44 | |||
| 9bbac46b3f | |||
| d8c591e64c | |||
| 2c28a8f550 | |||
| d6c5586159 | |||
| 08a7893b1d | |||
| fa6cf17079 | |||
| fe2a20f92a | |||
| b713d57168 | |||
| 17ca06693e | |||
| 243d738d64 | |||
| 3f50b95f26 | |||
| f0d8ce99a1 | |||
| 259eec97d6 | |||
| 8b2168abe7 | |||
| a51e127309 | |||
| c5cee79ff7 | |||
| 9393b08c3f | |||
| 0ca039e914 | |||
| cd8b4f088f | |||
| 847842504b | |||
| 8ab91d31fe | |||
| bb4d891549 | |||
| 4a316a76fa | |||
| 529e4cc07e | |||
| 579747d0f7 | |||
| 6880c53082 | |||
| 6e011e75c3 | |||
| 683ba7dc59 | |||
| 717e598330 | |||
| a6489a1044 | |||
| df911adcae | |||
| d7c0b1ec58 | |||
| 7135d4fa27 | |||
| 83e063bf2b | |||
| 6e0773b355 | |||
| 60f34223b0 | |||
| 539be2ce84 | |||
| 561198b81b | |||
| c823215eb6 | |||
| 93f890f6d9 | |||
| 8a3aec6866 | |||
| 1ef8ed73ab | |||
| 9004c3955e | |||
| 4c98ce7da1 | |||
| 0ae5381203 | |||
| 3f2f1b45f6 | |||
| e6bec8f7cc | |||
| f1f15fc1c5 | |||
| bcca09563c | |||
| ee355659ce | |||
| a660e4a9da | |||
| a44fd57e98 | |||
| 85de0bbf8a | |||
| 7274b6d19c | |||
| c0371f141a | |||
| 5c96264234 | |||
| a3c41d1740 | |||
| 7c15b780e2 | |||
| fb081b4876 | |||
| a28315f38b | |||
| 49e4f00b62 | |||
| 9167063976 | |||
| aaa425724c | |||
| ffdbb0af64 | |||
| 12dec650de | |||
| d4b2563e9b | |||
| 55817b65b5 | |||
| ab6e7531b4 | |||
| 1e4cf9b0ad | |||
| 13efa58c9a | |||
| 88b9b40bfe | |||
| 0011e39c55 | |||
| aa6b67734b | |||
| 733258cc83 | |||
| 4742fd7ed2 | |||
| 96996431b4 | |||
| f06ce760ba | |||
| 53cf2bb953 | |||
| 859b2dd638 | |||
| 0225b8588c | |||
| 0bb11079af | |||
| 35d4c4b99c | |||
| 76a4c3c171 | |||
| 5493e1d4ac | |||
| 807f772055 | |||
| 3e97a4cc4d | |||
| 5e42d67570 | |||
| 6ecdb43148 | |||
| ea5e06aabd | |||
| 54a88ae3d9 | |||
| 6edd941c1a | |||
| 04c64c1bea | |||
| db550f81cd | |||
| 5de8efff32 | |||
| a591bcc59c |
+18
@@ -0,0 +1,18 @@
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
examples/**/example*
|
||||
!examples/**/*.*
|
||||
cmd/wails/wails
|
||||
.DS_Store
|
||||
tmp
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/cmd/wails/main.go",
|
||||
"env": {},
|
||||
"args": [
|
||||
"setup"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
-1300
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 wailsapp
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,138 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
// -------------------------------- Compile time Flags ------------------------------
|
||||
|
||||
// BuildMode indicates what mode we are in
|
||||
var BuildMode = cmd.BuildModeProd
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// App defines the main application struct
|
||||
type App struct {
|
||||
config *AppConfig // The Application configuration object
|
||||
cli *cmd.Cli // In debug mode, we have a cli
|
||||
renderer Renderer // The renderer is what we will render the app to
|
||||
logLevel string // The log level of the app
|
||||
ipc *ipcManager // Handles the IPC calls
|
||||
log *CustomLogger // Logger
|
||||
bindingManager *bindingManager // Handles binding of Go code to renderer
|
||||
eventManager *eventManager // Handles all the events
|
||||
runtime *Runtime // The runtime object for registered structs
|
||||
|
||||
// This is a list of all the JS/CSS that needs injecting
|
||||
// It will get injected in order
|
||||
jsCache []string
|
||||
cssCache []string
|
||||
}
|
||||
|
||||
// CreateApp creates the application window with the given configuration
|
||||
// If none given, the defaults are used
|
||||
func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||
var userConfig *AppConfig
|
||||
if len(optionalConfig) > 0 {
|
||||
userConfig = optionalConfig[0]
|
||||
}
|
||||
|
||||
result := &App{
|
||||
logLevel: "info",
|
||||
renderer: &webViewRenderer{},
|
||||
ipc: newIPCManager(),
|
||||
bindingManager: newBindingManager(),
|
||||
eventManager: newEventManager(),
|
||||
log: newCustomLogger("App"),
|
||||
}
|
||||
|
||||
appconfig, err := newAppConfig(userConfig)
|
||||
if err != nil {
|
||||
result.log.Fatalf("Cannot use custom HTML: %s", err.Error())
|
||||
}
|
||||
result.config = appconfig
|
||||
|
||||
// Set up the CLI if not in release mode
|
||||
if BuildMode != cmd.BuildModeProd {
|
||||
result.cli = result.setupCli()
|
||||
} else {
|
||||
// Disable Inspector in release mode
|
||||
result.config.DisableInspector = true
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Run the app
|
||||
func (a *App) Run() error {
|
||||
if BuildMode != cmd.BuildModeProd {
|
||||
return a.cli.Run()
|
||||
}
|
||||
|
||||
a.logLevel = "error"
|
||||
return a.start()
|
||||
}
|
||||
|
||||
func (a *App) start() error {
|
||||
|
||||
// Set the log level
|
||||
setLogLevel(a.logLevel)
|
||||
|
||||
// Log starup
|
||||
a.log.Info("Starting")
|
||||
|
||||
// Check if we are to run in headless mode
|
||||
if BuildMode == cmd.BuildModeBridge {
|
||||
a.renderer = &Headless{}
|
||||
}
|
||||
|
||||
// Initialise the renderer
|
||||
err := a.renderer.Initialise(a.config, a.ipc, a.eventManager)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Start event manager and give it our renderer
|
||||
a.eventManager.start(a.renderer)
|
||||
|
||||
// Start the IPC Manager and give it the event manager and binding manager
|
||||
a.ipc.start(a.eventManager, a.bindingManager)
|
||||
|
||||
// Create the runtime
|
||||
a.runtime = newRuntime(a.eventManager, a.renderer)
|
||||
|
||||
// Start binding manager and give it our renderer
|
||||
err = a.bindingManager.start(a.renderer, a.runtime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Inject CSS
|
||||
a.renderer.AddCSSList(a.cssCache)
|
||||
|
||||
// Inject JS
|
||||
a.renderer.AddJSList(a.jsCache)
|
||||
|
||||
// Run the renderer
|
||||
a.renderer.Run()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Bind allows the user to bind the given object
|
||||
// with the application
|
||||
func (a *App) Bind(object interface{}) {
|
||||
a.bindingManager.bind(object)
|
||||
}
|
||||
|
||||
// AddJS adds a piece of Javascript to a cache that
|
||||
// gets injected at runtime
|
||||
func (a *App) AddJS(js string) {
|
||||
a.jsCache = append(a.jsCache, js)
|
||||
}
|
||||
|
||||
// AddCSS adds a CSS string to a cache that
|
||||
// gets injected at runtime
|
||||
func (a *App) AddCSS(js string) {
|
||||
a.cssCache = append(a.cssCache, js)
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
// setupCli creates a new cli handler for the application
|
||||
func (app *App) setupCli() *cmd.Cli {
|
||||
|
||||
// Create a new cli
|
||||
result := cmd.NewCli(app.config.Title, "Debug build")
|
||||
|
||||
// Setup cli to handle loglevel and headless flags
|
||||
result.
|
||||
StringFlag("loglevel", "Sets the log level [debug|info|error|panic|fatal]. Default debug", &app.logLevel).
|
||||
// BoolFlag("headless", "Runs the app in headless mode", &app.headless).
|
||||
Action(app.start)
|
||||
|
||||
// Banner
|
||||
result.PreRun(func(cli *cmd.Cli) error {
|
||||
log := cmd.NewLogger()
|
||||
log.PrintSmallBanner()
|
||||
fmt.Println()
|
||||
log.YellowUnderline(app.config.Title + " - Debug Build")
|
||||
return nil
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/dchest/htmlmin"
|
||||
"github.com/leaanthony/mewn"
|
||||
)
|
||||
|
||||
// AppConfig is the configuration structure used when creating a Wails App object
|
||||
type AppConfig struct {
|
||||
Width, Height int
|
||||
Title string
|
||||
defaultHTML string
|
||||
HTML string
|
||||
JS string
|
||||
CSS string
|
||||
Colour string
|
||||
Resizable bool
|
||||
DisableInspector bool
|
||||
isHTMLFragment bool
|
||||
}
|
||||
|
||||
func (a *AppConfig) merge(in *AppConfig) error {
|
||||
if in.CSS != "" {
|
||||
a.CSS = in.CSS
|
||||
}
|
||||
if in.Title != "" {
|
||||
a.Title = in.Title
|
||||
}
|
||||
if in.HTML != "" {
|
||||
minified, err := htmlmin.Minify([]byte(in.HTML), &htmlmin.Options{
|
||||
MinifyScripts: true,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
inlineHTML := string(minified)
|
||||
inlineHTML = strings.Replace(inlineHTML, "'", "\\'", -1)
|
||||
inlineHTML = strings.Replace(inlineHTML, "\n", " ", -1)
|
||||
a.HTML = strings.TrimSpace(inlineHTML)
|
||||
|
||||
// Deduce whether this is a full html page or a fragment
|
||||
// The document is determined to be a fragment if an HMTL
|
||||
// tag exists and is located before the first div tag
|
||||
HTMLTagIndex := strings.Index(a.HTML, "<html")
|
||||
DivTagIndex := strings.Index(a.HTML, "<div")
|
||||
|
||||
if HTMLTagIndex == -1 {
|
||||
a.isHTMLFragment = true
|
||||
} else {
|
||||
if DivTagIndex < HTMLTagIndex {
|
||||
a.isHTMLFragment = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if in.Colour != "" {
|
||||
a.Colour = in.Colour
|
||||
}
|
||||
|
||||
if in.JS != "" {
|
||||
a.JS = in.JS
|
||||
}
|
||||
|
||||
if in.Width != 0 {
|
||||
a.Width = in.Width
|
||||
}
|
||||
if in.Height != 0 {
|
||||
a.Height = in.Height
|
||||
}
|
||||
a.Resizable = in.Resizable
|
||||
a.DisableInspector = in.DisableInspector
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Creates the default configuration
|
||||
func newAppConfig(userConfig *AppConfig) (*AppConfig, error) {
|
||||
result := &AppConfig{
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
Resizable: true,
|
||||
Title: "My Wails App",
|
||||
Colour: "#FFF", // White by default
|
||||
HTML: mewn.String("./wailsruntimeassets/default/default.html"),
|
||||
}
|
||||
|
||||
if userConfig != nil {
|
||||
err := result.merge(userConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user