mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 桌面端系统休眠唤醒后判断网络连通性后再执行数据同步 Fix https://github.com/siyuan-note/siyuan/issues/6687
This commit is contained in:
parent
3cc4ad6bff
commit
2217f92df5
2 changed files with 34 additions and 9 deletions
|
|
@ -583,10 +583,6 @@ const initKernel = (initData) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const sleep = (ms) => {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, ms))
|
|
||||||
}
|
|
||||||
|
|
||||||
const getKernelPort = async () => {
|
const getKernelPort = async () => {
|
||||||
if (isDevEnv) {
|
if (isDevEnv) {
|
||||||
return kernelPort
|
return kernelPort
|
||||||
|
|
@ -797,15 +793,31 @@ app.on('before-quit', (event) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const {powerMonitor} = require('electron')
|
const {powerMonitor} = require('electron')
|
||||||
const cp = require("child_process");
|
|
||||||
|
|
||||||
powerMonitor.on('suspend', () => {
|
powerMonitor.on('suspend', () => {
|
||||||
writeLog('system suspend')
|
writeLog('system suspend')
|
||||||
fetch(getServer() + '/api/sync/performSync', {method: 'POST'})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
powerMonitor.on('resume', () => {
|
powerMonitor.on('resume', async () => {
|
||||||
writeLog('system resume')
|
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'})
|
fetch(getServer() + '/api/sync/performSync', {method: 'POST'})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -813,3 +825,16 @@ powerMonitor.on('shutdown', () => {
|
||||||
writeLog('system shutdown')
|
writeLog('system shutdown')
|
||||||
fetch(getServer() + '/api/system/exit', {method: 'POST'})
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
4
app/pnpm-lock.yaml
generated
4
app/pnpm-lock.yaml
generated
|
|
@ -1906,10 +1906,10 @@ packages:
|
||||||
resolution: {integrity: sha512-m0+M53+HYMzqKxwNQZT143K7WwXEGUy9LY31l8dJphXx2P/FQod615mVbxHyqbDCG4J5bHdWm21qZ0e2DVY6CQ==}
|
resolution: {integrity: sha512-m0+M53+HYMzqKxwNQZT143K7WwXEGUy9LY31l8dJphXx2P/FQod615mVbxHyqbDCG4J5bHdWm21qZ0e2DVY6CQ==}
|
||||||
engines: {node: '>=14.0.0'}
|
engines: {node: '>=14.0.0'}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
7zip-bin: 5.1.1
|
||||||
'@develar/schema-utils': 2.6.5
|
'@develar/schema-utils': 2.6.5
|
||||||
'@electron/universal': 1.2.1
|
'@electron/universal': 1.2.1
|
||||||
'@malept/flatpak-bundler': 0.4.0
|
'@malept/flatpak-bundler': 0.4.0
|
||||||
7zip-bin: 5.1.1
|
|
||||||
async-exit-hook: 2.0.1
|
async-exit-hook: 2.0.1
|
||||||
bluebird-lst: 1.0.9
|
bluebird-lst: 1.0.9
|
||||||
builder-util: 23.3.3
|
builder-util: 23.3.3
|
||||||
|
|
@ -2193,9 +2193,9 @@ packages:
|
||||||
/builder-util/23.3.3:
|
/builder-util/23.3.3:
|
||||||
resolution: {integrity: sha512-MJZlUiq2PY5hjYv9+XNaoYdsITqvLgRDoHSFg/4nzpInbNxNjLQOolL04Zsyp+hgfcbFvMC4h0KkR1CMPHLWbA==}
|
resolution: {integrity: sha512-MJZlUiq2PY5hjYv9+XNaoYdsITqvLgRDoHSFg/4nzpInbNxNjLQOolL04Zsyp+hgfcbFvMC4h0KkR1CMPHLWbA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
7zip-bin: 5.1.1
|
||||||
'@types/debug': 4.1.7
|
'@types/debug': 4.1.7
|
||||||
'@types/fs-extra': 9.0.13
|
'@types/fs-extra': 9.0.13
|
||||||
7zip-bin: 5.1.1
|
|
||||||
app-builder-bin: 4.0.0
|
app-builder-bin: 4.0.0
|
||||||
bluebird-lst: 1.0.9
|
bluebird-lst: 1.0.9
|
||||||
builder-util-runtime: 9.0.3
|
builder-util-runtime: 9.0.3
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue