From b72b832007ee60e688e89ad7e2a4a86a8e63e37c Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 19 Mar 2024 23:11:44 +0800 Subject: [PATCH] :bug: Can't switch workspaces on mobile app Fix https://github.com/siyuan-note/siyuan/issues/10654 --- kernel/api/system.go | 2 +- kernel/api/workspace.go | 2 +- kernel/model/conf.go | 24 ++++++++++++++---------- kernel/model/process.go | 4 ++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/kernel/api/system.go b/kernel/api/system.go index 05dac8c73..0606bef38 100644 --- a/kernel/api/system.go +++ b/kernel/api/system.go @@ -490,7 +490,7 @@ func exit(c *gin.Context) { execInstallPkg = int(execInstallPkgArg.(float64)) } - exitCode := model.Close(force, execInstallPkg) + exitCode := model.Close(force, true, execInstallPkg) ret.Code = exitCode switch exitCode { case 0: diff --git a/kernel/api/workspace.go b/kernel/api/workspace.go index bdda877c3..9e5d18652 100644 --- a/kernel/api/workspace.go +++ b/kernel/api/workspace.go @@ -312,7 +312,7 @@ func setWorkspaceDir(c *gin.Context) { if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container { util.PushMsg(model.Conf.Language(42), 1000*15) time.Sleep(time.Second * 2) - model.Close(false, 1) + model.Close(false, false, 1) } } diff --git a/kernel/model/conf.go b/kernel/model/conf.go index 2ee3ffc74..a26d66e95 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -527,6 +527,8 @@ var exitLock = sync.Mutex{} // // force:是否不执行同步过程而直接退出 // +// setCurrentWorkspace:是否将当前工作空间放到工作空间列表的最后一个 +// // execInstallPkg:是否执行新版本安装包 // // 0:默认按照设置项 System.DownloadInstallPkg 检查并推送提示 @@ -540,7 +542,7 @@ var exitLock = sync.Mutex{} // 2:提示新安装包 // // 当 force 为 true(强制退出)并且 execInstallPkg 为 0(默认检查更新)并且同步失败并且新版本安装版已经准备就绪时,执行新版本安装 https://github.com/siyuan-note/siyuan/issues/10288 -func Close(force bool, execInstallPkg int) (exitCode int) { +func Close(force, setCurrentWorkspace bool, execInstallPkg int) (exitCode int) { exitLock.Lock() defer exitLock.Unlock() @@ -588,15 +590,17 @@ func Close(force bool, execInstallPkg int) (exitCode int) { clearCorruptedNotebooks() clearPortJSON() - // 将当前工作空间放到工作空间列表的最后一个 - // Open the last workspace by default https://github.com/siyuan-note/siyuan/issues/10570 - workspacePaths, err := util.ReadWorkspacePaths() - if nil != err { - logging.LogErrorf("read workspace paths failed: %s", err) - } else { - workspacePaths = gulu.Str.RemoveElem(workspacePaths, util.WorkspaceDir) - workspacePaths = append(workspacePaths, util.WorkspaceDir) - util.WriteWorkspacePaths(workspacePaths) + if setCurrentWorkspace { + // 将当前工作空间放到工作空间列表的最后一个 + // Open the last workspace by default https://github.com/siyuan-note/siyuan/issues/10570 + workspacePaths, err := util.ReadWorkspacePaths() + if nil != err { + logging.LogErrorf("read workspace paths failed: %s", err) + } else { + workspacePaths = gulu.Str.RemoveElem(workspacePaths, util.WorkspaceDir) + workspacePaths = append(workspacePaths, util.WorkspaceDir) + util.WriteWorkspacePaths(workspacePaths) + } } util.UnlockWorkspace() diff --git a/kernel/model/process.go b/kernel/model/process.go index bc5140859..ac618231f 100644 --- a/kernel/model/process.go +++ b/kernel/model/process.go @@ -34,7 +34,7 @@ func HandleSignal() { signal.Notify(c, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) s := <-c logging.LogInfof("received os signal [%s], exit kernel process now", s) - Close(false, 1) + Close(false, true, 1) } var ( @@ -78,7 +78,7 @@ func HookDesktopUIProcJob() { } logging.LogWarnf("confirmed no active UI proc, exit kernel process now") - Close(false, 1) + Close(false, true, 1) } var uiProcNames = []string{"siyuan", "electron"}