mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-29 21:08:49 +01:00
🎨 系统公告消息提醒 Fix https://github.com/siyuan-note/siyuan/issues/5409
This commit is contained in:
parent
d1fb78ebb1
commit
f825fefa43
8 changed files with 96 additions and 22 deletions
|
|
@ -21,6 +21,8 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -150,6 +152,8 @@ func AutoRefreshUser() {
|
|||
if !subscriptionExpirationReminded {
|
||||
subscriptionExpirationReminded = true
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
if "ios" == util.Container {
|
||||
return
|
||||
}
|
||||
|
|
@ -170,13 +174,65 @@ func AutoRefreshUser() {
|
|||
}()
|
||||
}
|
||||
|
||||
if nil != Conf.User {
|
||||
time.Sleep(3 * time.Minute)
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
if nil != Conf.User {
|
||||
RefreshUser(Conf.User.UserToken)
|
||||
time.Sleep(3 * time.Minute)
|
||||
if nil != Conf.User {
|
||||
RefreshUser(Conf.User.UserToken)
|
||||
}
|
||||
subscriptionExpirationReminded = false
|
||||
}
|
||||
subscriptionExpirationReminded = false
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
|
||||
time.Sleep(1 * time.Minute)
|
||||
announcementConf := filepath.Join(util.HomeDir, ".config", "siyuan", "announcement.json")
|
||||
var existingAnnouncements, newAnnouncements []*Announcement
|
||||
if gulu.File.IsExist(announcementConf) {
|
||||
data, err := os.ReadFile(announcementConf)
|
||||
if nil != err {
|
||||
util.LogErrorf("read announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &existingAnnouncements); nil != err {
|
||||
util.LogErrorf("unmarshal announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, announcement := range GetAnnouncements() {
|
||||
var exist bool
|
||||
for _, existingAnnouncement := range existingAnnouncements {
|
||||
if announcement.Id == existingAnnouncement.Id {
|
||||
exist = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exist {
|
||||
existingAnnouncements = append(existingAnnouncements, announcement)
|
||||
newAnnouncements = append(newAnnouncements, announcement)
|
||||
}
|
||||
}
|
||||
|
||||
data, err := gulu.JSON.MarshalJSON(existingAnnouncements)
|
||||
if nil != err {
|
||||
util.LogErrorf("marshal announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = os.WriteFile(announcementConf, data, 0644); nil != err {
|
||||
util.LogErrorf("write announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, newAnnouncement := range newAnnouncements {
|
||||
util.PushMsg(fmt.Sprintf(Conf.Language(11), newAnnouncement.URL, newAnnouncement.Title), 0)
|
||||
}
|
||||
}()
|
||||
|
||||
<-refreshUserTicker.C
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,15 +27,33 @@ var (
|
|||
checkUpdateLock = &sync.Mutex{}
|
||||
)
|
||||
|
||||
func CheckUpdate(showMsg bool) {
|
||||
if !showMsg {
|
||||
type Announcement struct {
|
||||
Id string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func GetAnnouncements() (ret []*Announcement) {
|
||||
result, err := util.GetRhyResult(false)
|
||||
if nil != err {
|
||||
util.LogErrorf("get ")
|
||||
return
|
||||
}
|
||||
|
||||
if "ios" == util.Container {
|
||||
if showMsg {
|
||||
util.PushMsg(Conf.Language(36), 5000)
|
||||
}
|
||||
announcements := result["announcement"].([]interface{})
|
||||
for _, announcement := range announcements {
|
||||
ann := announcement.(map[string]interface{})
|
||||
ret = append(ret, &Announcement{
|
||||
Id: ann["id"].(string),
|
||||
Title: ann["title"].(string),
|
||||
URL: ann["url"].(string),
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func CheckUpdate(showMsg bool) {
|
||||
if !showMsg {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue