kernel.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.BootSyncData()
  47. model.InitBoxes()
  48. model.InitFlashcards()
  49. go model.AutoGenerateDocHistory()
  50. go model.AutoSync()
  51. go model.AutoStat()
  52. util.SetBooted()
  53. util.ClearPushProgress(100)
  54. go model.AutoRefreshCheck()
  55. go model.AutoFlushTx()
  56. go sql.AutoFlushTreeQueue()
  57. go treenode.AutoFlushBlockTree()
  58. go cache.LoadAssets()
  59. }()
  60. }
  61. func Language(num int) string {
  62. return model.Conf.Language(num)
  63. }
  64. func ShowMsg(msg string, timeout int) {
  65. util.PushMsg(msg, timeout)
  66. }
  67. func IsHttpServing() bool {
  68. return util.HttpServing
  69. }
  70. func SetTimezone(container, appDir, timezoneID string) {
  71. if "ios" == container {
  72. os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip"))
  73. }
  74. z, err := time.LoadLocation(strings.TrimSpace(timezoneID))
  75. if err != nil {
  76. fmt.Printf("load location failed: %s\n", err)
  77. time.Local = time.FixedZone("CST", 8*3600)
  78. return
  79. }
  80. time.Local = z
  81. }