Skip to content

Commit

Permalink
solve the looping of refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
HowcanoeWang committed Jul 31, 2023
1 parent 55439a1 commit 603b840
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 43 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
<details open>
<summary><b>July 2023</b></summary>

**23.07.31**

* 解决伺服时陷入主题更改刷新的死循环

**23.07.26**

* 优化文件哈希逻辑
Expand Down
4 changes: 4 additions & 0 deletions README_en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ It is recommended for theme authors to follow the SourceNote theme template and
<details open>
<summary><b>July 2023</b></summary>

**23.07.31**

* Solve stucking in an infinite loop of theme change and refresh

**23.07.26**

* Optimize file hash logic
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "siyuan-plugin-background-cover",
"author": "HowcanoeWang",
"url": "https://github.com/HowcanoeWang/siyuan-plugin-background-cover",
"version": "0.3.2",
"version": "0.3.3",
"minAppVersion": "2.9.3",
"backends": ["windows", "linux", "darwin"],
"frontends": ["desktop", "browser-desktop"],
Expand Down
30 changes: 0 additions & 30 deletions src/bugreportUI.ts

This file was deleted.

10 changes: 7 additions & 3 deletions src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"closeBackgroundLabel": "Closing Background",
"openBackgroundLabel": "Opening Background",
"openBackgroundLabelDes": "Not display the background when clsoing (but the element still exists in the html code)",
"bugReportLabel": "Bug report",
"settingLabel": "Settings",
"autoRefreshLabel": "Refresh background at launch",
"autoRefreshDes": "The background image will randomly changes after lanuching if checked",
Expand All @@ -45,7 +44,7 @@
"cacheImgExtra": "Find the following images not in the cache index:",
"cacheManager": "Manage",
"doNotOperateCacheFolder": "No worries and has been updated, may caused by cross-device sync",
"confirm": "Still reporting",
"confirm": "Confirm",
"reset": "Reset",
"cancel": "Cancel",
"save": "Save",
Expand All @@ -56,7 +55,9 @@
"addElement": "Add element",
"addStyle": "Add style",
"setAsBg": "Set as background",
"bugReportLabel": "Bug report",
"bugReportConfirmText": "As this background cover plugin is implemented by modifying the opacity of the entire interface, if some UI element's transparency display abnormally after enabling the plugin, please contact the theme author for compatibility adjustments.",
"confirmBugReport": "Still reporting",
"resetConfigLabel": "Reset Configs",
"resetConfigDes": "Reset all configs to default values ",
"resetConfigDes2": "(including all cached images!)",
Expand All @@ -79,5 +80,8 @@
"themeCssReadDOMError": "DOM read css style file failed, this may cause style modification error. Recommend to use global transparency mode or contact theme author for adaptation.",
"inDevModeLabel": "Developer mode",
"inDevModeDes": "Show more logs when open",
"updateHashNotice": "The background plugin version 0.3.2 updated the file hash logic, please re-add the background covers"
"updateHashNotice": "The background plugin version 0.3.2 updated the file hash logic, please re-add the background covers",
"themeOnChangeTitle": "The theme has been changed",
"themeOnChangeMsg": "Recommend to refresh the SiYuan note to make the theme changes taking effect",
"themeRefresh": "Refresh"
}
9 changes: 6 additions & 3 deletions src/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"closeBackgroundLabel": "关闭图片背景",
"openBackgroundLabel": "打开图片背景",
"openBackgroundLabelDes": "关闭后背景图片不显示(但背景元素还存在于html代码中)",
"bugReportLabel": "Bug反馈",
"settingLabel": "设置",
"autoRefreshLabel": "启动时自动更换背景",
"autoRefreshDes": "勾选之后每次启动思源都会随机更换背景图,若要固定某一张图片请取消勾选",
Expand All @@ -45,7 +44,6 @@
"cacheImgExtra": "发现下列图片未被缓存记录:",
"cacheManager": "管理",
"doNotOperateCacheFolder": "不要恐慌,可能由跨设备同步引起,已更新缓存",
"confirm": "仍然汇报",
"reset": "重置",
"cancel": "取消",
"save": "保存",
Expand All @@ -56,7 +54,9 @@
"addElement": "添加元素",
"addStyle": "添加样式",
"setAsBg": "设为背景",
"bugReportLabel": "Bug反馈",
"bugReportConfirmText": "由于该背景插件是通过整体修改opacity实现的,如果开启插件后部分UI透明度/显示异常,请联系主题作者进行适配。",
"confirmBugReport": "仍然汇报",
"resetConfigLabel": "重置设置",
"resetConfigDes": "将所有设置恢复到插件初始值",
"resetConfigDes2": "(包括所有缓存的图片!)",
Expand All @@ -79,5 +79,8 @@
"themeCssReadDOMError": "DOM读取CSS样式文件失败,可能存在样式修改异常,推荐使用全透明模式或联系主题作者尝试适配",
"inDevModeLabel": "开发者模式",
"inDevModeDes": "开启后将显示更多日志输出",
"updateHashNotice": "背景插件0.3.2版本更新了文件哈希逻辑,请重新添加背景图"
"updateHashNotice": "背景插件0.3.2版本更新了文件哈希逻辑,请重新添加背景图",
"themeOnChangeTitle": "侦测到主题改变",
"themeOnChangeMsg": "建议刷新重载思源来使插件适配更改后的主题",
"themeRefresh": "刷新"
}
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ export default class BgCoverPlugin extends Plugin {
}

async onLayoutReady() {


bgRender.createBgLayer();

// 给layouts, dockLeft, dockRight三个元素的父级面板,增加一个方便定位的ID值
Expand All @@ -110,6 +108,9 @@ export default class BgCoverPlugin extends Plugin {

debug(`frontend: ${getFrontend()}; backend: ${getBackend()}`);

// 去除检测到主题变化的提示(因为此时已经刷新了)
noticeUI.removeThemeRefreshDialog();

// 临时debug用,不用每次都打开
// themeAdapterUI.adaptConfigEditor(this);
}
Expand All @@ -133,10 +134,11 @@ export default class BgCoverPlugin extends Plugin {
debug(`Theme changed! from ${prevTheme} to ${themeMode} | ${themeName}`)

if (prevTheme !== themeName) {
// 更换主题时,强制刷新笔记页面
// 更换主题时且没有重载时,提示需要刷新笔记页面
configs.set('prevTheme', themeName);
await configs.save()
window.location.reload()
noticeUI.themeRefreshDialog();
// 如果重载了,这个界面会在onLoadReady时被去掉
}
}

Expand Down
73 changes: 73 additions & 0 deletions src/noticeUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,77 @@ export function showIndev(msg: string = '') {
content: `<div class="b3-dialog__content">${window.bgCoverPlugin.i18n.inDev}<span>${msg}</span></div>`,
width: window.bgCoverPlugin.isMobile ? "92vw" : "520px",
});
}

export function bugReportDialog() {
const dialog = new Dialog({
title: `${window.bgCoverPlugin.i18n.bugReportLabel}`,
content: `
<div class="b3-dialog__content">${window.bgCoverPlugin.i18n.bugReportConfirmText}</div>
<div class="b3-dialog__action">
<button class="b3-button b3-button--cancel">${window.bgCoverPlugin.i18n.cancel}</button><div class="fn__space"></div>
<button class="b3-button b3-button--text">${window.bgCoverPlugin.i18n.confirmBugReport}</button>
</div>
<div class="b3-dialog__action">
`,
width: window.bgCoverPlugin.isMobile ? "92vw" : `520px`,
});

const btnsElement = dialog.element.querySelectorAll(".b3-button");

// cancel button
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
});

// still report
btnsElement[1].addEventListener("click", () => {
window.open('https://github.com/HowcanoeWang/siyuan-plugin-background-cover/issues', '_blank');
dialog.destroy();
});
}

export function themeRefreshDialog() {
const dialog = new Dialog({
title: `${window.bgCoverPlugin.i18n.themeOnChangeTitle}`,
content: `
<div class="b3-dialog__content">${window.bgCoverPlugin.i18n.themeOnChangeMsg}</div>
<div class="b3-dialog__action">
<button class="b3-button b3-button--cancel">${window.bgCoverPlugin.i18n.cancel}</button><div class="fn__space"></div>
<button class="b3-button b3-button--text">${window.bgCoverPlugin.i18n.themeRefresh}</button>
</div>
<div class="b3-dialog__action">
`,
width: window.bgCoverPlugin.isMobile ? "92vw" : `520px`,
});

const btnsElement = dialog.element.querySelectorAll(".b3-button");

// cancel button
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
});

// still report
btnsElement[1].addEventListener("click", () => {
dialog.destroy();
window.location.reload();
});
}

export function removeThemeRefreshDialog(){

let dialog = document.getElementsByClassName('b3-dialog__container')[0];
/**
* 这边必须只能到b3-dialog__container;
* 加载的时候,也会生成一个dialog:直接销毁会导致笔记加载白屏
* 然后用两级追溯parementElement.parenetElement,去获取dialog的Element
* <div class="b3-dialog--open">
* <div class="b3-dialog">
* <div class="b3-dialog__scrim"></div>
* => <div class="b3-dialog__container" ...
*/
if (dialog !== undefined) {
dialog.parentElement.parentElement.remove();
}
}
3 changes: 1 addition & 2 deletions src/topbarUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import BgCoverPlugin from "./index"
import { configs } from './configs';
import * as cst from './constants';
import * as noticeUI from "./noticeUI";
import * as bugreportUI from "./bugreportUI";
import * as settingsUI from "./settingsUI";
import * as fileManagerUI from "./fileManagerUI";
import * as bgRender from "./bgRender";
Expand Down Expand Up @@ -120,7 +119,7 @@ export async function initTopbar(pluginInstance: BgCoverPlugin) {
icon: "iconGithub",
label: `${window.bgCoverPlugin.i18n.bugReportLabel}`,
click: () => {
bugreportUI.bugReportDialog();
noticeUI.bugReportDialog();
}
});
menu.addItem({
Expand Down

0 comments on commit 603b840

Please sign in to comment.