diff --git a/kernel/job/cron.go b/kernel/job/cron.go index 7255631f2..eef5d79dc 100644 --- a/kernel/job/cron.go +++ b/kernel/job/cron.go @@ -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()) { diff --git a/kernel/model/shortcuts.go b/kernel/model/shortcuts.go new file mode 100644 index 000000000..6f4527f1e --- /dev/null +++ b/kernel/model/shortcuts.go @@ -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 . + +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) +} diff --git a/kernel/util/working.go b/kernel/util/working.go index c9bea4845..c643a5843 100644 --- a/kernel/util/working.go +++ b/kernel/util/working.go @@ -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) { diff --git a/kernel/util/working_mobile.go b/kernel/util/working_mobile.go index 541b3d055..f7fc0b942 100644 --- a/kernel/util/working_mobile.go +++ b/kernel/util/working_mobile.go @@ -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")