|
@@ -17,9 +17,11 @@
|
|
package util
|
|
package util
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "log"
|
|
"math/rand"
|
|
"math/rand"
|
|
"os"
|
|
"os"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
+ "strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"github.com/88250/gulu"
|
|
"github.com/88250/gulu"
|
|
@@ -28,47 +30,110 @@ import (
|
|
"github.com/siyuan-note/logging"
|
|
"github.com/siyuan-note/logging"
|
|
)
|
|
)
|
|
|
|
|
|
-func BootMobile(container, appDir, workspaceDir, nativeLibDir, privateDataDir, lang string) {
|
|
|
|
|
|
+func BootMobile(container, appDir, workspaceBaseDir, lang string) {
|
|
IncBootProgress(3, "Booting...")
|
|
IncBootProgress(3, "Booting...")
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
initMime()
|
|
initMime()
|
|
initHttpClient()
|
|
initHttpClient()
|
|
|
|
+ ServerPort = FixedPort
|
|
|
|
+ Container = container
|
|
|
|
+ UserAgent = UserAgent + " " + Container
|
|
|
|
+ httpclient.SetUserAgent(UserAgent)
|
|
|
|
+ Lang = lang
|
|
|
|
|
|
- HomeDir = filepath.Join(workspaceDir, "home")
|
|
|
|
|
|
+ WorkingDir = filepath.Join(appDir, "app")
|
|
|
|
+ HomeDir = filepath.Join(workspaceBaseDir, "home")
|
|
userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
|
|
userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
|
|
if !gulu.File.IsExist(userHomeConfDir) {
|
|
if !gulu.File.IsExist(userHomeConfDir) {
|
|
os.MkdirAll(userHomeConfDir, 0755)
|
|
os.MkdirAll(userHomeConfDir, 0755)
|
|
}
|
|
}
|
|
- WorkingDir = filepath.Join(appDir, "app")
|
|
|
|
- WorkspaceDir = workspaceDir
|
|
|
|
- ConfDir = filepath.Join(workspaceDir, "conf")
|
|
|
|
- DataDir = filepath.Join(workspaceDir, "data")
|
|
|
|
- HistoryDir = filepath.Join(workspaceDir, "history")
|
|
|
|
|
|
+
|
|
|
|
+ initWorkspaceDirMobile(workspaceBaseDir)
|
|
|
|
+
|
|
|
|
+ initPathDir()
|
|
|
|
+ bootBanner := figure.NewFigure("SiYuan", "", true)
|
|
|
|
+ logging.LogInfof("\n" + bootBanner.String())
|
|
|
|
+ logBootInfo()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func initWorkspaceDirMobile(workspaceBaseDir string) {
|
|
|
|
+ userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
|
|
|
|
+ workspaceConf := filepath.Join(userHomeConfDir, "workspace.json")
|
|
|
|
+ if !gulu.File.IsExist(workspaceConf) {
|
|
|
|
+ if err := os.MkdirAll(userHomeConfDir, 0755); nil != err && !os.IsExist(err) {
|
|
|
|
+ log.Printf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
|
|
|
|
+ os.Exit(ExitCodeCreateConfDirErr)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ defaultWorkspaceDir := filepath.Join(workspaceBaseDir, "siyuan")
|
|
|
|
+ var workspacePaths []string
|
|
|
|
+ if !gulu.File.IsExist(workspaceConf) {
|
|
|
|
+ WorkspaceDir = defaultWorkspaceDir
|
|
|
|
+ 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)
|
|
|
|
+ } else {
|
|
|
|
+ data, err := os.ReadFile(workspaceConf)
|
|
|
|
+ if err = gulu.JSON.UnmarshalJSON(data, &workspacePaths); nil != err {
|
|
|
|
+ log.Printf("unmarshal workspace conf [%s] failed: %s", workspaceConf, err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var tmp []string
|
|
|
|
+ for _, d := range workspacePaths {
|
|
|
|
+ d = strings.TrimRight(d, " \t\n") // 去掉工作空间路径尾部空格 https://github.com/siyuan-note/siyuan/issues/6353
|
|
|
|
+ if gulu.File.IsDir(d) {
|
|
|
|
+ tmp = append(tmp, d)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ workspacePaths = tmp
|
|
|
|
+
|
|
|
|
+ if 0 < len(workspacePaths) {
|
|
|
|
+ WorkspaceDir = workspacePaths[len(workspacePaths)-1]
|
|
|
|
+ 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[len(workspacePaths)-1] = WorkspaceDir
|
|
|
|
+ } else {
|
|
|
|
+ WorkspaceDir = defaultWorkspaceDir
|
|
|
|
+ workspacePaths = append(workspacePaths, WorkspaceDir)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if data, err := gulu.JSON.MarshalJSON(workspacePaths); nil == err {
|
|
|
|
+ if err = os.WriteFile(workspaceConf, data, 0644); nil != err {
|
|
|
|
+ log.Fatalf("write workspace conf [%s] failed: %s", workspaceConf, err)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.Fatalf("marshal workspace conf [%s] failed: %s", workspaceConf, err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ConfDir = filepath.Join(WorkspaceDir, "conf")
|
|
|
|
+ DataDir = filepath.Join(WorkspaceDir, "data")
|
|
RepoDir = filepath.Join(WorkspaceDir, "repo")
|
|
RepoDir = filepath.Join(WorkspaceDir, "repo")
|
|
- TempDir = filepath.Join(workspaceDir, "temp")
|
|
|
|
|
|
+ HistoryDir = filepath.Join(WorkspaceDir, "history")
|
|
|
|
+ TempDir = filepath.Join(WorkspaceDir, "temp")
|
|
osTmpDir := filepath.Join(TempDir, "os")
|
|
osTmpDir := filepath.Join(TempDir, "os")
|
|
os.RemoveAll(osTmpDir)
|
|
os.RemoveAll(osTmpDir)
|
|
- os.MkdirAll(osTmpDir, 0755)
|
|
|
|
|
|
+ if err := os.MkdirAll(osTmpDir, 0755); nil != err {
|
|
|
|
+ log.Fatalf("create os tmp dir [%s] failed: %s", osTmpDir, err)
|
|
|
|
+ }
|
|
os.RemoveAll(filepath.Join(TempDir, "repo"))
|
|
os.RemoveAll(filepath.Join(TempDir, "repo"))
|
|
os.Setenv("TMPDIR", osTmpDir)
|
|
os.Setenv("TMPDIR", osTmpDir)
|
|
|
|
+ os.Setenv("TEMP", osTmpDir)
|
|
|
|
+ os.Setenv("TMP", osTmpDir)
|
|
DBPath = filepath.Join(TempDir, DBName)
|
|
DBPath = filepath.Join(TempDir, DBName)
|
|
HistoryDBPath = filepath.Join(TempDir, "history.db")
|
|
HistoryDBPath = filepath.Join(TempDir, "history.db")
|
|
BlockTreePath = filepath.Join(TempDir, "blocktree.msgpack")
|
|
BlockTreePath = filepath.Join(TempDir, "blocktree.msgpack")
|
|
- AndroidNativeLibDir = nativeLibDir
|
|
|
|
- AndroidPrivateDataDir = privateDataDir
|
|
|
|
- LogPath = filepath.Join(TempDir, "siyuan.log")
|
|
|
|
- logging.SetLogPath(LogPath)
|
|
|
|
|
|
+ SnippetsPath = filepath.Join(DataDir, "snippets")
|
|
|
|
+
|
|
AppearancePath = filepath.Join(ConfDir, "appearance")
|
|
AppearancePath = filepath.Join(ConfDir, "appearance")
|
|
ThemesPath = filepath.Join(AppearancePath, "themes")
|
|
ThemesPath = filepath.Join(AppearancePath, "themes")
|
|
IconsPath = filepath.Join(AppearancePath, "icons")
|
|
IconsPath = filepath.Join(AppearancePath, "icons")
|
|
- SnippetsPath = filepath.Join(DataDir, "snippets")
|
|
|
|
- ServerPort = FixedPort
|
|
|
|
- Container = container
|
|
|
|
- UserAgent = UserAgent + " " + Container
|
|
|
|
- httpclient.SetUserAgent(UserAgent)
|
|
|
|
- Lang = lang
|
|
|
|
- initPathDir()
|
|
|
|
- bootBanner := figure.NewFigure("SiYuan", "", true)
|
|
|
|
- logging.LogInfof("\n" + bootBanner.String())
|
|
|
|
- logBootInfo()
|
|
|
|
|
|
+
|
|
|
|
+ LogPath = filepath.Join(TempDir, "siyuan.log")
|
|
|
|
+ logging.SetLogPath(LogPath)
|
|
}
|
|
}
|