Skip to content

Commit

Permalink
Merge pull request #1475 from hustshenl/master
Browse files Browse the repository at this point in the history
fixed some issues
  • Loading branch information
r0x0r authored Oct 2, 2024
2 parents a2b8d04 + 1839566 commit 5fab5b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 9 additions & 1 deletion webview/platforms/edgechromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,14 @@ def on_script_notify(self, _, args):
if return_value == '"FilesDropped"':
if _dnd_state['num_listeners'] == 0:
return
additionalObjects = args.get_AdditionalObjects()
if additionalObjects is None:
return

files = [
(os.path.basename(file.Path), file.Path)
for file
in list(args.get_AdditionalObjects())
in list(additionalObjects)
if 'CoreWebView2File' in str(type(file))
]
_dnd_state['paths'] += files
Expand All @@ -202,6 +205,10 @@ def on_new_window_request(self, sender, args):
else:
self.load_url(str(args.get_Uri()))

def on_source_changed(self, sender, args):
self.url = sender.Source
self.ishtml = False

def on_webview_ready(self, sender, args):
if not args.IsSuccess:
logger.error(
Expand All @@ -210,6 +217,7 @@ def on_webview_ready(self, sender, args):
)
return

self.web_view.CoreWebView2.SourceChanged += self.on_source_changed
sender.CoreWebView2.NewWindowRequested += self.on_new_window_request

if _settings['ssl']:
Expand Down
7 changes: 4 additions & 3 deletions webview/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from webview.js import api, dom_json, events, npo, polyfill
from webview.dom import _dnd_state
from webview.errors import WebViewException
import urllib.parse

if TYPE_CHECKING:
from webview.window import Window
Expand Down Expand Up @@ -246,11 +247,11 @@ def get_nested_attribute(obj: object, attr_str: str):
if event['type'] == 'drop':
files = event['dataTransfer'].get('files', [])
for file in files:
path = [item for item in _dnd_state['paths'] if item[0] == file['name']]
path = [item for item in _dnd_state['paths'] if urllib.parse.unquote(item[0]) == file['name']]
if len(path) == 0:
continue

file['pywebviewFullPath'] = path[0][1]
file['pywebviewFullPath'] = urllib.parse.unquote(path[0][1])
_dnd_state['paths'].remove(path[0])

for handler in element._event_handlers.get(event['type'], []):
Expand Down Expand Up @@ -389,4 +390,4 @@ def css_to_camel(css_case_string: str) -> str:


def android_jar_path() -> str:
return os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib', 'pywebview-android.jar')
return os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib', 'pywebview-android.jar')

0 comments on commit 5fab5b3

Please sign in to comment.