kernel.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SiYuan - Refactor your thinking
  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 main
  17. import (
  18. "C"
  19. "fmt"
  20. "os"
  21. "path/filepath"
  22. "strings"
  23. "time"
  24. "github.com/siyuan-note/filelock"
  25. "github.com/siyuan-note/logging"
  26. "github.com/siyuan-note/siyuan/kernel/cache"
  27. "github.com/siyuan-note/siyuan/kernel/job"
  28. "github.com/siyuan-note/siyuan/kernel/model"
  29. "github.com/siyuan-note/siyuan/kernel/server"
  30. "github.com/siyuan-note/siyuan/kernel/sql"
  31. "github.com/siyuan-note/siyuan/kernel/util"
  32. )
  33. //export StartKernelFast
  34. func StartKernelFast(container, appDir, workspaceBaseDir, localIPs *C.char) {
  35. go server.Serve(true)
  36. }
  37. //export StartKernel
  38. func StartKernel(container, appDir, workspaceBaseDir, timezoneID, localIPs, lang, osVer *C.char) {
  39. SetTimezone(C.GoString(container), C.GoString(appDir), C.GoString(timezoneID))
  40. util.Mode = "prod"
  41. util.MobileOSVer = C.GoString(osVer)
  42. util.LocalIPs = strings.Split(C.GoString(localIPs), ",")
  43. util.BootMobile(C.GoString(container), C.GoString(appDir), C.GoString(workspaceBaseDir), C.GoString(lang))
  44. model.InitConf()
  45. go server.Serve(false)
  46. go func() {
  47. model.InitAppearance()
  48. sql.InitDatabase(false)
  49. sql.InitHistoryDatabase(false)
  50. sql.InitAssetContentDatabase(false)
  51. sql.SetCaseSensitive(model.Conf.Search.CaseSensitive)
  52. sql.SetIndexAssetPath(model.Conf.Search.IndexAssetPath)
  53. model.BootSyncData()
  54. model.InitBoxes()
  55. model.LoadFlashcards()
  56. util.LoadAssetsTexts()
  57. util.SetBooted()
  58. util.PushClearAllMsg()
  59. job.StartCron()
  60. go model.AutoGenerateFileHistory()
  61. go cache.LoadAssets()
  62. }()
  63. }
  64. //export Language
  65. func Language(num int) string {
  66. return model.Conf.Language(num)
  67. }
  68. //export ShowMsg
  69. func ShowMsg(msg string, timeout int) {
  70. util.PushMsg(msg, timeout)
  71. }
  72. //export IsHttpServing
  73. func IsHttpServing() bool {
  74. return util.HttpServing
  75. }
  76. //export SetHttpServerPort
  77. func SetHttpServerPort(port int) {
  78. filelock.AndroidServerPort = port
  79. }
  80. //export GetCurrentWorkspacePath
  81. func GetCurrentWorkspacePath() string {
  82. return util.WorkspaceDir
  83. }
  84. //export GetAssetAbsPath
  85. func GetAssetAbsPath(asset string) (ret string) {
  86. ret, err := model.GetAssetAbsPath(asset)
  87. if err != nil {
  88. logging.LogErrorf("get asset [%s] abs path failed: %s", asset, err)
  89. ret = asset
  90. }
  91. return
  92. }
  93. //export GetMimeTypeByExt
  94. func GetMimeTypeByExt(ext string) string {
  95. return util.GetMimeTypeByExt(ext)
  96. }
  97. //export SetTimezone
  98. func SetTimezone(container, appDir, timezoneID string) {
  99. if "ios" == container {
  100. os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip"))
  101. }
  102. z, err := time.LoadLocation(strings.TrimSpace(timezoneID))
  103. if err != nil {
  104. fmt.Printf("load location failed: %s\n", err)
  105. time.Local = time.FixedZone("CST", 8*3600)
  106. return
  107. }
  108. time.Local = z
  109. }
  110. //export DisableFeature
  111. func DisableFeature(feature *C.char) {
  112. util.DisableFeature(C.GoString(feature))
  113. }
  114. func main() {}