-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v2/windows] implement full file path resolver #2774
[v2/windows] implement full file path resolver #2774
Conversation
Signed-off-by: Hidayatullah <[email protected]>
I think we need to think about the scenario where the webview runtime doesn't support this feature. Any thoughts on how the developer would manage that? |
return | ||
} | ||
|
||
file := *(**edge.ICoreWebView2File)(unsafe.Pointer(&_file)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to release this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no explanation about it in the docs. But I think it is better to release the resource to avoid memory leaks, or maybe it will be cleared by the garbage collector? honestly, I don't know much about Golang memory 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid a memory leak we need to call Release
here, because whenever COM returns a pointer to a COM Object the reference counter is increased. There's no special mentioning on the WebView2 docs, but it's a coding guideline when using COM
on which all the WebView2 APIs are based. Managing the Lifetime of an COM-Object
Garbage Collector of Go can't do anything here, because the memory has been allocated in native COM code of which Go isn't aware of.
Maybe we can make a function to check if this feature is available with Because another solution is using a different way to get the file path, for example when using overlay as a drop target, we cannot use the same Maybe it will be something like this:
As far as I know, right now only WebView2 provides an API to resolve the js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job @ayatkyo, thanks so much for all your time you have put into this 🙏
I've added some comments about COM memory management and pointer conversions.
return | ||
} | ||
|
||
file := *(**edge.ICoreWebView2File)(unsafe.Pointer(&_file)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid a memory leak we need to call Release
here, because whenever COM returns a pointer to a COM Object the reference counter is increased. There's no special mentioning on the WebView2 docs, but it's a coding guideline when using COM
on which all the WebView2 APIs are based. Managing the Lifetime of an COM-Object
Garbage Collector of Go can't do anything here, because the memory has been allocated in native COM code of which Go isn't aware of.
} | ||
|
||
files := []File{} | ||
count := *(*uint32)(unsafe.Pointer(&_count)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conversion seems somehow strange to me. According to the signature of GetCount() (*uint32, error) {
_count
is a *uint32
, so we convert **uint32
to a *uint32
and dereference that.
I would suggest changing the signature of GetCount
to return a uint32
instead of *uint32
. AFAIK we never return pointers to primitive types in go-webview2
Sorry for the late reply. Thanks for the comments, I learn a lot from that, especially the pointer, I will update the code 🙏 If I not mistaken, we will need to update // ...
func (i *ICoreWebView2File) Release() error {
return i.vtbl.CallRelease(unsafe.Pointer(i))
}
// ... Then call the file := (*edge.ICoreWebView2File)(unsafe.Pointer(_file))
defer file.Release() Also for // ...
func (i *ICoreWebView2ObjectCollectionView) Release() error {
return i.vtbl.CallRelease(unsafe.Pointer(i))
}
// ... objs, err := args.GetAdditionalObjects()
defer objs.Release()
if err != nil {
f.logger.Error(err.Error())
return
} |
Co-authored-by: stffabi <[email protected]>
Signed-off-by: Hidayatullah <[email protected]>
Signed-off-by: Hidayatullah <[email protected]>
Signed-off-by: Hidayatullah <[email protected]>
My suggestions for releasing would be:
I think that should work as it copies the reference. |
Signed-off-by: Hidayatullah <[email protected]>
I have updated the code, thanks a lot for guiding me on this PR @leaanthony @stffabi, I really appreciate that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for all your time you have put into this.
I suspect we also need to update go-webview2
with the changed method signature for GetCount
. But this part looks good to me.
Signed-off-by: Hidayatullah <[email protected]>
Thank you for your response. You are right. I have made some changes to the code and created a new PR for The previous code caused the application to crash when using WebView2 SDK versions < |
I've commented on the go-webview PR so I think we're pretty close to getting it in. One question: Am I right in thinking that if a webview runtime is installed which does not support |
Thanks for the reply, let's move the discussion to go-webview PR, sorry for the late reply.
Yes, to get full file path, frontend needs to send the File object using Unfortunately, we cannot simply just use |
@ayatkyo - Do you still want to proceed with this PR? I think |
Closing this due to no response from the Author. If anyone wants to pick it up, feel free 🙏 |
Description
This PR add a feature for resolving the full path of js File.
Currently only tested in Windows 11 with WebView2 114.0.1823.79.
Fixes #1090 but only for Windows with WebView2 version >= 1.0.1774.30.
Usage Demo
Source code of this demo is on https://github.com/ayatkyo/wails-2-file-drop-test
2023-07-14_04-19-27.mp4
Type of change
Another Solution
The previous solution that I tried before using this is using an overlay view in front of the webview, so it is something like this:
dragenter
event then get the target element size and position usingevent.target.getBoundingClientRect()
But this solution will trigger
dragleave
to target the element on the JS side as soon as we show the Overlay view, but we can triggerdragover
programmatically to webview with the mouse position (I have not tried this).Checklist:
website/src/pages/changelog.mdx
with details of this PR