🎨 Support sending notifications on HarmonyOS https://github.com/siyuan-note/siyuan/issues/17125

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-03-05 23:44:55 +08:00
parent 656e676c8b
commit b8ee424d26
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 2 additions and 76 deletions

View file

@ -23,15 +23,6 @@ export const onMessage = (app: App, data: IWebSocketData) => {
switch (data.cmd) {
case "logoutAuth":
redirectToCheckAuth();
break;
case "sendDeviceNotification":
if (window.JSAndroid.sendNotification) {
window.JSAndroid.sendNotification(data.data.channel, data.data.id, data.data.title, data.data.body, data.data.delayInSeconds);
}
if (window.JSHarmony.sendNotification) {
window.JSHarmony.sendNotification(data.data.channel, data.data.id, data.data.title, data.data.body, data.data.delayInSeconds);
}
break;
case "backgroundtask":
if (!document.querySelector("#keyboardToolbar").classList.contains("fn__none") ||

View file

@ -255,7 +255,7 @@ interface Window {
getScreenWidthPx(): number
exit(): void
setWebViewFocusable(enable: boolean): void
sendNotification(channel: string, id: number, title: string, body: string, delayInSeconds: number): number
sendNotification(channel: string, title: string, body: string, delayInSeconds: number): number
cancelNotification(id: number): void
};
JSHarmony: {
@ -275,7 +275,7 @@ interface Window {
getScreenWidthPx(): number
exit(): void
setWebViewFocusable(enable: boolean): void
sendNotification(channel: string, id: number, title: string, body: string, delayInSeconds: number): void
sendNotification(channel: string, title: string, body: string, delayInSeconds: number): number
cancelNotification(id: number): void
};

View file

@ -19,76 +19,12 @@ package api
import (
"net/http"
"strings"
"time"
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/util"
)
func sendDeviceNotification(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
if util.ContainerAndroid != util.Container && util.ContainerHarmony != util.Container {
ret.Code = -1
ret.Msg = "Just support Android and HarmonyOS"
return
}
var channel string
if nil != arg["channel"] {
channel = strings.TrimSpace(arg["channel"].(string))
} else {
channel = "SiYuan Notifications"
}
var id int
if nil != arg["id"] {
id = int(arg["id"].(float64))
} else {
id = int(time.Now().Unix())
}
var title string
if nil != arg["title"] {
title = strings.TrimSpace(arg["title"].(string))
} else {
ret.Code = -1
ret.Msg = "title can't be empty"
return
}
var body string
if nil != arg["body"] {
body = strings.TrimSpace(arg["body"].(string))
} else {
ret.Code = -1
ret.Msg = "body can't be empty"
return
}
var delayInSeconds int
if nil != arg["delayInSeconds"] {
delayInSeconds = int(arg["delayInSeconds"].(float64))
} else {
delayInSeconds = 1
}
util.BroadcastByType("main", "sendDeviceNotification", 0, "", map[string]interface{}{
"channel": channel,
"id": id,
"title": title,
"body": body,
"delayInSeconds": delayInSeconds,
})
}
func pushMsg(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -458,7 +458,6 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, model.CheckAdminRole, pushMsg)
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, model.CheckAdminRole, pushErrMsg)
ginServer.Handle("POST", "/api/notification/sendDeviceNotification", model.CheckAuth, model.CheckAdminRole, sendDeviceNotification)
ginServer.Handle("POST", "/api/snippet/getSnippet", model.CheckAuth, getSnippet)
ginServer.Handle("POST", "/api/snippet/setSnippet", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setSnippet)