diff --git a/build.sh b/build.sh index efe3129..ef08f3f 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ if [ -d unpack ]; then sudo rm -rf unpack fi -version="0.1.0" +version="0.2.0" mkdir -p unpack/DEBIAN diff --git a/debian/control b/debian/control index 2bbbeb3..70ca588 100644 --- a/debian/control +++ b/debian/control @@ -1,5 +1,5 @@ Package: python3-webengine-gtk3 -Version: 0.1.0 +Version: 0.2.0 Section: develop Priority: optional Maintainer: Yutent diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py b/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py index 3df6f4f..76b2c1b 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py @@ -4,7 +4,8 @@ from webengine.gtk3._webengine import WebEngine from webengine.gtk3._settings import create_setting +from webengine.gtk3._hotreload import create_hmr_server -build = (0, 1, 0) +build = (0, 2, 0) version = '.'.join(map(str, build)) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_hotreload.py b/usr/lib/python3/dist-packages/webengine/gtk3/_hotreload.py new file mode 100644 index 0000000..a6a3213 --- /dev/null +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_hotreload.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + + +import time, os + +try: + from watchdog.observers import Observer + from watchdog.events import FileSystemEventHandler +except: + Observer = None + FileSystemEventHandler = object + + +class DogHandler(FileSystemEventHandler): + + last_reload = 0 + + def __init__(self, webview): + super().__init__() + self.webview = webview + + + def on_modified(self, event): + if os.path.isfile(event.src_path): + stamp = int(time.time()) + # 1秒内有多个修改, 不重复reload + if stamp == self.last_reload: + return + + self.last_reload = stamp + self.webview.reload() + + + + +def create_hmr_server(options = None): + if Observer is None: + print('Warning: HMR server depends on "python-watchdog". Please install it before using it') + dog = None + else: + dog = Observer() + + + def wrapper(app, extra = None): + if dog is None: + return + + if app.root: + dog.schedule(DogHandler(app), app.root, recursive=True) + dog.start() + else: + raise SyntaxError('Web root must be set before HMR server starts.') + + return wrapper \ No newline at end of file diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_settings.py b/usr/lib/python3/dist-packages/webengine/gtk3/_settings.py index d668c50..af3fbcf 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_settings.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_settings.py @@ -22,7 +22,7 @@ class Settings(WebKit2.Settings): self.set_javascript_can_open_windows_automatically(True) - self.set_user_agent_with_application_details('WebEngine', '0.1.0') + self.set_user_agent_with_application_details('WebEngine', '0.2.0') # indexedDB 和 localStorage 和 离线缓存