Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony authored Aug 25, 2024
2 parents 2eb93ce + 1a23102 commit 3818477
Show file tree
Hide file tree
Showing 37 changed files with 440 additions and 259 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate-sponsor-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
SPONSORKIT_GITHUB_LOGIN: wailsapp

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
uses: peter-evans/create-pull-request@v6
with:
commit-message: "chore: update sponsors.svg"
add-paths: "website/static/img/sponsors.svg"
Expand Down
5 changes: 4 additions & 1 deletion v2/internal/binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ func (b *Bindings) hasExportedJSONFields(typeOf reflect.Type) bool {
for i := 0; i < typeOf.NumField(); i++ {
jsonFieldName := ""
f := typeOf.Field(i)
jsonTag := f.Tag.Get("json")
jsonTag, hasTag := f.Tag.Lookup("json")
if !hasTag && f.IsExported() {
return true
}
if len(jsonTag) == 0 {
continue
}
Expand Down
59 changes: 59 additions & 0 deletions v2/internal/binding/binding_test/binding_notags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package binding_test

type NoFieldTags struct {
Name string
Address string
Zip *string
Spouse *NoFieldTags
}

func (n NoFieldTags) Get() NoFieldTags {
return n
}

var NoFieldTagsTest = BindingTest{
name: "NoFieldTags",
structs: []interface{}{
&NoFieldTags{},
},
exemptions: nil,
shouldError: false,
want: `
export namespace binding_test {
export class NoFieldTags {
Name: string;
Address: string;
Zip?: string;
Spouse?: NoFieldTags;
static createFrom(source: any = {}) {
return new NoFieldTags(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.Name = source["Name"];
this.Address = source["Address"];
this.Zip = source["Zip"];
this.Spouse = this.convertValues(source["Spouse"], NoFieldTags);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
}
`,
}
1 change: 1 addition & 0 deletions v2/internal/binding/binding_test/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestBindings_GenerateModels(t *testing.T) {
EntityWithDiffNamespacesTest,
SpecialCharacterFieldTest,
WithoutFieldsTest,
NoFieldTagsTest,
}

testLogger := &logger.Logger{}
Expand Down
5 changes: 5 additions & 0 deletions v2/internal/frontend/desktop/windows/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,11 @@ func (f *Frontend) processMessageWithAdditionalObjects(message string, sender *e
return
}

if _file == nil {
f.logger.Warning("object at %d is not a file", i)
continue
}

file := (*edge.ICoreWebView2File)(unsafe.Pointer(_file))
defer file.Release()

Expand Down
21 changes: 11 additions & 10 deletions v2/internal/frontend/runtime/desktop/draganddrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function onDragOver(e) {
if (!window.wails.flags.enableWailsDragAndDrop) {
return;
}
e.dataTransfer.dropEffect = 'copy';
e.preventDefault();

if (!flags.useDropTarget) {
Expand Down Expand Up @@ -130,16 +131,6 @@ function onDrop(e) {
}
e.preventDefault();

if (!flags.useDropTarget) {
return;
}

// Trigger debounce function to deactivate drop targets
if(flags.nextDeactivate) flags.nextDeactivate();

// Deactivate all drop targets
Array.from(document.getElementsByClassName(DROP_TARGET_ACTIVE)).forEach(el => el.classList.remove(DROP_TARGET_ACTIVE));

if (CanResolveFilePaths()) {
// process files
let files = [];
Expand All @@ -154,6 +145,16 @@ function onDrop(e) {
}
window.runtime.ResolveFilePaths(e.x, e.y, files);
}

if (!flags.useDropTarget) {
return;
}

// Trigger debounce function to deactivate drop targets
if(flags.nextDeactivate) flags.nextDeactivate();

// Deactivate all drop targets
Array.from(document.getElementsByClassName(DROP_TARGET_ACTIVE)).forEach(el => el.classList.remove(DROP_TARGET_ACTIVE));
}

/**
Expand Down
12 changes: 6 additions & 6 deletions v2/internal/frontend/runtime/desktop/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ function notifyListeners(eventData) {
// Get the event name
let eventName = eventData.name;

// Check if we have any listeners for this event
if (eventListeners[eventName]) {
// Keep a list of listener indexes to destroy
const newEventListenerList = eventListeners[eventName]?.slice() || [];

// Keep a list of listener indexes to destroy
const newEventListenerList = eventListeners[eventName].slice();
// Check if we have any listeners for this event
if (newEventListenerList.length) {

// Iterate listeners
for (let count = eventListeners[eventName].length - 1; count >= 0; count -= 1) {
for (let count = newEventListenerList.length - 1; count >= 0; count -= 1) {

// Get next listener
const listener = eventListeners[eventName][count];
const listener = newEventListenerList[count];

let data = eventData.data;

Expand Down
23 changes: 12 additions & 11 deletions v2/internal/frontend/runtime/runtime_debug_desktop.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/internal/frontend/runtime/runtime_prod_desktop.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v2/internal/system/packagemanager/eopkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (e *Eopkg) Packages() packagemap {
{Name: "gcc", SystemPackage: true},
},
"pkg-config": []*Package{
{Name: "pkg-config", SystemPackage: true},
{Name: "pkgconf", SystemPackage: true},
},
"npm": []*Package{
{Name: "nodejs", SystemPackage: true},
Expand Down
8 changes: 7 additions & 1 deletion v2/internal/typescriptify/typescriptify.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,13 @@ func (t *TypeScriptify) getFieldOptions(structType reflect.Type, field reflect.S

func (t *TypeScriptify) getJSONFieldName(field reflect.StructField, isPtr bool) string {
jsonFieldName := ""
jsonTag := field.Tag.Get("json")
jsonTag, hasTag := field.Tag.Lookup("json")
if !hasTag && field.IsExported() {
jsonFieldName = field.Name
if isPtr {
jsonFieldName += "?"
}
}
if len(jsonTag) > 0 {
jsonTagParts := strings.Split(jsonTag, ",")
if len(jsonTagParts) > 0 {
Expand Down
24 changes: 20 additions & 4 deletions v2/pkg/assetserver/webview/responsewriter_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import "C"

import (
"encoding/json"
"fmt"
"net/http"
"unsafe"
)
Expand Down Expand Up @@ -98,16 +99,31 @@ func (rw *responseWriter) Write(buf []byte) (int, error) {

rw.WriteHeader(http.StatusOK)

var content unsafe.Pointer
var contentLen int
if buf != nil {
content = unsafe.Pointer(&buf[0])
contentLen = len(buf)
}

if !C.URLSchemeTaskDidReceiveData(rw.r.task, content, C.int(contentLen)) {
return 0, errRequestStopped
if contentLen > 0 {
// Create a C array to hold the data
cBuf := C.malloc(C.size_t(contentLen))
if cBuf == nil {
return 0, fmt.Errorf("memory allocation failed for %d bytes", contentLen)
}
defer C.free(cBuf)

// Copy the Go slice to the C array
C.memcpy(cBuf, unsafe.Pointer(&buf[0]), C.size_t(contentLen))

if !C.URLSchemeTaskDidReceiveData(rw.r.task, cBuf, C.int(contentLen)) {
return 0, errRequestStopped
}
} else {
if !C.URLSchemeTaskDidReceiveData(rw.r.task, nil, 0) {
return 0, errRequestStopped
}
}

return contentLen, nil
}

Expand Down
4 changes: 2 additions & 2 deletions v2/pkg/commands/build/packager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ func packageApplicationForDarwin(options *Options) error {
return err
}
// Copy binary
packedBinaryPath := filepath.Join(exeDir, options.ProjectData.Name)
packedBinaryPath := filepath.Join(exeDir, options.ProjectData.OutputFilename)
err = fs.MoveFile(options.CompiledBinary, packedBinaryPath)
if err != nil {
return errors.Wrap(err, "Cannot move file: "+options.ProjectData.OutputFilename)
return errors.Wrap(err, "Cannot move file: "+options.CompiledBinary)
}

// Generate Info.plist
Expand Down
29 changes: 26 additions & 3 deletions v2/pkg/git/git.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package git

import (
"html/template"
"encoding/json"
"fmt"
"runtime"
"strings"

Expand Down Expand Up @@ -30,9 +31,31 @@ func Email() (string, error) {

// Name tries to retrieve the
func Name() (string, error) {
errMsg := "failed to retrieve git user name: %w"
stdout, _, err := shell.RunCommand(".", gitcommand(), "config", "user.name")
name := template.JSEscapeString(strings.TrimSpace(stdout))
return name, err
if err != nil {
return "", fmt.Errorf(errMsg, err)
}
name := strings.TrimSpace(stdout)
return EscapeName(name)
}

func EscapeName(str string) (string, error) {
b, err := json.Marshal(str)
if err != nil {
return "", err
}
// Remove the surrounding quotes
escaped := string(b[1 : len(b)-1])

// Check if username is JSON compliant
var js json.RawMessage
jsonVal := fmt.Sprintf(`{"name": "%s"}`, escaped)
err = json.Unmarshal([]byte(jsonVal), &js)
if err != nil {
return "", fmt.Errorf("failed to retrieve git user name: %w", err)
}
return escaped, nil
}

func InitRepo(projectDir string) error {
Expand Down
44 changes: 44 additions & 0 deletions v2/pkg/git/git_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package git

import (
"testing"
)

func TestEscapeName1(t *testing.T) {
type args struct {
str string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "Escape Apostrophe",
args: args{
str: `John O'Keefe`,
},
want: `John O'Keefe`,
},
{
name: "Escape backslash",
args: args{
str: `MYDOMAIN\USER`,
},
want: `MYDOMAIN\\USER`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := EscapeName(tt.args.str)
if (err != nil) != tt.wantErr {
t.Errorf("EscapeName() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("EscapeName() got = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion website/docs/guides/application-development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ create files on the fly or process POST/PUT requests.
GET requests are always first handled by the `assets` FS. If the FS doesn't find the requested file the request will be
forwarded to the `http.Handler` for serving. Any requests other than GET will be directly processed by the `AssetsHandler`
if specified.
It's also possible to only use the `AssetsHandler` by specifiy `nil` as the `Assets` option.
It's also possible to only use the `AssetsHandler` by specifying `nil` as the `Assets` option.

## Built in Dev Server

Expand Down
2 changes: 1 addition & 1 deletion website/docs/guides/frontend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The options are as follows:
| noautoinjectipc | Disable the autoinjection of `/wails/ipc.js` |
| noautoinject | Disable all autoinjection of scripts |

Multiple options may be used provided they are comma seperated.
Multiple options may be used provided they are comma separated.

This code is perfectly valid and operates the same as the autoinjection version:

Expand Down
2 changes: 1 addition & 1 deletion website/docs/guides/mac-appstore.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ This is an example entitlements file from the [RiftShare](https://github.com/ach
```

**Add the Embedded Provisioning Profile**
The Provisioning Profile created above needs to be added to the root of the applicaton. It needs to be named embedded.provisionprofile.
The Provisioning Profile created above needs to be added to the root of the application. It needs to be named embedded.provisionprofile.

#### Build and Sign the App Package

Expand Down
2 changes: 1 addition & 1 deletion website/docs/guides/nixos-font.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NixOS FontSize Bug

NixOS/Wayland can cause a bug where the `font-size` css property doesnt affect the rendered page. To fix this add the following to your devShell.
NixOS/Wayland can cause a bug where the `font-size` css property doesn't affect the rendered page. To fix this add the following to your devShell.

```shell
shellHook = with pkgs; ''
Expand Down
6 changes: 4 additions & 2 deletions website/docs/guides/signing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ Now we need to configure some gon config files in our `build/darwin` directory:
"bundle_id": "app.myapp",
"apple_id": {
"username": "[email protected]",
"password": "@env:APPLE_PASSWORD",
"password": "your-app-specific-password",
"provider": "ABCDE12345"
},
"sign": {
Expand All @@ -268,11 +268,13 @@ Here is a brief break down of the above fields:
- `source`: The location of your wails binary to be signed
- `apple_id`:
- `username`: Your Apple ID email address
- `password`: Your app-specific password, referenced using Gon's environment variable syntax
- `password`: Your app-specific password
- `provider`: Your team ID for your App Store Connect account
- `sign`:
- `application_identity`: Your Apple developer identity

The (https://developer.apple.com/documentation/technotes/tn3147-migrating-to-the-latest-notarization-tool)[deprecated Apple's altool]'s syntax supporting `@env:` is no longer available since Apple has migrated to the new notarytool.

Your developer identity and team ID can both by found on macOS by running the following command:

```bash
Expand Down
Loading

0 comments on commit 3818477

Please sign in to comment.