diff --git a/inject.js b/inject.js
index e09156e..1173a4b 100644
--- a/inject.js
+++ b/inject.js
@@ -356,5 +356,8 @@ Object.assign(native, {
handler('window', { action: 'set_keep_below', value: setting }, null)
}
},
+ notify({ title, summary, icon, progress = 0, urgency = 0 }) {
+ handler('notify', { title, summary, icon, progress, urgency })
+ },
handler
})
diff --git a/main.py b/main.py
index 35920e5..3497282 100755
--- a/main.py
+++ b/main.py
@@ -6,8 +6,9 @@ import gi, json, os, shutil
gi.require_version("Gtk", "3.0")
gi.require_version("WebKit2", "4.1")
gi.require_version("Keybinder", "3.0")
+gi.require_version('Notify', '0.7') # gir1.2-notify-0.7
-from gi.repository import Gtk, Gdk, WebKit2, GLib, Gio, Keybinder
+from gi.repository import Gtk, Gdk, WebKit2, GLib, Gio, Keybinder, Notify
from gi.repository.GdkPixbuf import Pixbuf
from notes.utils import *
@@ -23,7 +24,9 @@ except (ValueError, ImportError):
# 初始化 Keybinder
Keybinder.init()
+Notify.init(Notify.get_app_name() or 'webapp')
+# im_context = Gtk.IMContext()
class WebKitWindow(Gtk.Window):
@@ -51,6 +54,7 @@ class WebKitWindow(Gtk.Window):
settings.set_user_agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) weapp/1.0.0 Version/16.4 Safari/605.1.15")
+
manager = WebKit2.UserContentManager()
script = open(self.file_path('./inject.js'), 'r').read()
@@ -69,24 +73,26 @@ class WebKitWindow(Gtk.Window):
context = self.webview.get_context()
context.register_uri_scheme('app', self.resource_request_callback)
- # self.webview.connect("resource-load-started", self.resource_request_callback)
+
+
+ im = self.webview.get_input_method_context()
+ im.set_enable_preedit(True)
-
-
# self.webview.load_uri("http://127.0.0.1:10086/index.html")
self.webview.load_uri("app:///index.html")
# self.webview.load_uri("https://benchmark.wkit.fun")
+
+
+
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
-
-
-
self.add(self.webview)
+
def resource_request_callback(self, req):
schema = req.get_scheme()
@@ -96,11 +102,6 @@ class WebKitWindow(Gtk.Window):
if schema == 'app':
data = open(self.file_path('./webview' + pathname)).read()
data = Gio.MemoryInputStream.new_from_data(data.encode())
- # res = WebKit2.URISchemeResponse.new(data, -1)
- # res.set_content_type(get_mimetype(ext))
- # res.set_http_headers('text/html')
- # res.set_status(200)
- # req.finish_with_response(res)
req.finish(data, -1, get_mimetype(ext))
return True
else:
@@ -344,6 +345,22 @@ class WebKitWindow(Gtk.Window):
elif params['action'] == 'is_visible':
output = self.is_visible()
+ case 'notify':
+ title = params.get('title')
+ summary = params.get('summary')
+ icon = params.get('icon')
+ progress = params.get('progress')
+ urgency = params.get('urgency')
+
+ notify = Notify.Notification.new(title, summary, icon)
+
+ if progress:
+ notify.set_hint('value', progress)
+
+ notify.set_urgency(urgency)
+ notify.add_action("click", "Click Me!", my_callback_func)
+
+ notify.show()
# 有回调则返回结果
if callback :
@@ -352,8 +369,13 @@ class WebKitWindow(Gtk.Window):
def all_quit(win):
print('朕要休息了~~~')
+ Notify.uninit()
Gtk.main_quit()
+def my_callback_func(notification, action_name, user_data):
+ print("Button clicked! Action name: %s" % action_name)
+ notification.close()
+
win = WebKitWindow()
@@ -361,6 +383,7 @@ win.connect("destroy", all_quit)
win.show_all()
+
tray = win.create_tray()
Gtk.main()
\ No newline at end of file
diff --git a/webview/app.js b/webview/app.js
index 22560ff..990277f 100644
--- a/webview/app.js
+++ b/webview/app.js
@@ -80,6 +80,13 @@ class App extends Component {
>
rename
+
`