Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 桌面端系统休眠唤醒后判断网络连通性后再执行数据同步 Fix https://github.com/siyuan-note/siyuan/issues/6687

Liang Ding2217f92df570
diff --git a/app/electron/main.js b/app/electron/main.js
index fb27463d85..c154859edb 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -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,16 @@ 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) {
+ return false;
+ }
+}
diff --git a/app/pnpm-lock.yaml b/app/pnpm-lock.yaml
index 1223b8de6b..7192390486 100644
--- a/app/pnpm-lock.yaml
+++ b/app/pnpm-lock.yaml
@@ -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