From 6b298f3f24ece03849b405a1a052042bc2a9e02f Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 14 Jan 2023 11:13:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:art:=20=E6=A1=8C=E9=9D=A2=E7=AB=AF?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E6=96=B9=E5=BC=8F=E5=B7=A5=E4=BD=9C=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E5=8F=82=E6=95=B0=20`--workspace`=20=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=20Fix=20https://github.com/siyuan-note/siyuan/issues/?= =?UTF-8?q?7070?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/electron/main.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/electron/main.js b/app/electron/main.js index 5bc1f9cba..8f0f921c9 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -52,10 +52,8 @@ try { } } catch (e) { console.error(e) - require('electron'). - dialog. - 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.') + require('electron').dialog.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() } @@ -901,12 +899,17 @@ app.on('second-instance', (event, argv) => { }) return } + const siyuanURL = argv.find((arg) => arg.startsWith('siyuan://')) workspaces.forEach(item => { if (item.browserWindow && !item.browserWindow.isDestroyed() && siyuanURL) { item.browserWindow.webContents.send('siyuan-openurl', siyuanURL) } }) + + if (!siyuanURL && 0 < workspaces.length) { + showWindow(workspaces[0].browserWindow) + } }) app.on('activate', () => { From d7577ffb61c73f5cda2a3d4f8eb7bbac3291f8d1 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 14 Jan 2023 11:26:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:bug:=20=E5=A4=9A=E4=B8=AA=E6=A1=8C?= =?UTF-8?q?=E9=9D=A2=E7=AB=AF=E5=BF=AB=E6=8D=B7=E6=96=B9=E5=BC=8F=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E4=B8=8D=E5=90=8C=E7=9A=84=20`--workspace`=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=90=8E=E6=97=A0=E6=B3=95=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4=20https:?= =?UTF-8?q?//github.com/siyuan-note/siyuan/issues/7059?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/util/working.go | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/kernel/util/working.go b/kernel/util/working.go index d0136e279..f49a8accc 100644 --- a/kernel/util/working.go +++ b/kernel/util/working.go @@ -212,36 +212,26 @@ func initWorkspaceDir(workspaceArg string) { if "" != workspaceArg { WorkspaceDir = workspaceArg } - if !gulu.File.IsDir(WorkspaceDir) { - log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", defaultWorkspaceDir, WorkspaceDir) - WorkspaceDir = defaultWorkspaceDir - } - workspacePaths = append(workspacePaths, WorkspaceDir) } else { workspacePaths, _ = ReadWorkspacePaths() if 0 < len(workspacePaths) { + // 取最后一个(也就是最近打开的)工作空间 WorkspaceDir = workspacePaths[len(workspacePaths)-1] - if "" != workspaceArg { - WorkspaceDir = workspaceArg - } - if !gulu.File.IsDir(WorkspaceDir) { - log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir) - WorkspaceDir = defaultWorkspaceDir - } - workspacePaths[len(workspacePaths)-1] = WorkspaceDir } else { WorkspaceDir = defaultWorkspaceDir - if "" != workspaceArg { - WorkspaceDir = workspaceArg - } - if !gulu.File.IsDir(WorkspaceDir) { - log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir) - WorkspaceDir = defaultWorkspaceDir - } - workspacePaths = append(workspacePaths, WorkspaceDir) + } + + if "" != workspaceArg { + WorkspaceDir = workspaceArg } } + if !gulu.File.IsDir(WorkspaceDir) { + log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir) + WorkspaceDir = defaultWorkspaceDir + } + workspacePaths = append(workspacePaths, WorkspaceDir) + if err := WriteWorkspacePaths(workspacePaths); nil != err { log.Fatalf("write workspace conf [%s] failed: %s", workspaceConf, err) } @@ -284,8 +274,6 @@ func ReadWorkspacePaths() (ret []string, err error) { return } - ret = gulu.Str.RemoveDuplicatedElem(ret) - var tmp []string for _, d := range ret { d = strings.TrimRight(d, " \t\n") // 去掉工作空间路径尾部空格 https://github.com/siyuan-note/siyuan/issues/6353 @@ -294,6 +282,7 @@ func ReadWorkspacePaths() (ret []string, err error) { } } ret = tmp + ret = gulu.Str.RemoveDuplicatedElem(ret) return }