@@ -16,7 +16,7 @@ const { replaceArk } = require("./main_modules/replaceArk");
16
16
const { debounce } = require ( "./main_modules/debounce" ) ;
17
17
const { log } = require ( "./main_modules/log" ) ;
18
18
19
- let mainMessage , recordMessageRecallIdList , messageRecallPath , messageRecallJson ;
19
+ let mainMessage , recordMessageRecallIdList , messageRecallPath , messageRecallJson , localEmoticonsPath ;
20
20
21
21
const listenList = [ ] ; // 所有打开过的窗口对象
22
22
const catchMsgList = new LimitedMap ( 2000 ) ; // 内存缓存消息记录-用于根据消息id获取撤回原始内容
@@ -30,7 +30,6 @@ let options, localEmoticonsConfig; // 配置数据
30
30
function onLoad ( plugin ) {
31
31
const pluginDataPath = plugin . path . data ;
32
32
const settingsPath = path . join ( pluginDataPath , "settings.json" ) ;
33
- const localEmoticonsPath = path . join ( pluginDataPath , "localEmoticonsConfig.json" ) ;
34
33
const styleSassPath = path . join ( plugin . path . plugin , "src/style.scss" ) ;
35
34
const stylePath = path . join ( plugin . path . plugin , "src/style.css" ) ;
36
35
const globalScssPath = path . join ( plugin . path . plugin , "src/global.scss" ) ;
@@ -39,6 +38,7 @@ function onLoad(plugin) {
39
38
const settingPath = path . join ( plugin . path . plugin , "src/config/view.css" ) ;
40
39
messageRecallPath = path . join ( pluginDataPath , "/messageRecall" ) ;
41
40
messageRecallJson = path . join ( pluginDataPath , "/messageRecall/latestRecallMessage.json" ) ;
41
+ localEmoticonsPath = path . join ( pluginDataPath , "localEmoticonsConfig.json" ) ;
42
42
43
43
// 初始化配置文件路径
44
44
if ( ! fs . existsSync ( pluginDataPath ) ) {
@@ -126,18 +126,11 @@ function onLoad(plugin) {
126
126
log (
127
127
"%c轻量工具箱已加载" ,
128
128
"border-radius: 8px;padding:10px 20px;font-size:18px;background:linear-gradient(to right, #3f7fe8, #03ddf2);color:#fff;" ,
129
- plugin ,
130
129
) ;
131
130
132
131
// 监听本地表情包文件夹内的更新
133
132
onUpdateEmoticons ( ( emoticonsList ) => {
134
133
console . log ( "本地表情包更新" , emoticonsList . length ) ;
135
- if ( options . localEmoticons . commonlyEmoticons ) {
136
- emoticonsList . unshift ( {
137
- name : "常用表情" ,
138
- list : localEmoticonsConfig . commonlyEmoticons ,
139
- } ) ;
140
- }
141
134
globalBroadcast ( listenList , "LiteLoader.lite_tools.updateEmoticons" , emoticonsList ) ;
142
135
localEmoticonsList = emoticonsList ;
143
136
} ) ;
@@ -164,6 +157,7 @@ function onLoad(plugin) {
164
157
// 返回本地表情包数据
165
158
ipcMain . handle ( "LiteLoader.lite_tools.getLocalEmoticonsList" , ( event ) => {
166
159
log ( "返回本地表情包数据" ) ;
160
+ globalBroadcast ( listenList , "LiteLoader.lite_tools.updateLocalEmoticonsConfig" , localEmoticonsConfig ) ;
167
161
return localEmoticonsList ;
168
162
} ) ;
169
163
@@ -217,6 +211,12 @@ function onLoad(plugin) {
217
211
resetCommonlyEmoticons ( ) ; // 重置常用表情
218
212
loadEmoticons ( opt . localEmoticons . localPath ) ;
219
213
}
214
+ // 判断是否开启了常用表情
215
+ if ( opt . localEmoticons . commonlyEmoticons ) {
216
+ globalBroadcast ( listenList , "LiteLoader.lite_tools.updateLocalEmoticonsConfig" , localEmoticonsConfig ) ;
217
+ } else {
218
+ globalBroadcast ( listenList , "LiteLoader.lite_tools.updateLocalEmoticonsConfig" , { commonlyEmoticons : [ ] } ) ;
219
+ }
220
220
}
221
221
options = opt ;
222
222
fs . writeFileSync ( settingsPath , JSON . stringify ( options , null , 4 ) ) ;
@@ -234,6 +234,9 @@ function onLoad(plugin) {
234
234
log ( "%c轻量工具箱 [渲染进程]: " , "background:#272829;color:#fff;" , ...message ) ;
235
235
} ) ;
236
236
237
+ // 更新常用表情列表
238
+ ipcMain . on ( "LiteLoader.lite_tools.addCommonlyEmoticons" , addCommonlyEmoticons ) ;
239
+
237
240
// 获取全局样式
238
241
ipcMain . handle ( "LiteLoader.lite_tools.getGlobalStyle" , ( event ) => {
239
242
try {
@@ -331,7 +334,7 @@ function onBrowserWindowCreated(window, plugin) {
331
334
// 监听页面加载完成事件
332
335
window . webContents . on ( "did-stop-loading" , ( ) => {
333
336
if ( window . webContents . getURL ( ) . indexOf ( "#/main/message" ) !== - 1 ) {
334
- log ( "捕获到主窗口" , window ) ;
337
+ log ( "捕获到主窗口" ) ;
335
338
mainMessage = window ;
336
339
}
337
340
} ) ;
@@ -401,7 +404,7 @@ function onBrowserWindowCreated(window, plugin) {
401
404
// 捕获消息列表
402
405
const msgList = args [ 1 ] ?. msgList ;
403
406
if ( msgList && msgList . length ) {
404
- log ( "解析到消息数据" , msgList ) ;
407
+ log ( "解析到消息数据" ) ;
405
408
// 遍历消息列表中的所有消息
406
409
if ( options . message . showMsgTime || options . message . convertMiniPrgmArk || options . message . preventMessageRecall ) {
407
410
msgList . forEach ( ( msgItem , index ) => {
@@ -630,7 +633,7 @@ function onBrowserWindowCreated(window, plugin) {
630
633
}
631
634
}
632
635
}
633
- // 记录下可能会用到的时间名称
636
+ // 记录下可能会用到的事件名称
634
637
635
638
// 视频加载完成事件
636
639
// cmdName: "nodeIKernelMsgListener/onRichMediaDownloadComplete";
@@ -646,7 +649,28 @@ function onBrowserWindowCreated(window, plugin) {
646
649
647
650
// 重置常用表情列表
648
651
function resetCommonlyEmoticons ( ) {
652
+ log ( "重置常用表情" ) ;
649
653
localEmoticonsConfig . commonlyEmoticons = [ ] ;
654
+ globalBroadcast ( listenList , "LiteLoader.lite_tools.updateLocalEmoticonsConfig" , localEmoticonsConfig ) ;
655
+ fs . writeFileSync ( localEmoticonsPath , JSON . stringify ( localEmoticonsConfig , null , 4 ) ) ;
656
+ }
657
+ // 增加常用表情
658
+ function addCommonlyEmoticons ( event , src ) {
659
+ if ( ! options . localEmoticons . commonlyEmoticons ) {
660
+ return ;
661
+ }
662
+ log ( "更新常用表情" , localEmoticonsPath ) ;
663
+ const newSet = new Set ( localEmoticonsConfig . commonlyEmoticons ) ;
664
+ // 如果已经有这个表情了,则更新位置
665
+ newSet . delete ( src ) ;
666
+ localEmoticonsConfig . commonlyEmoticons = Array . from ( newSet ) ;
667
+ localEmoticonsConfig . commonlyEmoticons . unshift ( src ) ;
668
+ // 删除多余的值
669
+ if ( localEmoticonsConfig . commonlyEmoticons . length > 20 ) {
670
+ localEmoticonsConfig . commonlyEmoticons . pop ( ) ;
671
+ }
672
+ log ( "send2" , localEmoticonsConfig ) ;
673
+ globalBroadcast ( listenList , "LiteLoader.lite_tools.updateLocalEmoticonsConfig" , localEmoticonsConfig ) ;
650
674
fs . writeFileSync ( localEmoticonsPath , JSON . stringify ( localEmoticonsConfig , null , 4 ) ) ;
651
675
}
652
676
0 commit comments