Skip to content

Commit 7c2668d

Browse files
committed
feat: code by Trae
1 parent b5b7d10 commit 7c2668d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

epub_browser/assets/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function initScript() {
302302
// 注册 Service Worker
303303
if ('serviceWorker' in navigator) {
304304
window.addEventListener('load', function() {
305-
navigator.serviceWorker.register('/assets/sw.js')
305+
navigator.serviceWorker.register('/sw.js')
306306
.then(function(registration) {
307307
console.log('ServiceWorker registration successful with scope: ', registration.scope);
308308
})

epub_browser/library.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ def add_assets(self):
123123
# 确保目标目录存在
124124
os.makedirs(os.path.dirname(dst_path), exist_ok=True)
125125
shutil.copy2(src_path, dst_path)
126+
127+
# 复制 sw.js 到根目录(PWA 需要 Service Worker 在根目录)
128+
sw_src = os.path.join(ASSETS_DIR, 'sw.js')
129+
sw_dst = os.path.join(self.base_directory, 'sw.js')
130+
if os.path.exists(sw_src):
131+
shutil.copy2(sw_src, sw_dst)
126132

127133

128134
def create_library_home(self):
@@ -384,6 +390,8 @@ def cleanup(self):
384390
print(f"Cleaned up book: {book_info['title']}, path: {middle_dir}")
385391
if os.path.exists(os.path.join(self.output_dir, "index.html")):
386392
os.remove(os.path.join(self.output_dir, "index.html"))
393+
if os.path.exists(os.path.join(self.output_dir, "sw.js")):
394+
os.remove(os.path.join(self.output_dir, "sw.js"))
387395
if os.path.exists(os.path.join(self.output_dir, "assets")):
388396
shutil.rmtree(os.path.join(self.output_dir, "assets"), ignore_errors=True)
389397
if os.path.exists(os.path.join(self.output_dir, "book")):

0 commit comments

Comments
 (0)