A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
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
17package main
18
19import (
20 "C"
21 "fmt"
22 "os"
23 "path/filepath"
24 "strings"
25 "time"
26
27 "github.com/88250/gulu"
28 "github.com/siyuan-note/filelock"
29 "github.com/siyuan-note/logging"
30 "github.com/siyuan-note/siyuan/kernel/cache"
31 "github.com/siyuan-note/siyuan/kernel/job"
32 "github.com/siyuan-note/siyuan/kernel/model"
33 "github.com/siyuan-note/siyuan/kernel/server"
34 "github.com/siyuan-note/siyuan/kernel/sql"
35 "github.com/siyuan-note/siyuan/kernel/util"
36)
37
38//export StartKernelFast
39func StartKernelFast(container, appDir, workspaceBaseDir, localIPs *C.char) {
40 go server.Serve(true)
41}
42
43//export StartKernel
44func StartKernel(container, appDir, workspaceBaseDir, timezoneID, localIPs, lang, osVer *C.char) {
45 SetTimezone(C.GoString(container), C.GoString(appDir), C.GoString(timezoneID))
46 util.Mode = "prod"
47 util.MobileOSVer = C.GoString(osVer)
48 util.LocalIPs = strings.Split(C.GoString(localIPs), ",")
49 util.BootMobile(C.GoString(container), C.GoString(appDir), C.GoString(workspaceBaseDir), C.GoString(lang))
50
51 model.InitConf()
52 go server.Serve(false)
53 go func() {
54 model.InitAppearance()
55 sql.InitDatabase(false)
56 sql.InitHistoryDatabase(false)
57 sql.InitAssetContentDatabase(false)
58 sql.SetCaseSensitive(model.Conf.Search.CaseSensitive)
59 sql.SetIndexAssetPath(model.Conf.Search.IndexAssetPath)
60
61 model.BootSyncData()
62 model.InitBoxes()
63 model.LoadFlashcards()
64 util.LoadAssetsTexts()
65
66 util.SetBooted()
67 util.PushClearAllMsg()
68
69 job.StartCron()
70 go model.AutoGenerateFileHistory()
71 go cache.LoadAssets()
72 }()
73}
74
75//export Language
76func Language(num int) string {
77 return model.Conf.Language(num)
78}
79
80//export ShowMsg
81func ShowMsg(msg string, timeout int) {
82 util.PushMsg(msg, timeout)
83}
84
85//export IsHttpServing
86func IsHttpServing() bool {
87 return util.HttpServing
88}
89
90//export SetHttpServerPort
91func SetHttpServerPort(port int) {
92 filelock.AndroidServerPort = port
93}
94
95//export GetCurrentWorkspacePath
96func GetCurrentWorkspacePath() *C.char {
97 return C.CString(util.WorkspaceDir)
98}
99
100//export GetAssetAbsPath
101func GetAssetAbsPath(relativePath *C.char) *C.char {
102 absPath, err := model.GetAssetAbsPath(C.GoString(relativePath))
103 if nil != err {
104 logging.LogErrorf("get asset abs path failed: %s", err)
105 return relativePath
106 }
107 return C.CString(absPath)
108}
109
110//export GetMimeTypeByExt
111func GetMimeTypeByExt(ext string) string {
112 return util.GetMimeTypeByExt(ext)
113}
114
115//export SetTimezone
116func SetTimezone(container, appDir, timezoneID string) {
117 if "ios" == container {
118 os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip"))
119 }
120 z, err := time.LoadLocation(strings.TrimSpace(timezoneID))
121 if err != nil {
122 fmt.Printf("load location failed: %s\n", err)
123 time.Local = time.FixedZone("CST", 8*3600)
124 return
125 }
126 time.Local = z
127}
128
129//export DisableFeature
130func DisableFeature(feature *C.char) {
131 util.DisableFeature(C.GoString(feature))
132}
133
134//export Unzip
135func Unzip(zipFilePath, destination *C.char) {
136 if err := gulu.Zip.Unzip(C.GoString(zipFilePath), C.GoString(destination)); nil != err {
137 logging.LogErrorf("unzip [%s] failed: %s", zipFilePath, err)
138 }
139}
140
141func main() {}