This commit is contained in:
Liang Ding 2023-01-15 00:18:10 +08:00
parent ba8ff1cb31
commit eda9082f82
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D

View File

@ -21,11 +21,13 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"time" "time"
"unicode/utf8" "unicode/utf8"
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/facette/natsort"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/model" "github.com/siyuan-note/siyuan/kernel/model"
@ -130,11 +132,23 @@ func getWorkspaces(c *gin.Context) {
return return
} }
var workspaces []*Workspace var workspaces, openedWorkspaces, closedWorkspaces []*Workspace
for _, p := range workspacePaths { for _, p := range workspacePaths {
closed := !util.IsWorkspaceLocked(p) closed := !util.IsWorkspaceLocked(p)
workspaces = append(workspaces, &Workspace{Path: p, Closed: closed}) if closed {
closedWorkspaces = append(closedWorkspaces, &Workspace{Path: p, Closed: closed})
} else {
openedWorkspaces = append(openedWorkspaces, &Workspace{Path: p, Closed: closed})
}
} }
sort.Slice(openedWorkspaces, func(i, j int) bool {
return natsort.Compare(util.RemoveEmoji(filepath.Base(openedWorkspaces[i].Path)), util.RemoveEmoji(filepath.Base(openedWorkspaces[j].Path)))
})
sort.Slice(closedWorkspaces, func(i, j int) bool {
return natsort.Compare(util.RemoveEmoji(filepath.Base(closedWorkspaces[i].Path)), util.RemoveEmoji(filepath.Base(closedWorkspaces[j].Path)))
})
workspaces = append(workspaces, openedWorkspaces...)
workspaces = append(workspaces, closedWorkspaces...)
ret.Data = workspaces ret.Data = workspaces
} }