2023-08-30 18:05:37 +08:00
|
|
|
import { CACHE_NAME } from "../config";
|
2023-08-31 00:18:57 +08:00
|
|
|
import { browser } from "./browser";
|
2023-07-20 13:45:41 +08:00
|
|
|
|
|
|
|
|
/**
|
2023-08-30 18:05:37 +08:00
|
|
|
* 清除缓存数据
|
2023-07-20 13:45:41 +08:00
|
|
|
*/
|
2023-08-30 18:05:37 +08:00
|
|
|
export const tryClearCaches = async () => {
|
2023-08-27 17:43:27 +08:00
|
|
|
try {
|
2023-08-30 18:05:37 +08:00
|
|
|
caches.delete(CACHE_NAME);
|
2023-08-27 17:43:27 +08:00
|
|
|
} catch (err) {
|
2023-08-30 18:05:37 +08:00
|
|
|
console.log("[clean caches]", err.message);
|
2023-08-27 17:43:27 +08:00
|
|
|
}
|
2023-07-20 13:45:41 +08:00
|
|
|
};
|
2023-08-31 00:18:57 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 本地语言识别
|
|
|
|
|
* @param {*} q
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export const detectLang = async (q) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await browser?.i18n?.detectLanguage(q);
|
|
|
|
|
return res?.languages?.[0]?.language;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log("[detect lang]", err);
|
|
|
|
|
}
|
|
|
|
|
};
|