mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Code to launch WebWorkers
This commit is contained in:
parent
d7efe7d8f9
commit
486413f267
@ -1,6 +1,6 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
# globals: ρσ_get_module
|
||||
# globals: ρσ_get_module, self
|
||||
from __python__ import hash_literals
|
||||
|
||||
import initialize # noqa: unused-import
|
||||
@ -13,6 +13,15 @@ autoreload_enabled = False
|
||||
AUTO_UPDATE_THRESHOLD = 1000 # millisecs
|
||||
|
||||
|
||||
def worker_main(entry_point):
|
||||
m = ρσ_get_module(window.iframe_entry_point)
|
||||
main = m?.main
|
||||
if main:
|
||||
main()
|
||||
else:
|
||||
console.log('worker entry_point ' + entry_point + ' not found')
|
||||
|
||||
|
||||
def iframe_main(script):
|
||||
script.parentNode.removeChild(script) # free up some memory
|
||||
script = undefined
|
||||
@ -58,3 +67,8 @@ if document?:
|
||||
iframe_main(iframe_script)
|
||||
else:
|
||||
toplevel_main()
|
||||
url = window.URL.createObjectURL(Blob([main_js()]), {'type': 'text/javascript'})
|
||||
worker = new window.Worker(url + '#moo')
|
||||
console.log(worker)
|
||||
elif self?:
|
||||
entry_point = self.location.hash[1:]
|
||||
|
15
src/pyj/worker.pyj
Normal file
15
src/pyj/worker.pyj
Normal file
@ -0,0 +1,15 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from __python__ import bound_methods, hash_literals
|
||||
|
||||
from book_list.globals import main_js
|
||||
|
||||
|
||||
def worker_js_url(entry_point):
|
||||
if not worker_js_url.ans:
|
||||
worker_js_url.ans = window.URL.createObjectURL(Blob([main_js()]), {'type': 'text/javascript'})
|
||||
return worker_js_url.ans + '#' + entry_point
|
||||
|
||||
|
||||
def start_worker(entry_point):
|
||||
return new window.Worker(worker_js_url(entry_point))
|
Loading…
x
Reference in New Issue
Block a user