Files
YumeMichi 91bbc7f607 Add Android control app and embedded server
Inspired by HNKServer/honoka-chan-apk-server, but implemented as a JNI-based embedded runtime instead of the original approach.

- Add an Android Compose controller app that starts and stops honoka-chan through JNI, shows runtime and health status, manages data directory mounting, and supports backup import/export for data.db
- Add an embeddable Go server entrypoint plus JNI-exported status, health, and reload hooks so desktop and Android builds share the same startup and shutdown path
- Add Android build scripts, runtime packaging, and project documentation, including generated default config.json content for honoka_runtime.zip
- Add runtime bundle hash tracking so updated honoka_runtime.zip assets are automatically redeployed while preserving config.json and user data files
- Add in-app service settings for unlock_all_special_rotation with immediate config persistence and automatic reload when the service is running
- Split SQLite driver selection by platform, using go-sqlite3 on Android and modernc.org/sqlite elsewhere to avoid Android x86_64 seccomp crashes
- Update startup, database initialization, and system health/reload handlers to support the embedded runtime and Android control flow

Signed-off-by: Sean Du <do4suki@gmail.com>
2026-06-12 19:17:21 +08:00

77 lines
1.6 KiB
Go

package config
import (
"encoding/json"
"honoka-chan/pkg/utils"
"os"
"strconv"
"time"
)
var (
Conf = &AppConfigs{}
PackageVersion = "97.4.6"
ConfigPath = "./config.json"
PrivateKeyPath = "assets/certs/privatekey.pem"
PublicKeyPath = "assets/certs/publickey.pem"
)
type AppConfigs struct {
AppName string `json:"app_name"`
Settings Settings `json:"settings"`
}
type Settings struct {
ListenPort string `json:"listen_port"`
CdnServer string `json:"cdn_server"`
ReloadToken string `json:"reload_token"`
UnlockAllSpecialRotation bool `json:"unlock_all_special_rotation"`
}
func InitConfig() {
ReloadConfig()
}
func ReloadConfig() *AppConfigs {
Conf = Load(ConfigPath)
return Conf
}
func DefaultConfigs() *AppConfigs {
return &AppConfigs{
AppName: "honoka-chan",
Settings: Settings{
ListenPort: "8080",
CdnServer: "http://127.0.0.1:8080/static",
ReloadToken: "",
UnlockAllSpecialRotation: false,
},
}
}
func Load(p string) *AppConfigs {
if !utils.PathExists(p) {
_ = DefaultConfigs().Save(p)
}
c := AppConfigs{}
err := json.Unmarshal([]byte(utils.ReadAllText(p)), &c)
if err != nil {
_ = os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10))
_ = DefaultConfigs().Save(p)
}
c = AppConfigs{}
_ = json.Unmarshal([]byte(utils.ReadAllText(p)), &c)
return &c
}
func (c *AppConfigs) Save(p string) error {
data, err := json.MarshalIndent(c, "", " ")
if err != nil {
return err
}
utils.WriteAllText(p, string(data)+"\n")
return nil
}