From 5de2ac66ff43c4ca05aba9a80aeb3b8bfa867751 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 18 Nov 2024 20:49:03 +0800 Subject: [PATCH 1/3] :art: Support HarmonyOS NEXT system https://github.com/siyuan-note/siyuan/issues/13184 --- kernel/harmony/build-win.sh | 7 +++ kernel/harmony/build.sh | 7 +++ kernel/harmony/kernel.go | 120 ++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 kernel/harmony/build-win.sh create mode 100644 kernel/harmony/build.sh create mode 100644 kernel/harmony/kernel.go diff --git a/kernel/harmony/build-win.sh b/kernel/harmony/build-win.sh new file mode 100644 index 000000000..5d6c2d513 --- /dev/null +++ b/kernel/harmony/build-win.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export CGO_ENABLED=1 +export GOOS=android +export GOARCH=amd64 +export CC=/mnt/f/ohos-sdk-windows_linux-public/linux/native/llvm/bin/x86_64-unknown-linux-ohos-clang +go build --tags fts5 -ldflags "-s -w" -buildmode=c-shared -v -o libkernel.so . diff --git a/kernel/harmony/build.sh b/kernel/harmony/build.sh new file mode 100644 index 000000000..f7e3aaabc --- /dev/null +++ b/kernel/harmony/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export CGO_ENABLED=1 +export GOOS=android +export GOARCH=arm64 +export CC=/mnt/f/ohos-sdk-windows_linux-public/linux/native/llvm/bin/aarch64-unknown-linux-ohos-clang +go build --tags fts5 -ldflags "-s -w" -buildmode=c-shared -v -o libkernel.so . diff --git a/kernel/harmony/kernel.go b/kernel/harmony/kernel.go new file mode 100644 index 000000000..39dbf81dc --- /dev/null +++ b/kernel/harmony/kernel.go @@ -0,0 +1,120 @@ +// SiYuan - Refactor your thinking +// Copyright (c) 2020-present, b3log.org +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package main + +import ( + "C" + "fmt" + "os" + "path/filepath" + "strings" + "time" + + "github.com/siyuan-note/filelock" + "github.com/siyuan-note/logging" + "github.com/siyuan-note/siyuan/kernel/cache" + "github.com/siyuan-note/siyuan/kernel/job" + "github.com/siyuan-note/siyuan/kernel/model" + "github.com/siyuan-note/siyuan/kernel/server" + "github.com/siyuan-note/siyuan/kernel/sql" + "github.com/siyuan-note/siyuan/kernel/util" +) + +func StartKernelFast(container, appDir, workspaceBaseDir, localIPs string) { + go server.Serve(true) +} + +func StartKernel(container, appDir, workspaceBaseDir, timezoneID, localIPs, lang, osVer string) { + SetTimezone(container, appDir, timezoneID) + util.Mode = "prod" + util.MobileOSVer = osVer + util.LocalIPs = strings.Split(localIPs, ",") + util.BootMobile(container, appDir, workspaceBaseDir, lang) + + model.InitConf() + go server.Serve(false) + go func() { + model.InitAppearance() + sql.InitDatabase(false) + sql.InitHistoryDatabase(false) + sql.InitAssetContentDatabase(false) + sql.SetCaseSensitive(model.Conf.Search.CaseSensitive) + sql.SetIndexAssetPath(model.Conf.Search.IndexAssetPath) + + model.BootSyncData() + model.InitBoxes() + model.LoadFlashcards() + util.LoadAssetsTexts() + + util.SetBooted() + util.PushClearAllMsg() + + job.StartCron() + go model.AutoGenerateFileHistory() + go cache.LoadAssets() + }() +} + +func Language(num int) string { + return model.Conf.Language(num) +} + +func ShowMsg(msg string, timeout int) { + util.PushMsg(msg, timeout) +} + +func IsHttpServing() bool { + return util.HttpServing +} + +func SetHttpServerPort(port int) { + filelock.AndroidServerPort = port +} + +func GetCurrentWorkspacePath() string { + return util.WorkspaceDir +} + +func GetAssetAbsPath(asset string) (ret string) { + ret, err := model.GetAssetAbsPath(asset) + if err != nil { + logging.LogErrorf("get asset [%s] abs path failed: %s", asset, err) + ret = asset + } + return +} + +func GetMimeTypeByExt(ext string) string { + return util.GetMimeTypeByExt(ext) +} + +func SetTimezone(container, appDir, timezoneID string) { + if "ios" == container { + os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip")) + } + z, err := time.LoadLocation(strings.TrimSpace(timezoneID)) + if err != nil { + fmt.Printf("load location failed: %s\n", err) + time.Local = time.FixedZone("CST", 8*3600) + return + } + time.Local = z +} + +func DisableFeature(feature string) { + util.DisableFeature(feature) +} From adc4d13f12f6797fff6eb25153d7b9a07731f7a3 Mon Sep 17 00:00:00 2001 From: Liang Ding <845765@qq.com> Date: Mon, 18 Nov 2024 20:52:59 +0800 Subject: [PATCH 2/3] :art: Support HarmonyOS NEXT system https://github.com/siyuan-note/siyuan/issues/13184 --- kernel/harmony/build-win.sh | 0 kernel/harmony/build.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 kernel/harmony/build-win.sh mode change 100644 => 100755 kernel/harmony/build.sh diff --git a/kernel/harmony/build-win.sh b/kernel/harmony/build-win.sh old mode 100644 new mode 100755 diff --git a/kernel/harmony/build.sh b/kernel/harmony/build.sh old mode 100644 new mode 100755 From ce9ae722c4582be6306af577beb62c77f726ef4d Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 18 Nov 2024 21:53:12 +0800 Subject: [PATCH 3/3] :art: Support HarmonyOS NEXT system https://github.com/siyuan-note/siyuan/issues/13184 --- kernel/harmony/build-win.sh | 1 + kernel/harmony/build.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/kernel/harmony/build-win.sh b/kernel/harmony/build-win.sh index 5d6c2d513..fc3b15d32 100755 --- a/kernel/harmony/build-win.sh +++ b/kernel/harmony/build-win.sh @@ -1,5 +1,6 @@ #!/bin/bash +export GOPROXY=https://goproxy.io export CGO_ENABLED=1 export GOOS=android export GOARCH=amd64 diff --git a/kernel/harmony/build.sh b/kernel/harmony/build.sh index f7e3aaabc..a1c3c9569 100755 --- a/kernel/harmony/build.sh +++ b/kernel/harmony/build.sh @@ -1,5 +1,6 @@ #!/bin/bash +export GOPROXY=https://goproxy.io export CGO_ENABLED=1 export GOOS=android export GOARCH=arm64