blabla
parent
98023484cf
commit
69c15d3f57
|
@ -356,5 +356,8 @@ Object.assign(native, {
|
||||||
handler('window', { action: 'set_keep_below', value: setting }, null)
|
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
|
handler
|
||||||
})
|
})
|
||||||
|
|
43
main.py
43
main.py
|
@ -6,8 +6,9 @@ import gi, json, os, shutil
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
gi.require_version("WebKit2", "4.1")
|
gi.require_version("WebKit2", "4.1")
|
||||||
gi.require_version("Keybinder", "3.0")
|
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 gi.repository.GdkPixbuf import Pixbuf
|
||||||
|
|
||||||
from notes.utils import *
|
from notes.utils import *
|
||||||
|
@ -23,7 +24,9 @@ except (ValueError, ImportError):
|
||||||
|
|
||||||
# 初始化 Keybinder
|
# 初始化 Keybinder
|
||||||
Keybinder.init()
|
Keybinder.init()
|
||||||
|
Notify.init(Notify.get_app_name() or 'webapp')
|
||||||
|
|
||||||
|
# im_context = Gtk.IMContext()
|
||||||
|
|
||||||
|
|
||||||
class WebKitWindow(Gtk.Window):
|
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")
|
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()
|
manager = WebKit2.UserContentManager()
|
||||||
|
|
||||||
script = open(self.file_path('./inject.js'), 'r').read()
|
script = open(self.file_path('./inject.js'), 'r').read()
|
||||||
|
@ -69,24 +73,26 @@ class WebKitWindow(Gtk.Window):
|
||||||
|
|
||||||
context = self.webview.get_context()
|
context = self.webview.get_context()
|
||||||
context.register_uri_scheme('app', self.resource_request_callback)
|
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("http://127.0.0.1:10086/index.html")
|
||||||
self.webview.load_uri("app:///index.html")
|
self.webview.load_uri("app:///index.html")
|
||||||
# self.webview.load_uri("https://benchmark.wkit.fun")
|
# self.webview.load_uri("https://benchmark.wkit.fun")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.add(self.webview)
|
self.add(self.webview)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def resource_request_callback(self, req):
|
def resource_request_callback(self, req):
|
||||||
|
|
||||||
schema = req.get_scheme()
|
schema = req.get_scheme()
|
||||||
|
@ -96,11 +102,6 @@ class WebKitWindow(Gtk.Window):
|
||||||
if schema == 'app':
|
if schema == 'app':
|
||||||
data = open(self.file_path('./webview' + pathname)).read()
|
data = open(self.file_path('./webview' + pathname)).read()
|
||||||
data = Gio.MemoryInputStream.new_from_data(data.encode())
|
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))
|
req.finish(data, -1, get_mimetype(ext))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -344,6 +345,22 @@ class WebKitWindow(Gtk.Window):
|
||||||
elif params['action'] == 'is_visible':
|
elif params['action'] == 'is_visible':
|
||||||
output = self.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 :
|
if callback :
|
||||||
|
@ -352,8 +369,13 @@ class WebKitWindow(Gtk.Window):
|
||||||
|
|
||||||
def all_quit(win):
|
def all_quit(win):
|
||||||
print('朕要休息了~~~')
|
print('朕要休息了~~~')
|
||||||
|
Notify.uninit()
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
||||||
|
def my_callback_func(notification, action_name, user_data):
|
||||||
|
print("Button clicked! Action name: %s" % action_name)
|
||||||
|
notification.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
win = WebKitWindow()
|
win = WebKitWindow()
|
||||||
|
@ -361,6 +383,7 @@ win.connect("destroy", all_quit)
|
||||||
win.show_all()
|
win.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tray = win.create_tray()
|
tray = win.create_tray()
|
||||||
|
|
||||||
Gtk.main()
|
Gtk.main()
|
|
@ -80,6 +80,13 @@ class App extends Component {
|
||||||
>
|
>
|
||||||
rename
|
rename
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
@click=${async function () {
|
||||||
|
native.notify({ title: 'hello', icon: 'chrome' })
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
通知
|
||||||
|
</button>
|
||||||
<img style="width:100px;border:1px solid #09f;" src=${this.img} />
|
<img style="width:100px;border:1px solid #09f;" src=${this.img} />
|
||||||
<textarea @paste=${this.pasteImg}></textarea>
|
<textarea @paste=${this.pasteImg}></textarea>
|
||||||
`
|
`
|
||||||
|
|
Reference in New Issue