mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-07 21:22:34 +01:00
🎨 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:
parent
656e676c8b
commit
b8ee424d26
4 changed files with 2 additions and 76 deletions
|
|
@ -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") ||
|
||||
|
|
|
|||
4
app/src/types/index.d.ts
vendored
4
app/src/types/index.d.ts
vendored
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue