From 9f44133926a0398c284cea38d2897befba4ce01b Mon Sep 17 00:00:00 2001 From: stapxs <1007028430.stapx@gmail.com> Date: Fri, 23 Aug 2024 15:23:07 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E8=87=AA=E7=94=B1=20:spa?= =?UTF-8?q?rkles:=20=E7=8E=B0=E5=9C=A8=E4=BD=A0=E5=8F=AF=E4=BB=A5=E5=9C=A8?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8=E4=B8=AD=E5=8F=B3=E5=87=BB?= =?UTF-8?q?=E7=BE=A4=E7=BB=84=E8=AE=BE=E7=BD=AE=E6=98=AF=E5=90=A6=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E4=BA=86=EF=BC=81=20:lipstick:=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=B6=88=E6=81=AF=E5=9C=A8=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E6=A0=B7=E5=BC=8F=E9=94=99=E8=AF=AF=20:lipst?= =?UTF-8?q?ick:=20=E8=B0=83=E6=95=B4=E7=AA=97=E5=8F=A3=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=B0=BA=E5=AF=B8=20:bug:=20=E4=BF=AE=E6=AD=A3=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E8=BF=9E=E6=8E=A5=E6=A8=A1=E5=BC=8F=E4=B8=8B=E9=81=97?= =?UTF-8?q?=E6=BC=8F=E7=9A=84=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=20:bug:?= =?UTF-8?q?=20=E4=BF=AE=E6=AD=A3=E5=90=8E=E7=AB=AF=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E8=87=AA=E5=8A=A8=E9=87=8D=E8=BF=9E=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=9A=84=E7=BC=BA=E5=A4=B1=20:bug:=20=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E8=AE=BE=E7=BD=AE=E8=8E=B7=E5=8F=96=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=9C=A8=E5=A4=84=E7=90=86=20json=20=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E6=97=B6=E7=9A=84=E4=B8=8D=E7=BB=9F=E4=B8=80=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA=20:art:=20=E5=AF=B9=20Napcat=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=9A=84=E8=AF=86=E5=88=AB=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/css/view.css | 5 +++ src/assets/l10n/zh-CN.json | 2 ++ src/background.ts | 4 +-- src/function/connect.ts | 11 ++++--- src/function/electron/connector.ts | 30 +++++++++++++++--- src/function/msg.ts | 13 ++++++-- src/function/option.ts | 7 ++++- src/main.ts | 8 ++--- src/pages/Messages.vue | 46 ++++++++++++++++++++++++++++ src/pages/Scripts.vue | 24 ++------------- src/pages/chat-view/SystemNotice.vue | 4 +-- 11 files changed, 113 insertions(+), 41 deletions(-) diff --git a/src/assets/css/view.css b/src/assets/css/view.css index 6e69f059..9eb2c255 100644 --- a/src/assets/css/view.css +++ b/src/assets/css/view.css @@ -389,6 +389,10 @@ textarea:focus { background: var(--color-main); color: var(--color-font-r); } +.friend-body.active > svg { + background: var(--color-card-2); + color: var(--color-main); +} .friend-body.onmenu, .friend-body:hover { background: var(--color-card-2) !important; @@ -404,6 +408,7 @@ textarea:focus { width: 50px; } .friend-body > svg { + transition: background .3s, color .3s; background: var(--color-main); color: var(--color-font-1-r); pointer-events: none; diff --git a/src/assets/l10n/zh-CN.json b/src/assets/l10n/zh-CN.json index 61c36dd2..cad09ba6 100644 --- a/src/assets/l10n/zh-CN.json +++ b/src/assets/l10n/zh-CN.json @@ -341,6 +341,8 @@ "array_code": "Array 数组", "chat_pic": "图片", "log_con_backend": "使用后端连接模式", + "list_menu_notice": "开启通知", + "list_menu_notice_close": "关闭通知", "menu_about": "关于", "menu_update": "检查更新…", diff --git a/src/background.ts b/src/background.ts index 9f09c945..edebe35a 100644 --- a/src/background.ts +++ b/src/background.ts @@ -46,8 +46,8 @@ async function createWindow() { Menu.setApplicationMenu(null) // 创建窗口 const mainWindowState = windowStateKeeper({ - defaultWidth: 1200, - defaultHeight: 800 + defaultWidth: 850, + defaultHeight: 530 }) const store = new Store() let windowConfig = { diff --git a/src/function/connect.ts b/src/function/connect.ts index a16d16ce..8495e718 100644 --- a/src/function/connect.ts +++ b/src/function/connect.ts @@ -200,11 +200,12 @@ export class Connector { } } else { if(websocket) websocket.send(json) - if (Option.get('log_level') === 'debug') { - logger.debug('PUT:' + json) - } else { - logger.add(LogType.WS, 'PUT:' + json) - } + } + + if (Option.get('log_level') === 'debug') { + logger.debug('PUT:' + json) + } else { + logger.add(LogType.WS, 'PUT:' + json) } } } diff --git a/src/function/electron/connector.ts b/src/function/electron/connector.ts index 60b5f4f1..7ab9f7a8 100644 --- a/src/function/electron/connector.ts +++ b/src/function/electron/connector.ts @@ -13,6 +13,7 @@ export class Connector { private win: BrowserWindow private websocket: WebSocket | undefined + private reconnectTimes = 0 constructor(win: BrowserWindow) { this.logger.level = logLevel @@ -39,6 +40,7 @@ export class Connector { } this.websocket.onopen = () => { + this.reconnectTimes = 0 this.logger.info('已成功连接到', url) this.win.webContents.send('onebot:onopen', { address: url, token: token }) } @@ -59,6 +61,8 @@ export class Connector { this.win.webContents.send('onebot:onmessage', e.data) } this.websocket.onclose = (e) => { + this.websocket = undefined + this.logger.info('连接已关闭,代码:', e.code) if(e.code != 1006 && e.code != 1015) { // 除了需要重连的情况,其他情况都直接常规处理 @@ -68,10 +72,28 @@ export class Connector { address: url, token: token }) - } else if(e.code == 1015) { - // TSL 连接失败,尝试使用非加密连接 - this.logger.warn('连接失败,尝试使用非加密连接...') - this.connect(url.replace('wss://', 'ws://'), token) + } else { + this.win.webContents.send('onebot:onclose', { + code: -1, + message: e.reason, + address: url, + token: token + }) + } + if(this.reconnectTimes < 5) { + setTimeout(() => { + if(e.code == 1015) { + // TSL 连接失败,尝试使用非加密连接 + this.websocket = undefined + this.logger.warn('连接失败,尝试使用非加密连接...') + this.connect(url.replace('wss://', 'ws://'), token) + } else if(e.code == 1006) { + // 连接失败,尝试重连 + this.logger.warn('连接失败,尝试重连...') + this.connect(url, token) + } + this.reconnectTimes ++ + }, 1500) } } this.websocket.onerror = (e) => { diff --git a/src/function/msg.ts b/src/function/msg.ts index cb2fc40d..ab35134a 100644 --- a/src/function/msg.ts +++ b/src/function/msg.ts @@ -921,8 +921,17 @@ function newMsg(data: any) { if (data.sub_type === 'group') { data.sender.nickname = data.sender.user_id } - // (发送者不是自己 && (在特别关心列表里 || 发送者不是群组 || 群组 AT || 群组 AT 全体 || 打开了通知全部消息)) 这些情况需要进行新消息处理 - if (sender != loginId && sender != 0 && (isImportant || data.message_type !== 'group' || data.atme || data.atall || Option.get('notice_all') === true)) { + // 检查群组有没有开启通知 + let isGroupNotice = false + if(data.message_type === 'group') { + const noticeInfo = Option.get('notice_group') ?? {} + const list = noticeInfo[runtimeData.loginInfo.uin] + if(list) { + isGroupNotice = list.indexOf(id) >= 0 + } + } + // (发送者不是自己 && (在特别关心列表里 || 发送者不是群组 || 群组 AT || 群组 AT 全体 || 群组开启了通知 || 打开了通知全部消息)) 这些情况需要进行新消息处理 + if (sender != loginId && sender != 0 && (isImportant || data.message_type !== 'group' || data.atme || data.atall || isGroupNotice || Option.get('notice_all') === true)) { // (发送者没有被打开 || 窗口没有焦点 || 窗口被最小化 || 在特别关心列表里) 这些情况需要进行消息通知 if (id !== showId || !document.hasFocus() || document.hidden || isImportant) { // 准备消息内容 diff --git a/src/function/option.ts b/src/function/option.ts index 267f3865..8cd7d1f5 100644 --- a/src/function/option.ts +++ b/src/function/option.ts @@ -365,7 +365,12 @@ export function get(name: string): any { const names = Object.keys(cacheConfigs) for (let i = 0; i < names.length; i++) { if (names[i] === name) { - return cacheConfigs[names[i]] + const get = cacheConfigs[names[i]] + try { + return JSON.parse(get) + } catch(e: unknown) { + return get + } } } } diff --git a/src/main.ts b/src/main.ts index ef6d39a9..dc937ecf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -56,12 +56,12 @@ app.mount('#app') export default app export const uptime = new Date().getTime() +console.log(' _____ _____ _____ _____ __ __ \n' + + '| __|_ _| _ | _ | | | \n' + + '|__ | | | | | __|- -| \n' + + '|_____| |_| |__|__|__| |__|__| CopyRight © Stapx Steve') const strList = ['VERSION', 'WELCOME', 'HELLO'] const colorList = ['50534f', 'f9a633', '8076a3', 'f0a1a8', '92aa8a', '606E7A', '7abb7e', 'b573f7', 'ff5370', '99b3db', '677480'] const color = colorList[Math.floor(Math.random() * colorList.length)] const str = strList[Math.floor(Math.random() * strList.length)] console.log(`%c${str}%c Stapxs QQ Lite - ${packageInfo.version} ( ${process.env.NODE_ENV} ) `, `font-weight:bold;background:#${color};color:#fff;border-radius:7px 0 0 7px;display:inline-block;padding:7px 14px;margin:7px 0 7px 7px;`, 'background:#F8F9FA;color:#000;border-radius:0 7px 7px 0;display:inline-block;padding:7px 14px;margin:7px 7px 7px 0;'); -console.log(' _____ _____ _____ _____ __ __ \n' + - '| __|_ _| _ | _ | | | \n' + - '|__ | | | | | __|- -| \n' + - '|_____| |_| |__|__|__| |__|__| CopyRight © Stapx Steve') diff --git a/src/pages/Messages.vue b/src/pages/Messages.vue index c32ef645..34c5eb15 100644 --- a/src/pages/Messages.vue +++ b/src/pages/Messages.vue @@ -31,6 +31,8 @@
  • {{ $t('list_menu_canceltop') }}
  • {{ $t('list_menu_remove') }}
  • {{ $t('list_menu_readed') }}
  • +
  • {{ $t('list_menu_notice') }}
  • +
  • {{ $t('list_menu_notice_close') }}
  • @@ -224,11 +226,47 @@ export default defineComponent({ } case 'top': this.saveTop(item, true); break case 'canceltop': this.saveTop(item, false); break + case 'notice_open': { + const noticeInfo = Option.get('notice_group') ?? {} + const list = noticeInfo[runtimeData.loginInfo.uin] + if(list) { + list.push(item.group_id) + } else { + noticeInfo[runtimeData.loginInfo.uin] = [item.group_id] + } + Option.save('notice_group', noticeInfo) + break + } + case 'notice_close': { + const noticeInfo = Option.get('notice_group') ?? {} + const list = noticeInfo[runtimeData.loginInfo.uin] + if(list) { + const index = list.indexOf(item.group_id) + if(index >= 0) { + list.splice(index, 1) + } + } + Option.save('notice_group', noticeInfo) + break + } } } this.menu.select = undefined }, + /** + * 判断是否通知群消息 + * @param id 群 ID + */ + canGroupNotice(id: number) { + const noticeInfo = Option.get('notice_group') ?? {} + const list = noticeInfo[runtimeData.loginInfo.uin] + if(list) { + return list.indexOf(id) >= 0 + } + return false + }, + /** * 保存置顶信息 * @param event 点击事件 @@ -297,6 +335,14 @@ export default defineComponent({ if(item.always_top) { info.list = ['canceltop', 'readed'] } + // 是群的话显示通知设置 + if(item.group_id) { + if(this.canGroupNotice(item.group_id)) { + info.list.push('notice_close') + } else { + info.list.push('notice_open') + } + } this.listMenu = info this.menu.select = item }, diff --git a/src/pages/Scripts.vue b/src/pages/Scripts.vue index 49cd1c0a..c792aa06 100644 --- a/src/pages/Scripts.vue +++ b/src/pages/Scripts.vue @@ -89,6 +89,7 @@ import { highlight, languages } from 'prismjs' import { getMsgData } from '@/function/utils/msgUtil' import { Logger, PopInfo, PopType } from '@/function/base' +import { getRaw, save } from '@/function/option' export default defineComponent({ name: 'ViewScripts', @@ -166,13 +167,7 @@ export default defineComponent({ }, updateSave() { const saveJson = JSON.stringify(this.savedList) - if(runtimeData.tags.isElectron) { - runtimeData.reader?.send('sys:store', { - key: 'scripts', value: saveJson - }) - } else { - localStorage.setItem('scripts', saveJson) - } + save('scripts', saveJson) }, save() { this.editScript = false @@ -229,20 +224,7 @@ export default defineComponent({ } }) // 读取保存的脚本 - const electron = window.require('electron') - let data = null - if(electron) { - const reader = electron.ipcRenderer - if(reader) data = await reader.invoke('sys:getStore', 'scripts') - } - if(data) { - this.savedList = JSON.parse(data) - } else { - data = localStorage.getItem('scripts') - if(data) { - this.savedList = JSON.parse(data) - } - } + this.savedList = JSON.parse(decodeURIComponent(getRaw('scripts'))) ?? [] // 监听消息更改 this.$watch(() => runtimeData.watch.newMsg, () => { if(runtimeData.sysConfig.append_scripts) { diff --git a/src/pages/chat-view/SystemNotice.vue b/src/pages/chat-view/SystemNotice.vue index 13e35af4..97342923 100644 --- a/src/pages/chat-view/SystemNotice.vue +++ b/src/pages/chat-view/SystemNotice.vue @@ -15,7 +15,7 @@