mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Supports local shorthands on Android https://github.com/siyuan-note/siyuan/issues/14414
This commit is contained in:
parent
3206d718da
commit
25383ad760
3 changed files with 39 additions and 2 deletions
|
|
@ -44,6 +44,7 @@ func StartCron() {
|
||||||
go every(30*time.Second, model.HookDesktopUIProcJob)
|
go every(30*time.Second, model.HookDesktopUIProcJob)
|
||||||
go every(24*time.Hour, model.AutoPurgeRepoJob)
|
go every(24*time.Hour, model.AutoPurgeRepoJob)
|
||||||
go every(30*time.Minute, model.AutoCheckMicrosoftDefender)
|
go every(30*time.Minute, model.AutoCheckMicrosoftDefender)
|
||||||
|
go every(3*time.Second, model.WatchLocalShorthands)
|
||||||
}
|
}
|
||||||
|
|
||||||
func every(interval time.Duration, f func()) {
|
func every(interval time.Duration, f func()) {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func MoveLocalShorthands(boxID, hPath, parentID, id string) (retID string, err e
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := os.ReadDir(shorthandsDir)
|
entries, err := os.ReadDir(shorthandsDir)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("read dir [%s] failed: %s", shorthandsDir, err)
|
logging.LogErrorf("read dir [%s] failed: %s", shorthandsDir, err)
|
||||||
return
|
return
|
||||||
|
|
@ -41,7 +41,7 @@ func MoveLocalShorthands(boxID, hPath, parentID, id string) (retID string, err e
|
||||||
|
|
||||||
buff := bytes.Buffer{}
|
buff := bytes.Buffer{}
|
||||||
var toRemoves []string
|
var toRemoves []string
|
||||||
for _, entry := range dir {
|
for _, entry := range entries {
|
||||||
if entry.IsDir() {
|
if entry.IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -88,3 +88,35 @@ func MoveLocalShorthands(boxID, hPath, parentID, id string) (retID string, err e
|
||||||
clearShorthand(toRemoves)
|
clearShorthand(toRemoves)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WatchLocalShorthands() {
|
||||||
|
shorthandsDir := filepath.Join(util.ShortcutsPath, "shorthands")
|
||||||
|
if !gulu.File.IsDir(shorthandsDir) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := os.ReadDir(shorthandsDir)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("read dir [%s] failed: %s", shorthandsDir, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
shorthandCount := 0
|
||||||
|
for _, entry := range entries {
|
||||||
|
if entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if filepath.Ext(entry.Name()) != ".md" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
shorthandCount++
|
||||||
|
}
|
||||||
|
|
||||||
|
if 1 > shorthandCount {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
util.PushLocalShorthandCount(shorthandCount)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -275,6 +275,10 @@ func PushSetDefRefCount(rootID, blockID string, defIDs []string, refCount, rootR
|
||||||
BroadcastByType("main", "setDefRefCount", 0, "", map[string]interface{}{"rootID": rootID, "blockID": blockID, "refCount": refCount, "rootRefCount": rootRefCount, "defIDs": defIDs})
|
BroadcastByType("main", "setDefRefCount", 0, "", map[string]interface{}{"rootID": rootID, "blockID": blockID, "refCount": refCount, "rootRefCount": rootRefCount, "defIDs": defIDs})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PushLocalShorthandCount(count int) {
|
||||||
|
BroadcastByType("main", "setLocalShorthandCount", 0, "", map[string]interface{}{"count": count})
|
||||||
|
}
|
||||||
|
|
||||||
func PushProtyleLoading(rootID, msg string) {
|
func PushProtyleLoading(rootID, msg string) {
|
||||||
BroadcastByType("protyle", "addLoading", 0, msg, rootID)
|
BroadcastByType("protyle", "addLoading", 0, msg, rootID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue