mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 05:09:26 +08:00
📝 Supports append text by shortcuts to the dailynote doc on Android https://github.com/siyuan-note/siyuan/issues/14414
This commit is contained in:
parent
5c0273d0c2
commit
54ec99a199
@ -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
79
kernel/model/shortcuts.go
Normal 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)
|
||||
}
|
@ -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) {
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user