Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-11-23 22:05:43 +08:00
commit ebd09fee77
6 changed files with 45 additions and 12 deletions

View file

@ -330,7 +330,7 @@
"moveToLeft": "向左移",
"moveToRight": "向右移",
"copyProtocol": "複製塊超連結",
"uploadAssets2CDN": "上傳資料檔到雲端",
"uploadAssets2CDN": "上傳資料檔到圖床",
"notSupport1": "不支援跨筆記本進行拖拽",
"keymapTip": "部分快捷鍵修改後需點擊刷新按鈕後才能生效",
"keymapTip2": "使用默認快捷鍵",

View file

@ -330,7 +330,7 @@
"moveToLeft": "向左移",
"moveToRight": "向右移",
"copyProtocol": "复制块超链接",
"uploadAssets2CDN": "上传资源文件到云端",
"uploadAssets2CDN": "上传资源文件到图床",
"notSupport1": "不支持跨笔记本进行拖拽",
"keymapTip": "部分快捷键修改后需点击刷新按钮后才能生效",
"keymapTip2": "使用默认快捷键",

View file

@ -583,10 +583,6 @@ const initKernel = (initData) => {
})
}
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms))
}
const getKernelPort = async () => {
if (isDevEnv) {
return kernelPort
@ -797,15 +793,31 @@ app.on('before-quit', (event) => {
})
const {powerMonitor} = require('electron')
const cp = require("child_process");
powerMonitor.on('suspend', () => {
writeLog('system suspend')
fetch(getServer() + '/api/sync/performSync', {method: 'POST'})
})
powerMonitor.on('resume', () => {
powerMonitor.on('resume', async () => {
writeLog('system resume')
let online = false
for (let i = 0; i < 7; i++) {
if (await isOnline()) {
online = true
break;
}
writeLog("network is offline")
await sleep(1000)
}
if (!online) {
writeLog("network is offline, do not sync after system resume")
return;
}
writeLog("sync after system resume")
// 桌面端系统休眠唤醒后同步延时 7s 后再执行 https://github.com/siyuan-note/siyuan/issues/6687
fetch(getServer() + '/api/sync/performSync', {method: 'POST'})
})
@ -813,3 +825,21 @@ powerMonitor.on('shutdown', () => {
writeLog('system shutdown')
fetch(getServer() + '/api/system/exit', {method: 'POST'})
})
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms))
}
const isOnline = async () => {
try {
const result = await fetch("https://icanhazip.com", {timeout: 1000})
return 200 === result.status
} catch (e) {
try {
const result = await fetch("https://www.baidu.com", {timeout: 1000})
return 200 === result.status
} catch (e) {
return false;
}
}
}

4
app/pnpm-lock.yaml generated
View file

@ -1906,10 +1906,10 @@ packages:
resolution: {integrity: sha512-m0+M53+HYMzqKxwNQZT143K7WwXEGUy9LY31l8dJphXx2P/FQod615mVbxHyqbDCG4J5bHdWm21qZ0e2DVY6CQ==}
engines: {node: '>=14.0.0'}
dependencies:
7zip-bin: 5.1.1
'@develar/schema-utils': 2.6.5
'@electron/universal': 1.2.1
'@malept/flatpak-bundler': 0.4.0
7zip-bin: 5.1.1
async-exit-hook: 2.0.1
bluebird-lst: 1.0.9
builder-util: 23.3.3
@ -2193,9 +2193,9 @@ packages:
/builder-util/23.3.3:
resolution: {integrity: sha512-MJZlUiq2PY5hjYv9+XNaoYdsITqvLgRDoHSFg/4nzpInbNxNjLQOolL04Zsyp+hgfcbFvMC4h0KkR1CMPHLWbA==}
dependencies:
7zip-bin: 5.1.1
'@types/debug': 4.1.7
'@types/fs-extra': 9.0.13
7zip-bin: 5.1.1
app-builder-bin: 4.0.0
bluebird-lst: 1.0.9
builder-util-runtime: 9.0.3

View file

@ -447,7 +447,8 @@ const getExportPath = (option: { type: string, id: string }, removeAssets?: bool
} else if (option.type === "word") {
url = "/api/export/exportDocx";
}
const savePath = result.filePaths[0].endsWith(response.data.rootTitle) ? result.filePaths[0] : path.join(result.filePaths[0], replaceLocalPath(response.data.rootTitle));
let savePath = result.filePaths[0].endsWith(response.data.rootTitle) ? result.filePaths[0] : path.join(result.filePaths[0], replaceLocalPath(response.data.rootTitle));
savePath = savePath.trim();
fetchPost(url, {
id: option.id,
pdf: option.type === "pdf",

View file

@ -244,6 +244,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
tree = exportTree(tree, true, true, false)
name = path.Base(tree.HPath)
name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614
savePath = strings.TrimSpace(savePath)
if err := os.MkdirAll(savePath, 0755); nil != err {
logging.LogErrorf("mkdir [%s] failed: %s", savePath, err)
@ -330,6 +331,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
}
func ExportHTML(id, savePath string, pdf, keepFold bool) (name, dom string) {
savePath = strings.TrimSpace(savePath)
tree, _ := loadTreeByBlockID(id)
var headings []*ast.Node
if pdf { // 导出 PDF 需要标记目录书签