Skip to content

Commit

Permalink
增强内核稳定性 #597
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Mar 27, 2024
1 parent 28484fb commit 3ab2323
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"vue.features.codeActions.enable": false,
"files.associations": {
"*.sy": "json"
}
},
"workbench.editor.wrapTabs": true
}
1 change: 1 addition & 0 deletions app/scripts/genAppIndex.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const T = `<!DOCTYPE html>
<%- ndom.SiYuan.dockBottom %>
<%- ndom.SiYuan.status %>
<%- ndom.Sillot.SillotDrawer %>
<%- ndom.Sillot.SillotOverlay %>
<%- ndom.SiYuan.commonMenu %>
<%- ndom.SiYuan.message %>
<%- ndom.ReactApp.app1 %>
Expand Down
1 change: 1 addition & 0 deletions app/scripts/genAppWindow.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const T = `<!DOCTYPE html>
<%- ndom.SiYuan.status %>
<%- ndom.SiYuan.commonMenu %>
<%- ndom.SiYuan.message %>
<%- ndom.Sillot.SillotOverlay %>
<%- ndom.ReactApp.app1 %>
<%- ndom.ReactApp.app3 %>
<%- ndom.ReactApp.app5 %>
Expand Down
1 change: 1 addition & 0 deletions app/scripts/genDesktopIndex.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const T = `<!DOCTYPE html>
<%- ndom.SiYuan.status %>
<%- ndom.SiYuan.commonMenu %>
<%- ndom.SiYuan.message %>
<%- ndom.Sillot.SillotOverlay %>
<%- ndom.ReactApp.app1 %>
<%- ndom.ReactApp.app3 %>
<%- ndom.ReactApp.app5 %>
Expand Down
1 change: 1 addition & 0 deletions app/scripts/genDockerIndex.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const T = `<!DOCTYPE html>
<%- ndom.SiYuan.status %>
<%- ndom.SiYuan.commonMenu %>
<%- ndom.SiYuan.message %>
<%- ndom.Sillot.SillotOverlay %>
<%- ndom.ReactApp.app1 %>
<%- ndom.ReactApp.app3 %>
<%- ndom.ReactApp.app5 %>
Expand Down
1 change: 1 addition & 0 deletions app/scripts/genMobileIndex.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const T = `<!DOCTYPE html>
<%- ndom.SiYuan.mobile.status %>
<%- ndom.SiYuan.mobile.keyboardToolbar %>
<%- ndom.SiYuan.mobile.sideMask %>
<%- ndom.Sillot.SillotOverlay %>
<%- ndom.ReactApp.app1 %>
<%- ndom.ReactApp.app3 %>
<%- ndom.ReactApp.app5 %>
Expand Down
11 changes: 11 additions & 0 deletions app/scripts/genTPLData.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ exports.default = {
},
Sillot: {
SillotDrawer: /*html*/ `<div id="SillotDrawer" style="position: fixed;bottom: 0;right: 0;z-index: 9999;"></div>`,
SillotOverlay: /*html*/ `<div id="SillotOverlay" style="
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: none;
"></div>
`,
},
ReactApp: {
app1: /*html*/ `<div id="app1" data-bind="react" data-lib="react-toastify"></div>`,
Expand Down
11 changes: 11 additions & 0 deletions app/src/assets/template/app/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
<div id="dockBottom" class="dock fn__none"></div>
<div id="status" class="fn__flex status"></div>
<div id="SillotDrawer" style="position: fixed;bottom: 0;right: 0;z-index: 9999;"></div>
<div id="SillotOverlay" style="
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: none;
"></div>

<div id="commonMenu" class="b3-menu fn__none">
<div class="b3-menu__title fn__none">
<svg class="b3-menu__icon"><use xlink:href="#iconLeft"></use></svg>
Expand Down
11 changes: 11 additions & 0 deletions app/src/assets/template/app/window.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
<div class="b3-menu__items"></div>
</div>
<div id="message" class="b3-snackbars"></div>
<div id="SillotOverlay" style="
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: none;
"></div>

<div id="app1" data-bind="react" data-lib="react-toastify"></div>
<div id="app3" data-bind="react" data-lib="react-hot-toast"></div>
<div id="app5" data-bind="react" data-lib="joyUI"></div>
Expand Down
11 changes: 11 additions & 0 deletions app/src/assets/template/desktop/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
<div class="b3-menu__items"></div>
</div>
<div id="message" class="b3-snackbars"></div>
<div id="SillotOverlay" style="
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: none;
"></div>

<div id="app1" data-bind="react" data-lib="react-toastify"></div>
<div id="app3" data-bind="react" data-lib="react-hot-toast"></div>
<div id="app5" data-bind="react" data-lib="joyUI"></div>
Expand Down
11 changes: 11 additions & 0 deletions app/src/assets/template/mobile/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@
<div id="status" class="status status--hide"></div>
<div id="keyboardToolbar" class="keyboard fn__none"></div>
<div class="side-mask fn__none"></div>
<div id="SillotOverlay" style="
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: none;
"></div>

<div id="app1" data-bind="react" data-lib="react-toastify"></div>
<div id="app3" data-bind="react" data-lib="react-hot-toast"></div>
<div id="app5" data-bind="react" data-lib="joyUI"></div>
Expand Down
22 changes: 2 additions & 20 deletions app/src/dialog/processSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,10 @@ export const kernelError = () => {
}
};

// 在退出时禁用整个 HTML 页面的交互
function disableInteractions() {
// 创建一个遮罩层
const overlay = document.createElement('div');
overlay.style.position = 'fixed';
overlay.style.top = '0';
overlay.style.left = '0';
overlay.style.width = '100%';
overlay.style.height = '100%';
overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
overlay.style.zIndex = '9999'; // 确保在最上层
document.body.appendChild(overlay);

// 禁用遮罩层上的点击事件
overlay.addEventListener('click', (event) => {
event.preventDefault();
event.stopPropagation();
});
}

export const exitSiYuan = () => {
disableInteractions();
const overlay = document.querySelector('#SillotOverlay') as HTMLElement;
overlay.style.display = "block";
exportIDB().then(() => {
hideAllElements(["util"]);
/// #if MOBILE
Expand Down
4 changes: 3 additions & 1 deletion app/src/util/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ export const newDailyNote = (app: App) => {
};

export const mountHelp = () => {
const overlay = document.querySelector('#SillotOverlay') as HTMLElement;
overlay.style.display = "block";
const notebookId = Constants.HELP_PATH[window.siyuan.config.appearance.lang as "zh_CN" | "en_US"];
fetchPost("/api/notebook/removeNotebook", {notebook: notebookId, callback: Constants.CB_MOUNT_REMOVE}, () => {
fetchPost("/api/notebook/openNotebook", {
notebook: notebookId
});
}, () => { const overlay = document.querySelector('#SillotOverlay') as HTMLElement; overlay.style.display = 'none'; });
});
};

Expand Down
7 changes: 5 additions & 2 deletions kernel/api/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
)
Expand Down Expand Up @@ -235,7 +236,7 @@ func resolveFileAnnotationAbsPath(assetRelPath string) (ret string, err error) {
func removeUnusedAsset(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] (API) removeUnusedAsset invoked", c.ClientIP())
arg, ok := util.JsonArg(c, ret)
if !ok {
return
Expand All @@ -246,16 +247,18 @@ func removeUnusedAsset(c *gin.Context) {
ret.Data = map[string]interface{}{
"path": asset,
}
logging.LogDebugf("[%s] (model) removeUnusedAsset invoked", c.ClientIP())
}

func removeUnusedAssets(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] (API) removeUnusedAssets invoked", c.ClientIP())
paths := model.RemoveUnusedAssets()
ret.Data = map[string]interface{}{
"paths": paths,
}
logging.LogDebugf("[%s] (model) removeUnusedAssets invoked", c.ClientIP())
}

func getUnusedAssets(c *gin.Context) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/api/block_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func moveBlock(c *gin.Context) {
if !ok {
return
}
logging.LogDebugf("moveBlock invoked")
logging.LogDebugf("[%s] moveBlock invoked", c.ClientIP())

id := arg["id"].(string)
if util.InvalidIDPattern(id, ret) {
Expand Down
3 changes: 2 additions & 1 deletion kernel/api/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func renameFile(c *gin.Context) {
func removeFile(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] (API) removeFile invoked", c.ClientIP())
arg, ok := util.JsonArg(c, ret)
if !ok {
c.JSON(http.StatusOK, ret)
Expand Down Expand Up @@ -324,6 +324,7 @@ func removeFile(c *gin.Context) {
ret.Msg = err.Error()
return
}
logging.LogDebugf("[%s] (github.com/siyuan-note/filelock) filelock.Remove invoked", c.ClientIP())
}

func putFile(c *gin.Context) {
Expand Down
10 changes: 7 additions & 3 deletions kernel/api/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
Expand Down Expand Up @@ -156,7 +157,7 @@ func upsertIndexes(c *gin.Context) {
func removeIndexes(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] (API) removeIndexes invoked", c.ClientIP())
arg, ok := util.JsonArg(c, ret)
if !ok {
return
Expand All @@ -168,6 +169,7 @@ func removeIndexes(c *gin.Context) {
paths = append(paths, p.(string))
}
model.RemoveIndexes(paths)
logging.LogDebugf("[%s] (model) RemoveIndexes invoked", c.ClientIP())
}

func refreshFiletree(c *gin.Context) {
Expand Down Expand Up @@ -450,7 +452,7 @@ func moveDocs(c *gin.Context) {
func removeDoc(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] (API) removeDoc invoked", c.ClientIP())
arg, ok := util.JsonArg(c, ret)
if !ok {
return
Expand All @@ -463,12 +465,13 @@ func removeDoc(c *gin.Context) {

p := arg["path"].(string)
model.RemoveDoc(notebook, p)
logging.LogDebugf("[%s] (model) removeDoc invoked", c.ClientIP())
}

func removeDocs(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] (API) removeDocs invoked", c.ClientIP())
arg, ok := util.JsonArg(c, ret)
if !ok {
return
Expand All @@ -480,6 +483,7 @@ func removeDocs(c *gin.Context) {
paths = append(paths, path.(string))
}
model.RemoveDocs(paths)
logging.LogDebugf("[%s] (model) RemoveDocs invoked", c.ClientIP())
}

func renameDoc(c *gin.Context) {
Expand Down
12 changes: 8 additions & 4 deletions kernel/api/notebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func renameNotebook(c *gin.Context) {
func removeNotebook(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] removeNotebook invoked", c.ClientIP())
arg, ok := util.JsonArg(c, ret)
if !ok {
return
Expand Down Expand Up @@ -125,6 +125,7 @@ func removeNotebook(c *gin.Context) {
}
evt.Callback = arg["callback"]
util.PushEvent(evt)
logging.LogDebugf("[%s] removeNotebook done", c.ClientIP())
}

func createNotebook(c *gin.Context) {
Expand Down Expand Up @@ -173,7 +174,7 @@ func createNotebook(c *gin.Context) {
func openNotebook(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] openNotebook invoked", c.ClientIP())
arg, ok := util.JsonArg(c, ret)
if !ok {
return
Expand Down Expand Up @@ -216,6 +217,7 @@ func openNotebook(c *gin.Context) {
}
evt.Callback = arg["callback"]
util.PushEvent(evt)
logging.LogDebugf("[%s] openNotebook done", c.ClientIP())
}

func closeNotebook(c *gin.Context) {
Expand Down Expand Up @@ -265,7 +267,7 @@ func getNotebookConf(c *gin.Context) {
func setNotebookConf(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("[%s] (API) setNotebookConf invoked", c.ClientIP())
arg, ok := util.JsonArg(c, ret)
if !ok {
return
Expand Down Expand Up @@ -336,13 +338,14 @@ func setNotebookConf(c *gin.Context) {

box.SaveConf(boxConf)
ret.Data = boxConf
logging.LogDebugf("[%s] (...) setNotebookConf done", c.ClientIP())
}

func lsNotebooks(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

logging.LogDebugf("lsNotebooks invoked")
logging.LogDebugf("[%s] (API) lsNotebooks invoked", c.ClientIP())
flashcard := false

// 兼容旧版接口,不能直接使用 util.JsonArg()
Expand All @@ -359,6 +362,7 @@ func lsNotebooks(c *gin.Context) {
} else {
var err error
notebooks, err = model.ListNotebooks()
logging.LogDebugf("[%s] (model) lsNotebooks done", c.ClientIP())
if nil != err {
logging.LogDebugf("lsNotebooks model.ListNotebooks() failed")
return
Expand Down
1 change: 1 addition & 0 deletions kernel/model/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (box *Box) SaveConf(conf *conf.BoxConf) {
}

func (box *Box) saveConf0(data []byte) {
logging.LogDebugf("(model) saveConf0 invoked")
confPath := filepath.Join(util.DataDir, box.ID, ".siyuan/conf.json") // 这个不要改为 .sillot
if err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, ".siyuan"), 0755); nil != err { // 这个不要改为 .sillot
logging.LogErrorf("save box conf [%s] failed: %s", confPath, err)
Expand Down
2 changes: 1 addition & 1 deletion kernel/util/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func ReportFileSysFatalError(err error) {
lines := strings.Split(output, "\n")
output = strings.Join(lines[5:], "\n")
}
logging.LogErrorf("check file system status failed: %s, %s", err, output)
logging.LogErrorf("check file system status failed: %s [output] %s", err, output)
os.Exit(logging.ExitCodeFileSysErr)
}

Expand Down

0 comments on commit 3ab2323

Please sign in to comment.