kernel.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SiYuan - Build Your Eternal Digital Garden
  2. // Copyright (c) 2020-present, b3log.org
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. package mobile
  17. import (
  18. "fmt"
  19. "os"
  20. "path/filepath"
  21. "strings"
  22. "time"
  23. "github.com/siyuan-note/siyuan/kernel/cache"
  24. "github.com/siyuan-note/siyuan/kernel/model"
  25. "github.com/siyuan-note/siyuan/kernel/server"
  26. "github.com/siyuan-note/siyuan/kernel/sql"
  27. "github.com/siyuan-note/siyuan/kernel/treenode"
  28. "github.com/siyuan-note/siyuan/kernel/util"
  29. _ "golang.org/x/mobile/bind"
  30. )
  31. func StartKernelFast(container, appDir, workspaceDir, nativeLibDir, privateDataDir, localIP string) {
  32. go server.Serve(true)
  33. }
  34. func StartKernel(container, appDir, workspaceDir, nativeLibDir, privateDataDir, timezoneID, localIPs, lang string) {
  35. SetTimezone(container, appDir, timezoneID)
  36. util.Mode = "prod"
  37. util.LocalIPs = strings.Split(localIPs, ",")
  38. util.BootMobile(container, appDir, workspaceDir, nativeLibDir, privateDataDir, lang)
  39. model.InitConf()
  40. go server.Serve(false)
  41. go func() {
  42. model.InitAppearance()
  43. sql.InitDatabase(false)
  44. sql.InitHistoryDatabase(false)
  45. sql.SetCaseSensitive(model.Conf.Search.CaseSensitive)
  46. model.SyncData(true, false, false)
  47. model.InitBoxes()
  48. go model.AutoGenerateDocHistory()
  49. go model.AutoSync()
  50. go model.AutoStat()
  51. util.SetBooted()
  52. util.ClearPushProgress(100)
  53. go model.AutoRefreshUser()
  54. go model.AutoFlushTx()
  55. go sql.AutoFlushTreeQueue()
  56. go treenode.AutoFlushBlockTree()
  57. go cache.LoadAssets()
  58. }()
  59. }
  60. func Language(num int) string {
  61. return model.Conf.Language(num)
  62. }
  63. func ShowMsg(msg string, timeout int) {
  64. util.PushMsg(msg, timeout)
  65. }
  66. func IsHttpServing() bool {
  67. return util.HttpServing
  68. }
  69. func SetTimezone(container, appDir, timezoneID string) {
  70. if "ios" == container {
  71. os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip"))
  72. }
  73. z, err := time.LoadLocation(strings.TrimSpace(timezoneID))
  74. if err != nil {
  75. fmt.Printf("load location failed: %s\n", err)
  76. time.Local = time.FixedZone("CST", 8*3600)
  77. return
  78. }
  79. time.Local = z
  80. }