A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
1// SiYuan - Refactor your thinking
2// Copyright (c) 2020-present, b3log.org
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Affero General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Affero General Public License for more details.
13//
14// You should have received a copy of the GNU Affero General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17//go:build darwin
18
19package model
20
21import (
22 "path/filepath"
23 "time"
24
25 "github.com/radovskyb/watcher"
26 "github.com/siyuan-note/logging"
27 "github.com/siyuan-note/siyuan/kernel/util"
28)
29
30var emojisWatcher *watcher.Watcher
31
32func WatchEmojis() {
33 go func() {
34 watchEmojis()
35 }()
36}
37
38func watchEmojis() {
39 if nil != emojisWatcher {
40 emojisWatcher.Close()
41 }
42 emojisWatcher = watcher.New()
43
44 emojisDir := filepath.Join(util.DataDir, "emojis")
45
46 go func() {
47 for {
48 select {
49 case _, ok := <-emojisWatcher.Event:
50 if !ok {
51 return
52 }
53 util.PushReloadEmojiConf()
54 case err, ok := <-emojisWatcher.Error:
55 if !ok {
56 return
57 }
58 logging.LogErrorf("watch emojis failed: %s", err)
59 case <-emojisWatcher.Closed:
60 return
61 }
62 }
63 }()
64
65 if err := emojisWatcher.Add(emojisDir); err != nil {
66 logging.LogErrorf("add emojis watcher for folder [%s] failed: %s", emojisDir, err)
67 return
68 }
69
70 //logging.LogInfof("added file watcher [%s]", emojisDir)
71 if err := emojisWatcher.Start(10 * time.Second); err != nil {
72 logging.LogErrorf("start emojis watcher for folder [%s] failed: %s", emojisDir, err)
73 return
74 }
75}
76
77func CloseWatchEmojis() {
78 if nil != emojisWatcher {
79 emojisWatcher.Close()
80 }
81}