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