Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/17863#issuecomment-4714055684

Daniel96d77f229f10
diff --git a/app/electron/main.js b/app/electron/main.js
index a6b4ae56bf..bc0accbf08 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -621,7 +621,7 @@ const initKernel = (workspace, port, lang) => {
resolve(false);
return;
}
- const cmds = ["--port", kernelPort, "--wd", appDir];
+ const cmds = ["--port", kernelPort, "--wd", appDir, "--attach-ui"];
if (isDevEnv && workspaces.length === 0) {
cmds.push("--mode", "dev");
}
diff --git a/kernel/model/process.go b/kernel/model/process.go
index f95322374c..297e02d032 100644
--- a/kernel/model/process.go
+++ b/kernel/model/process.go
@@ -42,7 +42,7 @@ var (
)
func HookDesktopUIProcJob() {
- if util.ContainerStd != util.Container || "dev" == util.Mode {
+ if !util.AttachUI || util.ContainerStd != util.Container || "dev" == util.Mode {
return
}
diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go
index c5c8e25ea4..6d680be0af 100644
--- a/kernel/util/runtime.go
+++ b/kernel/util/runtime.go
@@ -117,8 +117,10 @@ func logBootInfo() {
if ghw.DriveTypeSSD.String() != driveType {
logging.LogWarnf("workspace dir [%s] is not in SSD drive, performance may be affected", WorkspaceDir)
- WaitForUILoaded()
- time.Sleep(3 * time.Second)
+ if AttachUI {
+ WaitForUILoaded()
+ time.Sleep(3 * time.Second)
+ }
PushErrMsg(Langs[Lang][278], 15000)
}
}()
diff --git a/kernel/util/working.go b/kernel/util/working.go
index d7fa27cc9b..c837661fd1 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -51,6 +51,7 @@ const (
var (
RunInContainer = false // 是否运行在容器中
SiYuanAccessAuthCodeBypass = false // 是否跳过空锁屏密码检查
+ AttachUI = false // 是否绑定桌面 UI 进程生命周期(Electron 拉起时为 true,手动 serve 为 false)
)
func initEnvVars() {
@@ -119,6 +120,7 @@ func Boot() {
readOnly := flag.String("readonly", "false", "read-only mode")
accessAuthCode := flag.String("accessAuthCode", "", "access auth code")
ssl := flag.Bool("ssl", false, "for https and wss")
+ attachUI := flag.Bool("attach-ui", false, "attach kernel lifecycle to desktop UI process (used by Electron)")
lang := flag.String("lang", "", "ar/de/en/es/fr/he/hi/id/it/ja/ko/nl/pl/pt-BR/ru/sk/th/tr/uk/zh-CN/zh-TW")
mode := flag.String("mode", "prod", "dev/prod")
flag.Parse()
@@ -136,6 +138,7 @@ func Boot() {
Mode = *mode
ServerPort = *port
ReadOnly, _ = strconv.ParseBool(*readOnly)
+ AttachUI = *attachUI
AccessAuthCode = *accessAuthCode
AccessAuthCode = RemoveInvalid(AccessAuthCode)
AccessAuthCode = strings.TrimSpace(AccessAuthCode)