diff --git a/README.md b/README.md index 2121b6b..bba6aeb 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,12 @@
July 2023 +**23.07.25** + +- 修改当缓存中发现多余图片但符合hash标准时,由删除图片改为添加到configs.json,以应对跨设备同步 +- 修复透明模式和兼容模式设置的UI不起效bug +- 开发者模式的输出日志中,前置提示词修改 + **23.07.22** - 重构项目结构 diff --git a/README_en_US.md b/README_en_US.md index f16aa10..d9e33ee 100644 --- a/README_en_US.md +++ b/README_en_US.md @@ -97,6 +97,12 @@ It is recommended for theme authors to follow the SourceNote theme template and
July 2023 +**23.07.25** + +* Change from deleting images to adding them to configs.json when redundant images are found in the cache but meet the hash criteria, in order to handle cross-device synchronization. +* Fix the bug where the UI settings for transparent mode and compatibility mode are not effective. +* Modify the prefix prompt in the output logs of developer mode. + **23.07.22** - Refactor project structure. diff --git a/src/bgRender.ts b/src/bgRender.ts index 1f35e7c..fb52053 100644 --- a/src/bgRender.ts +++ b/src/bgRender.ts @@ -16,6 +16,7 @@ import { CloseCV, MD5, OS, Numpy, getThemeInfo } from './utils'; +import { type } from 'os'; let np = new Numpy(); let cv2 = new CloseCV(); @@ -32,7 +33,7 @@ export function createBgLayer() { } export function useDefaultLiaoLiaoBg() { - debug(`[Func][applySettings] 没有缓存任何图片,使用默认的了了妹图片ULR来当作背景图`) + debug(`[bgRender][applySettings] 没有缓存任何图片,使用默认的了了妹图片ULR来当作背景图`) changeBackgroundContent(cst.demoImgURL, cst.bgMode.image) configs.set('bgObj', undefined); } @@ -41,7 +42,7 @@ export function changeBackgroundContent(background: string, mode: cst.bgMode) { var bgLayer = document.getElementById('bglayer'); if (mode === cst.bgMode.image) { - debug(`[Func][changeBackgroundContent] 替换当前背景图片为${background}`) + debug(`[bgRender][changeBackgroundContent] 替换当前背景图片为${background}`) bgLayer.style.setProperty('background-image', `url('${background}')`); } else if (mode == cst.bgMode.video) { noticeUI.showIndev(); @@ -52,11 +53,15 @@ export function changeBackgroundContent(background: string, mode: cst.bgMode) { } }; -export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tranMode: number, adaptMode: boolean) { +export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, transMode: number, adaptMode: boolean) { // opacity mode: fully transparent (adaptMode=False) // css mode: only background transparent (adaptMode=True) let opacity = 0.99 - 0.25 * alpha; + if (typeof transMode == 'string'){ + transMode = parseInt(transMode); + }; + const [themeMode, themeName] = getThemeInfo(); let operateElement: { @@ -110,7 +115,8 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran let themeAdaptObject: cst.themeAdaptObject; let themeAdaptElement: string[] = []; - if (themeName in adp.toAdaptThemes) { // 如果当前的主题在主题适配列表中 + if (themeName in adp.toAdaptThemes && adaptMode) { + // 如果当前的主题在主题适配列表中且启用兼容模式 // 获取constance.ts的配置中,所有需要适配主题对应的element id和对应的css值 themeAdaptObject = adp.toAdaptThemes[themeName]; // >>> "Savor": {...} @@ -122,7 +128,7 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran const itemName = themeAdaptElement[i]; // 如果是".xxxx"开头,说明这边要改的是css的样式 - debug(`[Func][chageOpacity] 添加主题适配列表内容${itemName}.slice(0,1) === '.'`, itemName.slice(0,1) === '.') + debug(`[bgRender][chageOpacity] 添加主题适配列表内容${itemName}.slice(0,1) === '.'`, itemName.slice(0,1) === '.') if (itemName.slice(0,1) === '.') { // 如果不含有当前的元素,则添加 if (!operateElement.css.operateCssStyle.includes(itemName)) { @@ -136,7 +142,7 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran } } - debug(`[Func][changeOpacity] operateElement: `, operateElement) + debug(`[bgRender][changeOpacity] operateElement: `, operateElement) /** * 用户打开图片背景 @@ -152,7 +158,10 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran let rmElementStyle: string[]; let restoreCssStyle: string[]; - if (adaptMode) { // 开启css的透明模式 + debug(`${transMode}, ${typeof transMode}`) + + if (transMode === 1 ) { // 开启css的透明模式(部分透明) + debug(`[bgRender][changeOpacity] 检测到tranMode为${transMode} - 部分透明模式`) addOpacityElement = operateElement.css.operateOpacityElement; zIndexValue = operateElement.css.zIndexValue; addElementStyle = operateElement.css.operateElementStyle; @@ -161,7 +170,8 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran rmOpacityElement = operateElement.opacity.operateOpacityElement; rmElementStyle = operateElement.opacity.operateElementStyle; restoreCssStyle = operateElement.opacity.operateCssStyle; - } else { // 开启 opacity 透明模式 + } else { // 开启 opacity 透明模式 (全局透明) + debug(`[bgRender][changeOpacity] 检测到tranMode为${transMode} - 全局透明模式`) addOpacityElement = operateElement.opacity.operateOpacityElement; zIndexValue = operateElement.opacity.zIndexValue; addElementStyle = operateElement.opacity.operateElementStyle; @@ -195,7 +205,7 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran var themeAdaptColor: string; var adaptColor: string; - debug(`[Func][changeOpacity] 修改元素ID为${elementid}的元素alpha值`); + debug(`[bgRender][changeOpacity] 修改元素ID为${elementid}的元素alpha值`); if (themeAdaptElement.includes(elementid)) { // 如果当前元素的css在主题适配列表中,直接获取适配列表中的配置 @@ -207,7 +217,7 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran adaptColor = cv2.changeColorOpacity(themeAdaptColor, opacity); } - debug(`[Func][changeOpacity] ${elementid} originalColor: ${themeAdaptColor}, adaptColor: ${adaptColor}`); + debug(`[bgRender][changeOpacity] ${elementid} originalColor: ${themeAdaptColor}, adaptColor: ${adaptColor}`); changeItem.style.setProperty('background-color', adaptColor, 'important'); changeItem.style.setProperty('background-blend-mode', `lighten`); @@ -224,16 +234,16 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran } // 遍历修改css自身的值 - if (adaptMode) { + if (transMode === 1) { var sheets = document.styleSheets; if (editCssStyle.length + restoreCssStyle.length > 0) { // 遍历所有的css style,找到指定的css for (var i in sheets) { - debug(`[Func][changeOpacity] 当前遍历到的CSS Style文件为:`, sheets[i].href) + debug(`[bgRender][changeOpacity] 当前遍历到的CSS Style文件为:`, sheets[i].href) try { var rules = sheets[i].cssRules; } catch (err) { - const errorMessage = `[${pluginInstance.i18n.addTopBarIcon} Plugin] ${pluginInstance.i18n.themeCssReadDOMError}
ErrorFile: ${sheets[i].href} when calling document.styleSheets[${i}].cssRules;` + const errorMessage = `[${window.bgCoverPlugin.i18n.addTopBarIcon} Plugin] ${window.bgCoverPlugin.i18n.themeCssReadDOMError}
ErrorFile: ${sheets[i].href} when calling document.styleSheets[${i}].cssRules;` // showMessage(errorMessage, 0, 'error'); error(errorMessage, err); @@ -268,7 +278,7 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran } rule.style.setProperty('background-color', transparentColor, 'important'); - debug(`[Func][changeOpacity]修改css属性表${csstext},从${cssColor}修改为透明色${transparentColor}`, rule.style); + debug(`[bgRender][changeOpacity]修改css属性表${csstext},从${cssColor}修改为透明色${transparentColor}`, rule.style); } // 需要恢复的css属性 @@ -281,7 +291,7 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran rule.style.removeProperty('background-color') } - debug(`[Func][changeOpacity]恢复css属性表${csstext}为主题默认色${pluginInstance.cssThemeStyle[csstext]}`, rule.style); + debug(`[bgRender][changeOpacity]恢复css属性表${csstext}为主题默认色${pluginInstance.cssThemeStyle[csstext]}`, rule.style); } } } @@ -298,7 +308,7 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran operateElement.opacity.operateOpacityElement, operateElement.css.operateOpacityElement, ) - debug(`[Func][changeOpacity] 移除下列元素的opacity和z-index值:`, removeOpacityElement) + debug(`[bgRender][changeOpacity] 移除下列元素的opacity和z-index值:`, removeOpacityElement) for (let eid in removeOpacityElement) { const elementid: string = removeOpacityElement[eid] var changeItem = document.getElementById(elementid) @@ -310,7 +320,7 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran operateElement.opacity.operateElementStyle, operateElement.css.operateElementStyle, ); - debug(`[Func][changeOpacity] 移除下列元素的background-color和blend-mode值:`, removeCssElement); + debug(`[bgRender][changeOpacity] 移除下列元素的background-color和blend-mode值:`, removeCssElement); for (let eid in removeCssElement) { const elementid: string = removeCssElement[eid]; var changeItem = document.getElementById(elementid); @@ -328,11 +338,11 @@ export function changeOpacity(pluginInstance: BgCoverPlugin, alpha: number, tran if (removeCssStyle.length > 0 && adaptMode) { // 遍历所有的css style,找到指定的css for (var i in sheets) { - debug(`[Func][changeOpacity] 当前遍历到的CSS Style文件为:`, sheets[i]) + debug(`[bgRender][changeOpacity] 当前遍历到的CSS Style文件为:`, sheets[i]) try { var rules = sheets[i].cssRules; } catch (err) { - const errorMessage = `[${pluginInstance.i18n.addTopBarIcon} Plugin] ${pluginInstance.i18n.themeCssReadDOMError}
ErrorFile: ${sheets[i].href} when calling document.styleSheets[${i}].cssRules;` + const errorMessage = `[${window.bgCoverPlugin.i18n.addTopBarIcon} Plugin] ${window.bgCoverPlugin.i18n.themeCssReadDOMError}
ErrorFile: ${sheets[i].href} when calling document.styleSheets[${i}].cssRules;` // showMessage(errorMessage, 0, 'error'); error(errorMessage, err); @@ -375,10 +385,10 @@ export function changeBgPosition(x: string, y: string) { var bgLayer = document.getElementById('bglayer'); if (x == null || x == undefined) { - debug(`[Func][changeBgPosition] xy未定义,不进行改变`) + debug(`[bgRender][changeBgPosition] xy未定义,不进行改变`) bgLayer.style.setProperty('background-position', `center`); } else { - debug(`[Func][changeBgPosition] 修改background-position为${x}% ${y}%`) + debug(`[bgRender][changeBgPosition] 修改background-position为${x}% ${y}%`) bgLayer.style.setProperty('background-position', `${x}% ${y}%`); } } @@ -395,26 +405,26 @@ export async function applySettings(pluginInstance: BgCoverPlugin) { // 缓存文件夹中没有图片 | 用户刚刚使用这个插件 | 用户刚刚重置了插件数据 | 当前文件404找不到 const cacheImgNum = fileManagerUI.getCacheImgNum() - debug(`[Func][applySettings] cacheImgNum= ${cacheImgNum}`) + debug(`[bgRender][applySettings] cacheImgNum= ${cacheImgNum}`) if (cacheImgNum === 0) { // 没有缓存任何图片,使用默认的了了妹图片ULR来当作背景图 useDefaultLiaoLiaoBg(); } else if (configs.get('bgObj') === undefined) { // 缓存中有1张以上的图片,但是设置的bjObj却是undefined,随机抽一张 - debug(`[Func][applySettings] 缓存中有1张以上的图片,但是设置的bjObj却是undefined,随机抽一张`) + debug(`[bgRender][applySettings] 缓存中有1张以上的图片,但是设置的bjObj却是undefined,随机抽一张`) await topbarUI.selectPictureRandom(pluginInstance); } else { // 缓存中有1张以上的图片,bjObj也有内容且图片存在 - debug(`[Func][applySettings] 缓存中有1张以上的图片,bjObj也有内容且图片存在`) + debug(`[bgRender][applySettings] 缓存中有1张以上的图片,bjObj也有内容且图片存在`) let bgObj = configs.get('bgObj') let fileidx = configs.get('fileidx') // 没有开启启动自动更换图片,则直接显示该图片 if (bgObj.hash in fileidx && !configs.get('autoRefresh')) { - debug(`[Func][applySettings] 没有开启启动自动更换图片,则直接显示当前图片`) + debug(`[bgRender][applySettings] 没有开启启动自动更换图片,则直接显示当前图片`) changeBackgroundContent(bgObj.path, bgObj.mode) } else { // 当bjObj找不到404 | 用户选择随机图片,则随机调一张作为bjObj - debug(`[Func][applySettings] 用户选择随机图片,则随机调一张作为bjObj`) + debug(`[bgRender][applySettings] 用户选择随机图片,则随机调一张作为bjObj`) await topbarUI.selectPictureRandom(pluginInstance); } } diff --git a/src/bugreportUI.ts b/src/bugreportUI.ts index a42ca01..5d934b4 100644 --- a/src/bugreportUI.ts +++ b/src/bugreportUI.ts @@ -3,12 +3,12 @@ import BgCoverPlugin from "./index" export function bugReportDialog(pluginInstance: BgCoverPlugin) { const dialog = new Dialog({ - title: `${pluginInstance.i18n.bugReportLabel}`, + title: `${window.bgCoverPlugin.i18n.bugReportLabel}`, content: ` -
${pluginInstance.i18n.bugReportConfirmText}
+
${window.bgCoverPlugin.i18n.bugReportConfirmText}
-
- +
+
`, diff --git a/src/constants.ts b/src/constants.ts index 9ca913f..5d1f551 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,9 @@ import packageInfo from '../plugin.json' +declare global { + interface Window { bgCoverPlugin : any; } +} + export enum bgMode { image = 0, video = 1, diff --git a/src/fileManagerUI.ts b/src/fileManagerUI.ts index b9f8e09..746561b 100644 --- a/src/fileManagerUI.ts +++ b/src/fileManagerUI.ts @@ -43,7 +43,7 @@ export async function checkCacheDirctory(pluginInstance: BgCoverPlugin) { let imgFiles = await os.listdir(oldpluginAssetsDir); if (imgFiles !== null && imgFiles.length > 0) { - showMessage(pluginInstance.i18n.cacheDirectoryMove, 7000, "info"); + showMessage(window.bgCoverPlugin.i18n.cacheDirectoryMove, 7000, "info"); await os.rmtree(oldpluginAssetsDir); } } @@ -68,7 +68,7 @@ export async function checkCacheDirctory(pluginInstance: BgCoverPlugin) { continue } else { // 背景图片 - debug(`[Func][checkCacheDirectory] Check ${item.name} in cached dir`) + debug(`[fileManagerUI][checkCacheDirectory] Check ${item.name} in cached dir`) if (item.name.slice(0, 5) === 'hash-') { const [hash_name, suffix] = os.splitext(item.name.split('-')[1]) @@ -103,8 +103,25 @@ export async function checkCacheDirctory(pluginInstance: BgCoverPlugin) { } } else { // 在缓存文件夹中,但图片并不在fileidx中(图片多余了) + // 更新版本:把多余的图片添加到缓存中而不是删除 extraCacheImgs.push(item.name) - ka.removeFile(`${cst.pluginImgDataDir}/${item.name}`) + //ka.removeFile(`${cst.pluginImgDataDir}/${item.name}`) + // slice(5) to remove '/data' prefix + const imgPath = `${cst.pluginImgDataDir.slice(5)}/${item.name}` + const imageSize = await cv2.getImageSize(imgPath) + + let bgObj: cst.bgObj = { + name: item.name, + path: imgPath, + hash: item.name.slice(0, 5), + mode: cst.bgMode.image, + offx: 50, + offy: 50, + height: imageSize.height, + width: imageSize.width + } + + fileidx[hash_name] = bgObj } } else { // 非法缓存图片 @@ -126,19 +143,19 @@ export async function checkCacheDirctory(pluginInstance: BgCoverPlugin) { // raise warning to users if (notCorrectCacheImgs.length !== 0) { - let msgInfo = `${pluginInstance.i18n.cacheImgWrongName}
[${notCorrectCacheImgs}]
${pluginInstance.i18n.doNotOperateCacheFolder}` + let msgInfo = `${window.bgCoverPlugin.i18n.cacheImgWrongName}
[${notCorrectCacheImgs}]
${window.bgCoverPlugin.i18n.doNotOperateCacheFolder}` showMessage(msgInfo, 7000, "info") info(msgInfo) } if (extraCacheImgs.length !== 0) { - let msgInfo = `${pluginInstance.i18n.cacheImgExtra}
[${extraCacheImgs}]
${pluginInstance.i18n.doNotOperateCacheFolder}` + let msgInfo = `${window.bgCoverPlugin.i18n.cacheImgExtra}
[${extraCacheImgs}]
${window.bgCoverPlugin.i18n.doNotOperateCacheFolder}` showMessage(msgInfo, 7000, "info") info(msgInfo) } if (missingCacheImgs.length !== 0) { - let msgInfo = `${pluginInstance.i18n.cacheImgMissing}
[${missingCacheImgs}]
${pluginInstance.i18n.doNotOperateCacheFolder}` + let msgInfo = `${window.bgCoverPlugin.i18n.cacheImgMissing}
[${missingCacheImgs}]
${window.bgCoverPlugin.i18n.doNotOperateCacheFolder}` showMessage(msgInfo, 7000, "info") info(msgInfo) } @@ -204,12 +221,12 @@ export function imgExistsInCache( if (fileidx !== undefined && md5 in fileidx) { if (notice) { const dialog = new Dialog({ - title: `${pluginInstance.i18n.inDevTitle}`, - content: `
${pluginInstance.i18n.imageFileExist}
`, + title: `${window.bgCoverPlugin.i18n.inDevTitle}`, + content: `
${window.bgCoverPlugin.i18n.imageFileExist}
`, width: pluginInstance.isMobile ? "92vw" : "520px", }); }else{ - debug(`[Func][imgIsInCache] 当前图片${file.name}已存在`) + debug(`[fileManagerUI][imgIsInCache] 当前图片${file.name}已存在`) } return 'exists' } else { @@ -220,7 +237,7 @@ export function imgExistsInCache( export async function uploadOneImage(pluginInstance: BgCoverPlugin, file: File) { let fileSizeMB: number = (file.size / 1024 / 1024); - showMessage(`${file.name}-${fileSizeMB.toFixed(2)}MB
${pluginInstance.i18n.addSingleImageUploadNotice}`, 3000, "info"); + showMessage(`${file.name}-${fileSizeMB.toFixed(2)}MB
${window.bgCoverPlugin.i18n.addSingleImageUploadNotice}`, 3000, "info"); let md5 = imgExistsInCache(pluginInstance, file); @@ -258,7 +275,7 @@ export async function uploadOneImage(pluginInstance: BgCoverPlugin, file: File) configs.set('bgObj', bgObj); configs.set('fileidx', fileidx); - debug(`[func][addSingleLocalImageFile]: fileidx ${fileidx}`); + debug(`[fileManagerUI][addSingleLocalImageFile]: fileidx ${fileidx}`); return bgObj } else { @@ -276,23 +293,23 @@ export async function batchUploadImages( { let bgObj:cst.bgObj; - debug('[Func][batchUploadImages] fileArray', fileArray) + debug('[fileManagerUI][batchUploadImages] fileArray', fileArray) if (fileArray.length === 0) { - debug('[Func][batchUploadImages] fileArray为空,不存在需要上传的图片') + debug('[fileManagerUI][batchUploadImages] fileArray为空,不存在需要上传的图片') }else{ for (let i in fileArray) { let file = fileArray[i]; bgObj = await uploadOneImage(pluginInstance, file); - debug('[Func][batchUploadImages] 在上传的循环内', bgObj) + debug('[fileManagerUI][batchUploadImages] 在上传的循环内', bgObj) }; await configs.save(); if (applySetting){ - debug('[Func][batchUploadImages] 在应用设置的判断内', bgObj) + debug('[fileManagerUI][batchUploadImages] 在应用设置的判断内', bgObj) bgRender.changeBackgroundContent(bgObj.path, bgObj.mode); settingsUI.updateSettingPanelElementStatus(); } @@ -305,7 +322,7 @@ export async function batchUploadImages( export async function selectPictureDialog(pluginInstance: BgCoverPlugin) { const cacheManagerDialog = new Dialog({ - title: pluginInstance.i18n.selectPictureManagerTitle, + title: window.bgCoverPlugin.i18n.selectPictureManagerTitle, width: pluginInstance.isMobile ? "92vw" : "520px", height: "92vh", content: ` @@ -315,14 +332,14 @@ export async function selectPictureDialog(pluginInstance: BgCoverPlugin) {
- ${pluginInstance.i18n.selectPictureManagerTab1} + ${window.bgCoverPlugin.i18n.selectPictureManagerTab1}
@@ -336,7 +353,7 @@ export async function selectPictureDialog(pluginInstance: BgCoverPlugin) { @@ -349,10 +366,10 @@ export async function selectPictureDialog(pluginInstance: BgCoverPlugin) { 20230609230328-7vp057x.png - + - + @@ -390,7 +407,7 @@ export async function selectPictureDialog(pluginInstance: BgCoverPlugin) { cacheImgListElement.appendChild(element); } - debug('[Func][selectPictureByHand]', listHtmlArray, cacheImgListElement); + debug('[fileManagerUI][selectPictureByHand]', listHtmlArray, cacheImgListElement); let deleteAllImgBtn = document.getElementById('removeAllImgs'); deleteAllImgBtn.addEventListener('click', clearCacheFolder.bind(pluginInstance, cst.bgMode.image)); @@ -425,10 +442,10 @@ export function generateCacheImgList(pluginInstance: BgCoverPlugin){ ${bgObj.name} - + - + @@ -472,7 +489,7 @@ export function generateCacheImgList(pluginInstance: BgCoverPlugin){ configs.set('fileidx', fileidx); // 调用os来移除本地文件夹中的缓存文件 - debug(`[Func][_rmBg] 移除下列路径的图片:${cst.pluginImgDataDir}/${bgObj.name}`); + debug(`[fileManagerUI][_rmBg] 移除下列路径的图片:${cst.pluginImgDataDir}/${bgObj.name}`); ka.removeFile(`data/${bgObj.path}`); // 检查当前文件数量是否为空,如果为空则设置为默认了了图 diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index 32adce7..cc1af30 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -44,7 +44,7 @@ "cacheImgMissing": "Find the following images missing in the cache folder:", "cacheImgExtra": "Find the following images not in the cache index:", "cacheManager": "Manage", - "doNotOperateCacheFolder": "No worries, but please do not operate the cache directory in the file explorer manually", + "doNotOperateCacheFolder": "No worries and has been updated, may caused by cross-device sync", "confirm": "Still reporting", "reset": "Reset", "cancel": "Cancel", diff --git a/src/i18n/zh_CN.json b/src/i18n/zh_CN.json index cc5f2c4..832bd4b 100644 --- a/src/i18n/zh_CN.json +++ b/src/i18n/zh_CN.json @@ -44,7 +44,7 @@ "cacheImgMissing": "发现下列图片在缓存文件夹中丢失:", "cacheImgExtra": "发现下列图片未被缓存记录:", "cacheManager": "管理", - "doNotOperateCacheFolder": "不要恐慌,但请不要手动去修改缓存文件夹中的内容", + "doNotOperateCacheFolder": "不要恐慌,可能由跨设备同步引起,已更新缓存", "confirm": "仍然汇报", "reset": "重置", "cancel": "取消", diff --git a/src/index.ts b/src/index.ts index 17b4763..e98ed54 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,6 +49,11 @@ export default class BgCoverPlugin extends Plugin { const frontEnd = getFrontend(); this.isMobile = frontEnd === "mobile" || frontEnd === "browser-mobile"; + window.bgCoverPlugin = { + i18n: this.i18n, + isMobile: this.isMobile, + } + // 图标的制作参见帮助文档 this.addIcons(cst.diyIcon.iconLogo); @@ -107,7 +112,7 @@ export default class BgCoverPlugin extends Plugin { debug(`frontend: ${getFrontend()}; backend: ${getBackend()}`); // 临时debug用,不用每次都打开 - themeAdapterUI.adaptConfigEditor(this); + // themeAdapterUI.adaptConfigEditor(this); } onunload() { diff --git a/src/noticeUI.ts b/src/noticeUI.ts index b6523fa..7449e96 100644 --- a/src/noticeUI.ts +++ b/src/noticeUI.ts @@ -14,13 +14,13 @@ import { export function showMobileTodo() { - showMessage(`${this.i18n.mobileNotSupported}`, 1000, "info") + showMessage(`${window.bgCoverPlugin.i18n.mobileNotSupported}`, 1000, "info") } export function showIndev(msg: string = '') { const dialog = new Dialog({ - title: `${this.i18n.inDevTitle}`, - content: `
${this.i18n.inDev}${msg}
`, - width: this.isMobile ? "92vw" : "520px", + title: `${window.bgCoverPlugin.i18n.inDevTitle}`, + content: `
${window.bgCoverPlugin.i18n.inDev}${msg}
`, + width: window.bgCoverPlugin.i18nisMobile ? "92vw" : "520px", }); } \ No newline at end of file diff --git a/src/settingsUI.ts b/src/settingsUI.ts index 387472a..44372e4 100644 --- a/src/settingsUI.ts +++ b/src/settingsUI.ts @@ -9,6 +9,7 @@ import * as fileManagerUI from "./fileManagerUI"; import * as topbarUI from "./topbarUI"; import * as bgRender from "./bgRender"; import * as themeAdapterUI from "./themeAdapterUI"; +import * as noticeUI from "./noticeUI" import { error, warn, info, debug, @@ -29,7 +30,7 @@ export function openSettingDialog(pluginInstance: BgCoverPlugin) { const cacheImgNum = fileManagerUI.getCacheImgNum(); const dialog = new Dialog({ - title: `${pluginInstance.i18n.addTopBarIcon}(v${packageInfo.version}) ${pluginInstance.i18n.settingLabel}`, + title: `${window.bgCoverPlugin.i18n.addTopBarIcon}(v${packageInfo.version}) ${window.bgCoverPlugin.i18n.settingLabel}`, width: pluginInstance.isMobile ? "92vw" : "max(520px, 50vw)", height: "max(520px, 90vh)", content: ` @@ -39,7 +40,7 @@ export function openSettingDialog(pluginInstance: BgCoverPlugin) { -->