mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
web: 移除Safari<14.5兼容处理
This commit is contained in:
parent
31e10b3010
commit
478a50f0eb
@ -22,9 +22,18 @@ ajax.interceptors.response.use((response) => response, APIExceptionHandler);
|
|||||||
const getReadConfig = () => ajax.get("/getReadConfig");
|
const getReadConfig = () => ajax.get("/getReadConfig");
|
||||||
const saveReadConfig = (config) => ajax.post("/saveReadConfig", config);
|
const saveReadConfig = (config) => ajax.post("/saveReadConfig", config);
|
||||||
|
|
||||||
const saveBookProcess = (bookProgress) =>
|
const saveBookProgress = (bookProgress) =>
|
||||||
ajax.post("/saveBookProgress", bookProgress);
|
ajax.post("/saveBookProgress", bookProgress);
|
||||||
|
|
||||||
|
const saveBookProgressWithBeacon = (bookProgress) => {
|
||||||
|
if (!bookProgress) return;
|
||||||
|
// 常规请求可能会被取消 使用Fetch keep-alive 或者 navigator.sendBeacon
|
||||||
|
navigator.sendBeacon(
|
||||||
|
`${import.meta.env.VITE_API || location.origin}/saveBookProgress`,
|
||||||
|
JSON.stringify(bookProgress)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const getBookShelf = () => ajax.get("/getBookshelf");
|
const getBookShelf = () => ajax.get("/getBookshelf");
|
||||||
|
|
||||||
const getChapterList = (/** @type {string} */ bookUrl) =>
|
const getChapterList = (/** @type {string} */ bookUrl) =>
|
||||||
@ -114,7 +123,8 @@ const debug = (
|
|||||||
export default {
|
export default {
|
||||||
getReadConfig,
|
getReadConfig,
|
||||||
saveReadConfig,
|
saveReadConfig,
|
||||||
saveBookProcess,
|
saveBookProgress,
|
||||||
|
saveBookProgressWithBeacon,
|
||||||
getBookShelf,
|
getBookShelf,
|
||||||
getChapterList,
|
getChapterList,
|
||||||
getBookContent,
|
getBookContent,
|
||||||
|
@ -22,7 +22,6 @@ export function getImageFromLegado(src) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
||||||
export const dateFormat = (/** @type {number} */ t) => {
|
export const dateFormat = (/** @type {number} */ t) => {
|
||||||
let time = new Date().getTime();
|
let time = new Date().getTime();
|
||||||
let offset = Math.floor((time - t) / 1000);
|
let offset = Math.floor((time - t) / 1000);
|
||||||
|
@ -100,7 +100,7 @@ export const useBookStore = defineStore("book", {
|
|||||||
//保存进度到app
|
//保存进度到app
|
||||||
async saveBookProgress() {
|
async saveBookProgress() {
|
||||||
if (!this.bookProgress) return Promise.resolve();
|
if (!this.bookProgress) return Promise.resolve();
|
||||||
return API.saveBookProcess(this.bookProgress);
|
return API.saveBookProgress(this.bookProgress);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -312,21 +312,18 @@ const saveReadingBookProgressToBrowser = (index, pos) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 进度同步
|
// 进度同步
|
||||||
// 返回同步 同步请求会在获取书架前完成
|
// 返回导航变化 同步请求会在获取书架前完成
|
||||||
// 关闭页面 切换tab 返回桌面 等操作 https://developer.mozilla.org/zh-CN/docs/Web/API/Document/visibilitychange_event
|
|
||||||
|
/**
|
||||||
|
* VisibilityChange https://developer.mozilla.org/zh-CN/docs/Web/API/Document/visibilitychange_event
|
||||||
|
* 监听关闭页面 切换tab 返回桌面 等操作
|
||||||
|
* 注意不用监听点击链接导航变化 不对Safari<14.5兼容处理
|
||||||
|
**/
|
||||||
const onVisibilityChange = () => {
|
const onVisibilityChange = () => {
|
||||||
if (!bookProgress.value) return;
|
|
||||||
if (document.visibilityState == "hidden") {
|
if (document.visibilityState == "hidden") {
|
||||||
// Safari > 14 和 非Safari移除额外pagehide event
|
API.saveBookProgressWithBeacon(bookProgress.value);
|
||||||
document.removeEventListener("pagehide", onVisibilityChange);
|
|
||||||
// 常规请求可能会被取消 使用Fetch keep-alive 或者 navigator.sendBeacon
|
|
||||||
navigator.sendBeacon(
|
|
||||||
`${import.meta.env.VITE_API || location.origin}/saveBookProgress`,
|
|
||||||
JSON.stringify(bookProgress.value)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 定时同步
|
// 定时同步
|
||||||
|
|
||||||
// 章节切换
|
// 章节切换
|
||||||
@ -470,8 +467,6 @@ onMounted(() => {
|
|||||||
window.addEventListener("keyup", handleKeyPress);
|
window.addEventListener("keyup", handleKeyPress);
|
||||||
// 兼容Safari < 14
|
// 兼容Safari < 14
|
||||||
document.addEventListener("visibilitychange", onVisibilityChange);
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
||||||
// 兼容Safari < 14.5
|
|
||||||
document.addEventListener("pagehide", onVisibilityChange);
|
|
||||||
//监听底部加载
|
//监听底部加载
|
||||||
scrollObserve.value = new IntersectionObserver(handleIScrollObserve, {
|
scrollObserve.value = new IntersectionObserver(handleIScrollObserve, {
|
||||||
rootMargin: "-100% 0% 20% 0%",
|
rootMargin: "-100% 0% 20% 0%",
|
||||||
@ -493,8 +488,6 @@ onUnmounted(() => {
|
|||||||
window.removeEventListener("keyup", handleKeyPress);
|
window.removeEventListener("keyup", handleKeyPress);
|
||||||
// 兼容Safari < 14
|
// 兼容Safari < 14
|
||||||
document.removeEventListener("visibilitychange", onVisibilityChange);
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
||||||
// 兼容Safari < 14.5
|
|
||||||
document.removeEventListener("pagehide", onVisibilityChange);
|
|
||||||
readSettingsVisible.value = false;
|
readSettingsVisible.value = false;
|
||||||
popCataVisible.value = false;
|
popCataVisible.value = false;
|
||||||
scrollObserve.value?.disconnect();
|
scrollObserve.value?.disconnect();
|
||||||
|
Loading…
Reference in New Issue
Block a user