Compare commits

..

92 Commits

Author SHA1 Message Date
leaanthony 4c05c0bd30 chore: update contributors.svg 2023-04-02 22:55:17 +00:00
Lea Anthony b38ad7c7f1 Add initial svg 2023-04-03 08:54:45 +10:00
Lea Anthony acfca594f2 Debug contrib image 2023-04-03 08:53:11 +10:00
Lea Anthony 767b7d6026 Check out repo for contributors workflow 2023-04-03 08:43:57 +10:00
Lea Anthony 086953bbe9 Do not directly commit contributors sag 2023-04-03 08:39:42 +10:00
Lea Anthony c51df752a1 Create PR for contributors SVG 2023-04-03 08:37:46 +10:00
Lea Anthony ea3b7ed9dd Generate Contributors SVG 2023-04-03 08:33:55 +10:00
dependabot[bot] ef6366af61 Bump webpack from 5.75.0 to 5.76.2 in /website (#2503)
Bumps [webpack](https://github.com/webpack/webpack) from 5.75.0 to 5.76.2.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v5.75.0...v5.76.2)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 22:02:24 +11:00
dependabot[bot] 488666f407 Bump undici from 5.13.0 to 5.21.0 in /scripts/sponsors (#2502)
Bumps [undici](https://github.com/nodejs/undici) from 5.13.0 to 5.21.0.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v5.13.0...v5.21.0)

---
updated-dependencies:
- dependency-name: undici
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 22:00:55 +11:00
Simon Shutter 34fd76617e annotated menu example and updated runtime.Quit call (#2539) 2023-04-01 21:50:29 +11:00
憧憬Licoy 1e8b938d15 fix obfuscate build param name (#2542)
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
2023-04-01 21:48:03 +11:00
Lea Anthony 3404250ac8 [v3] Add single_instance plugin 2023-04-01 20:36:55 +11:00
Misite Bao eddc949295 fix: fix console printing (#2483) 2023-04-01 18:22:27 +11:00
Misite Bao 49bd33e642 docs: update routing.mdx (#2547) 2023-04-01 16:05:09 +11:00
github-actions[bot] 78f638a9bc docs: sync documents (#2514)
Co-authored-by: misitebao <misitebao@users.noreply.github.com>
2023-04-01 16:04:43 +11:00
github-actions[bot] fef6e2a616 chore: update sponsors.svg (#2535)
Co-authored-by: leaanthony <leaanthony@users.noreply.github.com>
2023-04-01 16:03:09 +11:00
Noah Gorstein 2a22933220 docs: fix broken link for react router HashRouter (#2544) 2023-04-01 08:43:15 +11:00
Lea Anthony eae4fe62cd Merge branch 'v3/api-package' 2023-03-31 20:39:41 +11:00
stffabi b3a9332a5b [assetserver] Add linux platform implementation (#2543) 2023-03-31 20:39:13 +11:00
Lea Anthony e91b7832ee Provide types to runtime api 2023-03-31 20:37:50 +11:00
stffabi db527c0fc2 [assetserver] Add linux platform implementation (#2543) 2023-03-31 10:08:31 +02:00
Lea Anthony 0d25edc0c4 Improved api package 2023-03-30 12:51:43 +11:00
Lea Anthony eb36258c73 Merge branch 'master' into v3/plugins 2023-03-27 20:58:00 +11:00
Misite Bao bdb138d42c chore: fix push.yml (#2530) 2023-03-27 07:37:38 +11:00
Arpit Jain abe6f520b4 Fix dates in changelog (#2527) 2023-03-26 16:19:12 +11:00
Adam Tenderholt 130fab6c01 Feature/v3 parser: expand TS model generation tests & some fixes (#2485)
* v3 parser: add tests for model generation

* v3 parser: use single quotes for got model.ts

* v3 parser: fixes for some failing tests

* v3 parser: misc simplification and cleanup

* v3 parser: fix model tests when no structs returned

* v3 parser: fix last failing test case

* Update contributors list

* v3 parser: update README

* Revert "Update contributors list"

This reverts commit f429d2ba890020d7ff0772e6207830508261b489.

* Changelog: add line about my contribution
2023-03-25 10:09:17 +11:00
Lea Anthony 365aaf6bb1 Add sqlite plugin 2023-03-25 09:39:59 +11:00
github-actions[bot] b5f1eab59b chore: update sponsors.svg (#2525)
Co-authored-by: leaanthony <leaanthony@users.noreply.github.com>
2023-03-24 23:20:18 +11:00
Lea Anthony 5949e305ea Reorder startup sequence
Add plugin scripts to asset server
Add InjectJS support in plugins
2023-03-24 08:43:00 +11:00
github-actions[bot] 5988cdca9a chore: update sponsors.svg (#2517)
Co-authored-by: leaanthony <leaanthony@users.noreply.github.com>
2023-03-23 19:33:04 +11:00
Lea Anthony bf86b0d9c1 Add Window creation hooks
Add InjectJS() to plugins interface
2023-03-23 06:51:24 +11:00
Misite Bao 93d7c6b5f3 docs: optimize code block display style (#2520) 2023-03-22 21:54:08 +11:00
Lea Anthony d5808fde59 Simple logging plugin 2023-03-22 20:56:45 +11:00
Lea Anthony 3ae604e474 Exported() -> CallableByJS() 2023-03-22 20:42:20 +11:00
Lea Anthony 42fb91bc73 Fix for variadic args in bound methods 2023-03-22 20:36:46 +11:00
github-actions[bot] 7d28ad1a3b docs: sync documents (#2510)
Co-authored-by: misitebao <misitebao@users.noreply.github.com>
2023-03-21 17:47:23 +11:00
Lea Anthony 4165caa02e Add Exported() []string to plugin API 2023-03-21 08:55:55 +11:00
Lea Anthony b656bd2194 Prevent beeps when pressing a key in Mac window 2023-03-20 20:48:22 +11:00
Lea Anthony a7278b4224 Update docs 2023-03-20 20:32:25 +11:00
Lea Anthony e2b7b68ec9 v2.4.1 2023-03-20 20:31:35 +11:00
Lea Anthony ba82f27534 Fix Bug with nil parameters.
Added browser and kvstore plugins.
2023-03-20 20:28:33 +11:00
stffabi 47af68a8cb [windows] Allow single-clicks on wails-draggable items (#2482)
* [runtime] Make it possible to restore old drag behaviour on windows with window.wails.flags.deferDragToMouseMove

* [runtime] Use deferDragToMouseMove as new default

This enhanced version should work well in all cases for Windows:
- No lag/delayed start of dragging
- Double-Clicks and Single-Click events still work in JavaScript on elements

* [docs] Add changelog
2023-03-20 08:45:21 +01:00
github-actions[bot] 77f053068c docs: sync documents (#2504)
Co-authored-by: misitebao <misitebao@users.noreply.github.com>
2023-03-19 20:37:06 +11:00
Lea Anthony 13f620ae54 Add plugin init. Update plugin signature. 2023-03-19 09:13:05 +11:00
github-actions[bot] e3edea1cb3 chore: update sponsors.svg (#2498)
Co-authored-by: leaanthony <leaanthony@users.noreply.github.com>
2023-03-18 11:48:23 +11:00
Lea Anthony c774af48b7 Extend call subsystem to support plugins 2023-03-18 09:12:44 +11:00
Lea Anthony 4300521064 Initial implementation 2023-03-18 08:11:36 +11:00
Filip Borkiewicz a0b7eb4ab6 Fix incorrect rendering of FAQ section header (#2497) 2023-03-18 07:37:21 +11:00
Lea Anthony 86aaa3a956 Merge branch 'v3/central-assetserver' into v3/plugins 2023-03-17 17:03:21 +11:00
stffabi 6ed0eb217d [webview2] Fix error handling in CreateWebResourceResponse (#2496)
The old error handling fails on WebView2Runtimes > 110.0.1587.69 and
will show a "connection refused" page and reloads after a short time.
After the reload everything worked as expected again.
2023-03-16 10:49:59 +01:00
github-actions[bot] a2c1c507e1 chore: update sponsors.svg (#2492)
Co-authored-by: leaanthony <leaanthony@users.noreply.github.com>
2023-03-16 19:27:23 +11:00
stffabi 74f349862e [v3] AssetServer options update comments 2023-03-16 06:49:46 +01:00
stffabi 0e614b0194 [v3] Centralize the AssetServer and move it to the application 2023-03-16 06:49:45 +01:00
github-actions[bot] 4bffc57cb5 chore: update sponsors.svg (#2488)
Co-authored-by: leaanthony <leaanthony@users.noreply.github.com>
2023-03-14 17:32:25 +11:00
stffabi 5dba18c853 [dev] Fix panic in devserver when using the logger (#2481) 2023-03-13 08:12:09 +01:00
github-actions[bot] 4cd873fecb docs: sync documents (#2443)
Co-authored-by: misitebao <misitebao@users.noreply.github.com>
2023-03-11 17:57:56 +11:00
Misite Bao e339c40e85 feat: update sync translated document script (#2479) 2023-03-11 14:09:48 +11:00
github-actions[bot] 050ac9e613 chore: update sponsors.svg (#2478)
Co-authored-by: leaanthony <leaanthony@users.noreply.github.com>
2023-03-11 12:54:20 +11:00
Lea Anthony 58986237b9 [v3] Minor fixes to templates + improved Taskfile 2023-03-11 12:48:10 +11:00
Lea Anthony 7cb4c7b505 [v3] Improve init command 2023-03-10 08:05:13 +11:00
dependabot[bot] e3816e714e Bump golang.org/x/net in /v3/examples/binding (#2472)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.0.0-20220722155237-a158d28d115b to 0.7.0.
- [Release notes](https://github.com/golang/net/releases)
- [Commits](https://github.com/golang/net/commits/v0.7.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-09 20:07:11 +11:00
github-actions[bot] 1684894b52 chore: update sponsors.svg (#2474)
Co-authored-by: leaanthony <leaanthony@users.noreply.github.com>
2023-03-09 20:06:35 +11:00
Lea Anthony e302d11f12 Update module deps 2023-03-09 08:23:20 +11:00
Lea Anthony eb670f4ba1 Merge branch 'master' into feature/v3-parser
# Conflicts:
#	v3/go.mod
#	v3/go.sum
2023-03-09 08:22:47 +11:00
Lea Anthony 5e0ce40b41 Update TODO 2023-03-09 08:21:37 +11:00
Lea Anthony 26530a0f5a Fix reserve word check.
Add model generation.
Warn if field is unexported in the Go struct
2023-03-07 19:48:30 +11:00
Lea Anthony 7340247e25 Create bindings file per package
Improved bindings tests
2023-03-07 18:22:33 +11:00
Lea Anthony f1a7f1b781 Improved bindings generation 2023-03-06 20:54:04 +11:00
Lea Anthony 71aa7c9731 Initial bindings.js generation 2023-03-03 19:54:12 +11:00
Lea Anthony 868b769e7f Initial bindings generation 2023-03-01 21:31:29 +11:00
Lea Anthony 8dc8c8e15e Merge remote-tracking branch 'origin/feature/v3-parser' into feature/v3-parser 2023-02-28 20:35:39 +11:00
Adam Tenderholt da90e74268 v3 parser: initial work on model generation w/ templates (#2428)
* v3 parser: initial work on model generation w/ templates

* v3 parser: expand models to namespaces
2023-02-28 20:35:18 +11:00
Lea Anthony 443ea46d1d Example bindings 2023-02-27 20:05:54 +11:00
Lea Anthony 00c458f948 Implement basic binding 2023-02-26 20:49:29 +11:00
Lea Anthony 33855ff01d Add tests for bound structs returned by function calls. 2023-02-26 19:18:47 +11:00
Lea Anthony f9ffe915f2 Add bindings hook 2023-02-26 15:06:05 +11:00
Lea Anthony 91676080eb Support binding variables that were assigned by functions 2023-02-26 13:12:30 +11:00
Lea Anthony 6afb5260a7 Refactor parsing functions 2023-02-26 08:56:27 +11:00
Adam Tenderholt 0f80f031fd v3 parser: add some more test cases (functions) (#2422)
* [v3] add test case for parser (create struct from func)

* [v3] add another test case for parser (func in other pkg) + misc
2023-02-26 07:46:26 +11:00
Lea Anthony ecc1791420 Support bound variables (struct literals)
Factor out unaryexpression parsing
Fix package bleed between tests
2023-02-25 09:47:50 +11:00
Lea Anthony 4a8917ecbc Add nested anonymous struct test 2023-02-25 08:27:36 +11:00
Lea Anthony cc1a6a3d50 Support anonymous struct fields 2023-02-25 08:24:58 +11:00
Lea Anthony cd11c0a83c Support references to structs in other packages 2023-02-24 21:15:39 +11:00
Lea Anthony 8fd0e06c24 Use package path instead of name 2023-02-23 20:26:15 +11:00
Lea Anthony 4e5be36459 Parse structs bound from other packages 2023-02-22 20:36:30 +11:00
Lea Anthony 6bfd654ec8 Tidy up. More tests. 2023-02-21 17:10:36 +11:00
Lea Anthony dc0d99a8e9 Cover all type combinations
Fix bug in pointer type resolution
2023-02-21 07:52:29 +11:00
Lea Anthony b606561f8d Move struct cache into parsed package
Fix bug in package path calculation
2023-02-21 07:18:08 +11:00
Lea Anthony d0769ecd1c Parse Models
Support recursive fields
Add loads of tests
2023-02-20 20:36:58 +11:00
Lea Anthony 95bb15eef4 [v3] MUCH Improved parser for bound structs 2023-02-19 20:59:03 +11:00
Lea Anthony 93aa8345dc [v3] Improved parser for bound structs 2023-02-17 21:01:16 +11:00
Lea Anthony e1279a054f [v3] Improved parser for bound structs 2023-02-17 20:57:31 +11:00
528 changed files with 17167 additions and 4912 deletions
+31
View File
@@ -0,0 +1,31 @@
name: Generate Contributors Image
on:
schedule:
- cron: '0 1 * * 0' # At 01:00 on Sunday.
push:
branches:
- 'v2/update-contrib-svg'
jobs:
contributors:
runs-on: ubuntu-latest
if: github.repository == 'wailsapp/wails'
steps:
- uses: actions/checkout@v3
- uses: wow-actions/contributors-list@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
svgPath: ./website/static/img/contributors.svg
noCommit: true
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: "chore: update contributors.svg"
add-paths: "website/static/img/contributors.svg"
title: Update Contributors Image
body: Generated new image
branch: update-contributors
delete-branch: true
+1 -1
View File
@@ -22,12 +22,12 @@ jobs:
website/**/*.json
- name: Set node
if: steps.verify-changed-files.outputs.files_changed != 'true'
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Push files
if: steps.verify-changed-files.outputs.files_changed == 'true'
env:
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
run: |
+1
View File
@@ -34,3 +34,4 @@ v2/cmd/wails/internal/commands/initialise/templates/testtemplates/
/v3/.task
/v3/examples/build/bin/testapp
/websitev3/site/
+1
View File
@@ -97,6 +97,7 @@ This project is supported by these kind people / companies:
<p align="center">
<img src="https://wails.io/img/sponsor/jetbrains-grayscale.webp" style="width: 100px"/>
</p>
## FAQ
- Is this an alternative to Electron?
+3 -3
View File
@@ -1775,9 +1775,9 @@
}
},
"node_modules/undici": {
"version": "5.13.0",
"resolved": "https://registry.npmmirror.com/undici/-/undici-5.13.0.tgz",
"integrity": "sha512-UDZKtwb2k7KRsK4SdXWG7ErXiL7yTGgLWvk2AXO1JMjgjh404nFo6tWSCM2xMpJwMPx3J8i/vfqEh1zOqvj82Q==",
"version": "5.21.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.21.0.tgz",
"integrity": "sha512-HOjK8l6a57b2ZGXOcUsI5NLfoTrfmbOl90ixJDl0AEFG4wgHNDQxtZy15/ZQp7HhjkpaGlp/eneMgtsu1dIlUA==",
"dependencies": {
"busboy": "^1.6.0"
},
+1 -1
View File
@@ -2,4 +2,4 @@
cd ../website
npx @crowdin/cli@latest pull -b master
npx @crowdin/cli@latest pull -b master --export-only-approved
+1 -1
View File
@@ -1 +1 @@
v2.4.0
v2.4.1
+1 -1
View File
@@ -41,7 +41,7 @@ func printBulletPoint(text string, args ...any) {
fatal(err.Error())
}
t = strings.Trim(t, "\n\r")
pterm.Printf(t, args...)
pterm.Printfln(t, args...)
}
func printFooter() {
+6 -43
View File
@@ -78,7 +78,6 @@ import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"os"
"runtime"
@@ -88,6 +87,7 @@ import (
"unsafe"
"github.com/wailsapp/wails/v2/pkg/assetserver"
"github.com/wailsapp/wails/v2/pkg/assetserver/webview"
"github.com/wailsapp/wails/v2/internal/binding"
"github.com/wailsapp/wails/v2/internal/frontend"
@@ -166,10 +166,7 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
}
result.assets = assets
// Start 10 processors to handle requests in parallel
for i := 0; i < 10; i++ {
go result.startRequestProcessor()
}
go result.startRequestProcessor()
}
go result.startMessageProcessor()
@@ -461,50 +458,16 @@ func processMessage(message *C.char) {
messageBuffer <- goMessage
}
var requestBuffer = make(chan unsafe.Pointer, 100)
var requestBuffer = make(chan webview.Request, 100)
func (f *Frontend) startRequestProcessor() {
for request := range requestBuffer {
f.processRequest(request)
C.g_object_unref(C.gpointer(request))
f.assets.ServeWebViewRequest(request)
request.Release()
}
}
//export processURLRequest
func processURLRequest(request unsafe.Pointer) {
// Increment reference counter to allow async processing, will be decremented after the processing
// has been finished by a worker.
C.g_object_ref(C.gpointer(request))
requestBuffer <- request
}
func (f *Frontend) processRequest(request unsafe.Pointer) {
req := (*C.WebKitURISchemeRequest)(request)
uri := C.webkit_uri_scheme_request_get_uri(req)
goURI := C.GoString(uri)
rw := &webKitResponseWriter{req: req}
defer rw.Close()
f.assets.ProcessHTTPRequestLegacy(
rw,
func() (*http.Request, error) {
method := webkit_uri_scheme_request_get_http_method(req)
r, err := http.NewRequest(method, goURI, nil)
if err != nil {
return nil, err
}
r.Header = webkit_uri_scheme_request_get_http_headers(req)
if r.URL.Host != f.startURL.Host {
if r.Body != nil {
r.Body.Close()
}
return nil, fmt.Errorf("Expected host '%s' in request, but was '%s'", f.startURL.Host, r.URL.Host)
}
return r, nil
})
requestBuffer <- webview.NewRequest(request)
}
@@ -12,10 +12,12 @@ import (
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/assetserver/webview"
)
func validateWebKit2Version(options *options.App) {
if C.webkit_get_major_version() == 2 && C.webkit_get_minor_version() >= webkit2MinMinorVersion {
if C.webkit_get_major_version() == 2 && C.webkit_get_minor_version() >= webview.Webkit2MinMinorVersion {
return
}
@@ -24,6 +26,6 @@ func validateWebKit2Version(options *options.App) {
msg = options.Linux.Messages
}
v := fmt.Sprintf("2.%d.0", webkit2MinMinorVersion)
v := fmt.Sprintf("2.%d.0", webview.Webkit2MinMinorVersion)
showModalDialogAndExit("WebKit2GTK", fmt.Sprintf(msg.WebKit2GTKMinRequired, v))
}
@@ -4,6 +4,7 @@
package edge
import (
"fmt"
"log"
"runtime"
"syscall"
@@ -249,7 +250,7 @@ func (e *ICoreWebView2Environment) CreateWebResourceResponse(content []byte, sta
return nil, err
}
var response *ICoreWebView2WebResourceResponse
_, _, err = e.vtbl.CreateWebResourceResponse.Call(
hr, _, err := e.vtbl.CreateWebResourceResponse.Call(
uintptr(unsafe.Pointer(e)),
stream,
uintptr(statusCode),
@@ -257,7 +258,14 @@ func (e *ICoreWebView2Environment) CreateWebResourceResponse(content []byte, sta
uintptr(unsafe.Pointer(_headers)),
uintptr(unsafe.Pointer(&response)),
)
if err != windows.ERROR_SUCCESS {
if windows.Handle(hr) != windows.S_OK {
return nil, syscall.Errno(hr)
}
if response == nil {
if err == nil {
err = fmt.Errorf("unknown error")
}
return nil, err
}
return response, nil
+5 -4
View File
@@ -62,9 +62,13 @@ func (d *DevWebServer) Run(ctx context.Context) error {
return err
}
var myLogger assetserver.Logger
if _logger := ctx.Value("logger"); _logger != nil {
myLogger = _logger.(*logger.Logger)
}
var assetHandler http.Handler
var wsHandler http.Handler
var myLogger *logger.Logger
_fronendDevServerURL, _ := ctx.Value("frontenddevserverurl").(string)
if _fronendDevServerURL == "" {
@@ -73,9 +77,6 @@ func (d *DevWebServer) Run(ctx context.Context) error {
return c.String(http.StatusOK, assetdir)
})
if _logger := ctx.Value("logger"); _logger != nil {
myLogger = _logger.(*logger.Logger)
}
var err error
assetHandler, err = assetserver.NewAssetHandler(assetServerConfig, myLogger)
if err != nil {
+4 -5
View File
@@ -66,7 +66,7 @@ window.wails = {
defaultCursor: null,
borderThickness: 6,
shouldDrag: false,
deferDragToMouseMove: false,
deferDragToMouseMove: true,
cssDragProperty: "--wails-draggable",
cssDragValue: "drag",
}
@@ -130,7 +130,7 @@ window.addEventListener('mousedown', (e) => {
}
}
if (window.wails.flags.deferDragToMouseMove) {
window.wails.flags.shouldDrag = true;
window.wails.flags.shouldDrag = true;
} else {
e.preventDefault()
window.WailsInvoke("drag");
@@ -152,10 +152,9 @@ function setResize(cursor) {
window.addEventListener('mousemove', function (e) {
if (window.wails.flags.shouldDrag) {
window.wails.flags.shouldDrag = false;
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
if(mousePressed <= 0) {
window.wails.flags.shouldDrag = false;
} else {
if (mousePressed > 0) {
window.WailsInvoke("drag");
return;
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -61,7 +61,7 @@ var jsReservedKeywords []string = []string{
"typeof",
"var",
"void",
"volotile",
"volatile",
"while",
"with",
"yield",
+28
View File
@@ -2,8 +2,11 @@ package assetserver
import (
"bytes"
"fmt"
"math/rand"
"net/http"
"net/http/httptest"
"strings"
"golang.org/x/net/html"
@@ -42,6 +45,9 @@ type AssetServer struct {
// Use http based runtime
runtimeHandler RuntimeHandler
// plugin scripts
pluginScripts map[string]string
assetServerWebView
}
@@ -89,6 +95,16 @@ func (d *AssetServer) UseRuntimeHandler(handler RuntimeHandler) {
d.runtimeHandler = handler
}
func (d *AssetServer) AddPluginScript(pluginName string, script string) {
if d.pluginScripts == nil {
d.pluginScripts = make(map[string]string)
}
pluginName = strings.ReplaceAll(pluginName, "/", "_")
pluginName = html.EscapeString(pluginName)
pluginScriptName := fmt.Sprintf("/plugin_%s_%d.js", pluginName, rand.Intn(100000))
d.pluginScripts[pluginScriptName] = script
}
func (d *AssetServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if isWebSocket(req) {
// Forward WebSockets to the distinct websocket handler if it exists
@@ -149,6 +165,11 @@ func (d *AssetServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
d.writeBlob(rw, path, content)
default:
// Check if this is a plugin script
if script, ok := d.pluginScripts[path]; ok {
d.writeBlob(rw, path, []byte(script))
return
}
d.handler.ServeHTTP(rw, req)
}
}
@@ -174,6 +195,13 @@ func (d *AssetServer) processIndexHTML(indexHTML []byte) ([]byte, error) {
return nil, err
}
// Inject plugins
for scriptName := range d.pluginScripts {
if err := insertScriptInHead(htmlNode, scriptName); err != nil {
return nil, err
}
}
var buffer bytes.Buffer
err = html.Render(&buffer, htmlNode)
if err != nil {
@@ -0,0 +1,85 @@
//go:build linux
// +build linux
package webview
/*
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0 gio-unix-2.0
#include "gtk/gtk.h"
#include "webkit2/webkit2.h"
*/
import "C"
import (
"io"
"net/http"
"unsafe"
)
// NewRequest creates as new WebViewRequest based on a pointer to an `WebKitURISchemeRequest`
//
// Please make sure to call Release() when finished using the request.
func NewRequest(webKitURISchemeRequest unsafe.Pointer) Request {
webkitReq := (*C.WebKitURISchemeRequest)(webKitURISchemeRequest)
req := &request{req: webkitReq}
req.AddRef()
return req
}
var _ Request = &request{}
type request struct {
req *C.WebKitURISchemeRequest
header http.Header
body io.ReadCloser
rw *responseWriter
}
func (r *request) AddRef() error {
C.g_object_ref(C.gpointer(r.req))
return nil
}
func (r *request) Release() error {
C.g_object_unref(C.gpointer(r.req))
return nil
}
func (r *request) URL() (string, error) {
return C.GoString(C.webkit_uri_scheme_request_get_uri(r.req)), nil
}
func (r *request) Method() (string, error) {
return webkit_uri_scheme_request_get_http_method(r.req), nil
}
func (r *request) Header() (http.Header, error) {
if r.header != nil {
return r.header, nil
}
r.header = webkit_uri_scheme_request_get_http_headers(r.req)
return r.header, nil
}
func (r *request) Body() (io.ReadCloser, error) {
if r.body != nil {
return r.body, nil
}
// WebKit2GTK has currently no support for request bodies.
r.body = http.NoBody
return r.body, nil
}
func (r *request) Response() ResponseWriter {
if r.rw != nil {
return r.rw
}
r.rw = &responseWriter{req: r.req}
return r.rw
}
@@ -1,9 +1,20 @@
package webview
import (
"errors"
"net/http"
)
const (
HeaderContentLength = "Content-Length"
HeaderContentType = "Content-Type"
)
var (
errRequestStopped = errors.New("request has been stopped")
errResponseFinished = errors.New("response has been finished")
)
// A ResponseWriter interface is used by an HTTP handler to
// construct an HTTP response for the WebView.
type ResponseWriter interface {
@@ -69,16 +69,10 @@ import "C"
import (
"encoding/json"
"errors"
"net/http"
"unsafe"
)
var (
errRequestStopped = errors.New("request has been stopped")
errResponseFinished = errors.New("response has been finished")
)
var _ ResponseWriter = &responseWriter{}
type responseWriter struct {

Some files were not shown because too many files have changed in this diff Show More