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

This commit is contained in:
Vanessa 2023-01-06 19:46:41 +08:00
commit 278fa18aee
4 changed files with 61 additions and 9 deletions

View File

@ -53,10 +53,8 @@ try {
} }
} catch (e) { } catch (e) {
console.error(e) console.error(e)
require('electron'). require('electron').dialog.showErrorBox('创建配置目录失败 Failed to create config directory',
dialog. '思源需要在用户家目录下创建配置文件夹(~/.config/siyuan请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.')
showErrorBox('创建配置目录失败 Failed to create config directory',
'思源需要在用户家目录下创建配置文件夹(~/.config/siyuan请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.')
app.exit() app.exit()
} }
@ -889,6 +887,7 @@ app.on('before-quit', (event) => {
}) })
const {powerMonitor} = require('electron') const {powerMonitor} = require('electron')
const {write} = require("fs");
powerMonitor.on('suspend', () => { powerMonitor.on('suspend', () => {
writeLog('system suspend') writeLog('system suspend')
@ -926,11 +925,11 @@ powerMonitor.on('resume', async () => {
return return
} }
writeLog('sync after system resume')
workspaces.forEach(item => { workspaces.forEach(item => {
const currentURL = new URL(item.browserWindow.getURL()) const currentURL = new URL(item.browserWindow.getURL())
fetch(getServer(currentURL.port) + '/api/sync/performSync', const server = getServer(currentURL.port)
{method: 'POST'}) writeLog('sync after system resume [' + server + '/api/sync/performSync' + ']')
fetch(server + '/api/sync/performSync', {method: 'POST'})
}) })
}) })
@ -938,6 +937,6 @@ powerMonitor.on('shutdown', () => {
writeLog('system shutdown') writeLog('system shutdown')
workspaces.forEach(item => { workspaces.forEach(item => {
const currentURL = new URL(item.browserWindow.getURL()) const currentURL = new URL(item.browserWindow.getURL())
fetch(getServer(currentURL.port) + '/api/system/exit', {method: 'POST'}) fetch(getServer(currentURL.port) + '/api/system/exit', {method: 'POST'})
}) })
}) })

View File

@ -51,6 +51,7 @@ func main() {
go sql.AutoFlushTreeQueue() go sql.AutoFlushTreeQueue()
go treenode.AutoFlushBlockTree() go treenode.AutoFlushBlockTree()
go cache.LoadAssets() go cache.LoadAssets()
go model.HookDesktopUIProc()
model.WatchAssets() model.WatchAssets()
model.HandleSignal() model.HandleSignal()
} }

View File

@ -675,7 +675,6 @@ func clearWorkspaceTemp() {
os.RemoveAll(filepath.Join(util.TempDir, "import")) os.RemoveAll(filepath.Join(util.TempDir, "import"))
os.RemoveAll(filepath.Join(util.TempDir, "repo")) os.RemoveAll(filepath.Join(util.TempDir, "repo"))
os.RemoveAll(filepath.Join(util.TempDir, "os")) os.RemoveAll(filepath.Join(util.TempDir, "os"))
os.RemoveAll(filepath.Join(util.DataDir, "assets", ".siyuan", "assets.json"))
// 退出时自动删除超过 7 天的安装包 https://github.com/siyuan-note/siyuan/issues/6128 // 退出时自动删除超过 7 天的安装包 https://github.com/siyuan-note/siyuan/issues/6128
install := filepath.Join(util.TempDir, "install") install := filepath.Join(util.TempDir, "install")
@ -720,5 +719,10 @@ func clearWorkspaceTemp() {
} }
} }
// 老版本遗留文件清理
os.RemoveAll(filepath.Join(util.DataDir, "assets", ".siyuan", "assets.json"))
os.RemoveAll(filepath.Join(util.WorkspaceDir, "backup"))
os.RemoveAll(filepath.Join(util.WorkspaceDir, "sync"))
logging.LogInfof("cleared workspace temp") logging.LogInfof("cleared workspace temp")
} }

View File

@ -19,9 +19,14 @@ package model
import ( import (
"os" "os"
"os/signal" "os/signal"
"strconv"
"strings"
"syscall" "syscall"
"time"
goPS "github.com/mitchellh/go-ps"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
) )
func HandleSignal() { func HandleSignal() {
@ -31,3 +36,46 @@ func HandleSignal() {
logging.LogInfof("received os signal [%s], exit kernel process now", s) logging.LogInfof("received os signal [%s], exit kernel process now", s)
Close(false, 1) Close(false, 1)
} }
func HookDesktopUIProc() {
if util.ContainerStd != util.Container || "dev" == util.Mode {
return
}
time.Sleep(30 * time.Second)
uiProcNames := []string{"siyuan", "electron"}
existUIProc := false
for range time.Tick(7 * time.Second) {
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
if nil != err {
logging.LogErrorf("invalid UI proc ID [%s]: %s", uiProcIDArg, err)
return true
}
proc, err := goPS.FindProcess(uiProcID)
if nil != err {
logging.LogErrorf("find UI proc [%d] failed: %s", uiProcID, err)
return true
}
if nil == proc {
return true
}
procName := strings.ToLower(proc.Executable())
for _, name := range uiProcNames {
if strings.Contains(procName, name) {
existUIProc = true
return false
}
}
return true
})
if !existUIProc {
logging.LogInfof("no active UI proc, exit kernel process now")
Close(false, 1)
}
}
}