📝 Supports append text by shortcuts to the dailynote doc on Android https://github.com/siyuan-note/siyuan/issues/14414

This commit is contained in:
Daniel 2025-03-24 23:31:05 +08:00
parent 5c0273d0c2
commit 54ec99a199
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
4 changed files with 83 additions and 0 deletions

View File

@ -44,6 +44,7 @@ func StartCron() {
go every(30*time.Second, model.HookDesktopUIProcJob)
go every(24*time.Hour, model.AutoPurgeRepoJob)
go every(30*time.Minute, model.AutoCheckMicrosoftDefender)
go every(7*time.Second, model.ShortcutsAppendToDailynote)
}
func every(interval time.Duration, f func()) {

79
kernel/model/shortcuts.go Normal file
View File

@ -0,0 +1,79 @@
// SiYuan - Refactor your thinking
// Copyright (c) 2020-present, b3log.org
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package model
import (
"bytes"
"os"
"path/filepath"
"github.com/88250/gulu"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
)
func ShortcutsAppendToDailynote() {
dailynotesDir := filepath.Join(util.ShortcutsPath, "dailynotes")
if !gulu.File.IsDir(dailynotesDir) {
return
}
dir, err := os.ReadDir(dailynotesDir)
if nil != err {
logging.LogErrorf("read dir [%s] failed: %s", dailynotesDir, err)
return
}
buff := bytes.Buffer{}
var toRemoves []string
for _, entry := range dir {
if entry.IsDir() {
continue
}
if filepath.Ext(entry.Name()) != ".md" {
continue
}
p := filepath.Join(dailynotesDir, entry.Name())
data, readErr := os.ReadFile(p)
if nil != readErr {
logging.LogErrorf("read file [%s] failed: %s", p, readErr)
continue
}
buff.Write(bytes.TrimSpace(data))
buff.WriteString("\n\n")
logging.LogInfof("read dailynote [%s] content [%s]", p, data)
toRemoves = append(toRemoves, p)
}
defer func() {
for _, p := range toRemoves {
if err := os.Remove(p); nil != err {
logging.LogErrorf("remove file [%s] failed: %s", p, err)
}
}
}()
content := buff.String()
if 1 > len(content) {
return
}
logging.LogInfof("append dailynote content [%s]", content)
}

View File

@ -246,6 +246,7 @@ var (
ThemesPath string // 配置目录下的外观目录下的 themes/ 路径
IconsPath string // 配置目录下的外观目录下的 icons/ 路径
SnippetsPath string // 数据目录下的 snippets/ 路径
ShortcutsPath string // 用户家目录下的快捷方式目录路径 home/.config/siyuan/shortcuts/
UIProcessIDs = sync.Map{} // UI 进程 ID
)
@ -322,6 +323,7 @@ func initWorkspaceDir(workspaceArg string) {
AssetContentDBPath = filepath.Join(TempDir, "asset_content.db")
BlockTreeDBPath = filepath.Join(TempDir, "blocktree.db")
SnippetsPath = filepath.Join(DataDir, "snippets")
ShortcutsPath = filepath.Join(userHomeConfDir, "shortcuts")
}
func ReadWorkspacePaths() (ret []string, err error) {

View File

@ -164,6 +164,7 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
AssetContentDBPath = filepath.Join(TempDir, "asset_content.db")
BlockTreeDBPath = filepath.Join(TempDir, "blocktree.db")
SnippetsPath = filepath.Join(DataDir, "snippets")
ShortcutsPath = filepath.Join(userHomeConfDir, "shortcuts")
AppearancePath = filepath.Join(ConfDir, "appearance")
ThemesPath = filepath.Join(AppearancePath, "themes")