Skip to content

Commit

Permalink
卷不了一点
Browse files Browse the repository at this point in the history
✨ 客户端脚本支持!现在你可以通过编写 js 脚本来执行一些自动化操作;在 设置 - 高级 - 进阶功能 处打开它。
🐛 修正获取历史会话异步异常的问题
➕ 新增依赖 prismjs、vue-prism-editor
  • Loading branch information
Stapxs committed Aug 13, 2024
1 parent a9e850a commit 7d9e504
Show file tree
Hide file tree
Showing 13 changed files with 572 additions and 38 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stapxs-qq-lite",
"version": "2.7.18",
"version": "2.8.0",
"private": false,
"author": "Stapx Steve [林槐]",
"description": "一个兼容 OneBot 的非官方网页版 QQ 客户端,使用 Vue 重制的全新版本。",
Expand All @@ -17,6 +17,7 @@
"dependencies": {
"@jakejarrett/gtk-theme": "^2.0.1",
"@stapxs/umami-logger-typescript": "^1.0.12",
"@types/prismjs": "^1.26.4",
"axios": "^1.7.2",
"browser-image-compression": "^2.0.0",
"core-js": "^3.8.3",
Expand All @@ -28,6 +29,7 @@
"js-yaml-loader": "^1.2.2",
"jsonpath": "^1.1.1",
"pinyin": "^3.0.0-alpha.4",
"prismjs": "^1.29.0",
"raw-loader": "^4.0.2",
"register-service-worker": "^1.7.2",
"semver-compare": "^1.0.0",
Expand All @@ -39,6 +41,7 @@
"vue": "^3.2.13",
"vue-clipboard2": "^0.3.3",
"vue-i18n": "^9.2.2",
"vue-prism-editor": "^2.0.0-alpha.2",
"vue3-bcui": "^0.2.3",
"vue3-danmaku": "^1.6.0",
"vue3-infinite-scroll-better": "^2.2.0",
Expand Down
22 changes: 15 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
<div id="base-app">
<div class="main-body">
<ul :style="get('fs_adaptation') > 0 ? `padding-bottom: ${get('fs_adaptation')}px;` : ''">
<li id="bar-home" @click="changeTab('主页', 'Home', true)"
<li id="bar-home" @click="changeTab('主页', 'Home', false)"
:class="(tags.page == 'Home' ? 'active' : '') + (loginInfo.status ? ' hiden-home' : '')">
<font-awesome-icon :icon="['fas', 'home']" />
</li>
<li id="bar-msg" @click="changeTab('信息', 'Messages', false)" :class="tags.page == 'Messages' ? 'active' : ''">
<li id="bar-msg" @click="changeTab('信息', 'Messages', true)" :class="tags.page == 'Messages' ? 'active' : ''">
<font-awesome-icon :icon="['fas', 'envelope']" />
</li>
<li id="bar-friends" @click="changeTab('列表', 'Friends', false)" :class="tags.page == 'Friends' ? 'active' : ''">
<li id="bar-friends" @click="changeTab('列表', 'Friends', true)" :class="tags.page == 'Friends' ? 'active' : ''">
<font-awesome-icon :icon="['fas', 'user']" />
</li>
<div class="side-bar-space"></div>
<li @click="changeTab('设置', 'Options', true);Connector.send('get_version_info', {}, 'getVersionInfo')"
<li v-show="runtimeData.sysConfig.append_scripts" id="bar-friends" @click="changeTab('脚本', 'Scripts', false)" :class="tags.page == 'Scripts' ? 'active' : ''">
<font-awesome-icon :icon="['fas', 'file-code']" />
</li>
<li @click="changeTab('设置', 'Options', false);Connector.send('get_version_info', {}, 'getVersionInfo')"
:class="tags.page == 'Options' ? 'active' : ''">
<font-awesome-icon :icon="['fas', 'gear']" />
</li>
Expand Down Expand Up @@ -94,6 +97,9 @@
@userClick="changeChat">
</Friends>
</div>
<div v-show="tags.page == 'Scripts' && runtimeData.sysConfig.append_scripts">
<Scripts></Scripts>
</div>
<div class="opt-main-tab">
<Options
:class="tags.page == 'Options' ? 'active' : ''"
Expand Down Expand Up @@ -191,6 +197,7 @@ import { runtimeData, notificationList } from '@/function/msg'
import { BaseChatInfoElem } from '@/function/elements/information'
import * as App from './function/utils/appUtil'
import Scripts from '@/pages/Scripts.vue'
import Options from '@/pages/Options.vue'
import Friends from '@/pages/Friends.vue'
import Messages from '@/pages/Messages.vue'
Expand All @@ -199,6 +206,7 @@ import Chat from '@/pages/Chat.vue'
export default defineComponent({
name: 'App',
components: {
Scripts,
Options,
Friends,
Messages,
Expand Down Expand Up @@ -253,14 +261,14 @@ export default defineComponent({
changeTab (name: string, view: string, show: boolean) {
// UM:发送页面路由分析
Umami.trackPageView('/' + view)
this.tags.showChat = !show
this.tags.showChat = show
this.tags.page = view
},
barMainClick() {
if(loginInfo.status) {
this.changeTab('信息', 'Messages', false)
this.changeTab('信息', 'Messages', true)
} else {
this.changeTab('主页', 'Home', true)
this.changeTab('主页', 'Home', false)
}
},
Expand Down
43 changes: 43 additions & 0 deletions src/assets/css/append/append_new.css
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,49 @@
font-size: 0.7rem;
}

.script-view .list {
margin-left: -20px;
}
.script-view .list > header {
margin-top: 35px;
}
.script-view .list > header > span {
margin: 10px -5px 0 -5px;
font-size: 0.8rem;
}
.script-view .list-body {
margin: 0 -5px;
}
.script-view .list-body h2 {
font-size: 0.9rem;
}
.script-view .list-body span {
font-size: 0.8rem;
}
.script-view .list-body span svg {
margin: 0;
font-size: 0.75rem;
}
.script-view .editor-main {
box-shadow: -5px 0px 4px -5px var(--color-shader);
}
.script-view .save-controller > span,
.script-view .save-controller > svg {
font-size: 0.8rem;
}
.script-view .opt-item > select,
.script-view .ss-button {
height: 30px !important;
}
.script-view .ss-button,
.script-view .opt-item > select,
.script-view .ss-button > svg {
font-size: 0.75rem;
}
.script-view .editor {
font-size: 0.8rem;
}

@media (max-width: 700px) {
.main-body > ul {
background: var(--color-card-2) !important;
Expand Down
9 changes: 9 additions & 0 deletions src/assets/css/append/append_vibrancy.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
left: 270px;
}

.script-view {
background: rgba(var(--color-card-rgb), 0.6) !important;
}
.script-view .list > header > span,
.script-view .list-body > div {
background: transparent;
backdrop-filter: blur(10px);
}

@media (max-width: 500px) {
.chat-pan > div.info {
margin-top: 35px;
Expand Down
12 changes: 12 additions & 0 deletions src/assets/l10n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,18 @@
"option_dev_chat_respond": "关闭回应功能",
"option_dev_chat_respond_tip": "如果你不想用它或者 bot 不支持,可以关闭这个功能",
"chat_jump_reply_fail": "(获取回复消息失败)",
"title_scripts": "脚本",
"scripts_tip": "脚本功能提供了一种简便的自动化操作方式,能够执行如自动回复等任务。",
"scripts_run_save": "保存",
"scripts_run_condition": "条件",
"scripts_run_trigger": "触发",
"scripts_run_message": "新消息",
"option_dev_append": "进阶功能",
"option_dev_scripts_tip": "显示脚本功能面板",
"statue_enabled": "已启用",
"statue_disabled": "已禁用",
"scripts_run_title_err": "脚本标题已存在",
"scripts_run_notice": "脚本方法将限制在当前页面内,你可以参考当前页面的源代码来了解可用的方法可用。",

"menu_about": "关于",
"menu_update": "检查更新…",
Expand Down
57 changes: 32 additions & 25 deletions src/function/electron/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ export function regIpcListener() {
return os.release()
})
// 代理请求 HTTP
ipcMain.on('sys:requestHttp', (event, args) => {
console.log(args)
// ipcMain.on('sys:requestHttp', (event, args) => {
// console.log(args)

const cookies = JSON.parse(args.cookies)
console.log(cookies)
const cookieStrs = Object.keys(cookies).map((key) => {
return key + '=' + cookies[key]
})
console.log(cookieStrs.join('; '))
// 异步请求,不需要立即返回
axios({
method: args.type,
url: args.url,
headers: {
'Content-Type': 'application/json',
'Cookie': cookieStrs.join('; '),
},
data: args.data
}).then((res) => {
// res.data
console.log(res.data)
}).catch((err) => {
// err
console.error(err)
})
})
// const cookies = JSON.parse(args.cookies)
// console.log(cookies)
// const cookieStrs = Object.keys(cookies).map((key) => {
// return key + '=' + cookies[key]
// })
// console.log(cookieStrs.join('; '))
// // 异步请求,不需要立即返回
// axios({
// method: args.type,
// url: args.url,
// headers: {
// 'Content-Type': 'application/json',
// 'Cookie': cookieStrs.join('; '),
// },
// data: args.data
// }).then((res) => {
// // res.data
// console.log(res.data)
// }).catch((err) => {
// // err
// console.error(err)
// })
// })
// 关闭窗口
ipcMain.on('win:close', () => {
if(win) win.close()
Expand All @@ -63,6 +63,13 @@ export function regIpcListener() {
app.relaunch()
app.exit()
})
// 保存信息
ipcMain.on('sys:store', (event, arg) => {
store.set(arg.key, arg.value)
})
ipcMain.handle('sys:getStore', (event, key) => {
return store.get(key)
})
// 保存设置
// PS:升级至 electron 27 后 cookie 已完全无法持久化,只能进行保存
ipcMain.on('opt:saveAll', (event, arg) => {
Expand Down
3 changes: 3 additions & 0 deletions src/function/elements/information.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface RunTimeDataElem {
classes: any[],
sw?: boolean
},
watch: { // PS: 一些给监听器捕捉用的数据
newMsg: any
},
messageList: any[]
mergeMessageList?: any[] | undefined,
stickerCache?: any[],
Expand Down
14 changes: 14 additions & 0 deletions src/function/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const popInfo = new PopInfo()
// eslint-disable-next-line
let msgPath = require('@/assets/pathMap/Lagrange.OneBot.yaml')

// 其他 tag
let listLoadTimes = 0

export function parse(str: string) {
const msg = JSON.parse(str)
if (msg.echo !== undefined) {
Expand Down Expand Up @@ -244,6 +247,7 @@ function createRecentContact(data: any) {
}

function saveUser(msg: { [key: string]: any }, type: string) {
listLoadTimes ++
let list: any[] | undefined
if(msgPath.user_list)
list = getMsgData('user_list', msg, msgPath.user_list)
Expand Down Expand Up @@ -324,6 +328,12 @@ function saveUser(msg: { [key: string]: any }, type: string) {
value: app.config.globalProperties.$t('menu_user_list', { count: runtimeData.userList.length })
})
}
// 如果获取次数大于 0 并且是双数,刷新一下历史会话
if(listLoadTimes > 0 && listLoadTimes % 2 == 0) {
// 获取最近的会话
if(runtimeData.jsonMap.recent_contact)
Connector.send(runtimeData.jsonMap.recent_contact.name, {}, 'GetRecentContact')
}
}

function updateTopMsg(msg: any, echoList: string[]) {
Expand Down Expand Up @@ -781,6 +791,7 @@ function newMsg(data: any) {
return item.user_id == sender
})
const isImportant = senderInfo?.class_id == 9999
runtimeData.watch.newMsg = data

// 消息回调检查
// PS:如果在新消息中获取到了自己的消息,则自动打开“停止消息回调”设置防止发送的消息重复
Expand Down Expand Up @@ -1170,6 +1181,9 @@ const baseRuntime = {
connectSsl: false,
classes: []
},
watch: {
newMsg: {}
},
chatInfo: {
show: { type: '', id: 0, name: '', avatar: '' },
info: {
Expand Down
3 changes: 0 additions & 3 deletions src/function/utils/appUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ export function reloadUsers() {
Connector.send(groupName, {}, 'getGroupList')
// 获取系统消息
Connector.send('get_system_msg', {}, 'getSystemMsg')
// 获取最近的会话
if(runtimeData.jsonMap.recent_contact)
Connector.send(runtimeData.jsonMap.recent_contact.name, {}, 'GetRecentContact')
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/function/utils/msgUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export function sendMsgRaw(id: string, type: string, msg: string | { type: strin
switch (type) {
case 'group':
Connector.send(
runtimeData.jsonMap.message_list.name_group_send ?? 'send_group_msg',
runtimeData.jsonMap.message_list.name_group_send ?? 'send_msg',
{ 'group_id': id, 'message': msg },'sendMsgBack_uuid_' + msgUUID); break
case 'user':
{
Expand All @@ -400,7 +400,7 @@ export function sendMsgRaw(id: string, type: string, msg: string | { type: strin
{ 'user_id': id.split('/')[0], 'group_id': id.split('/')[1], 'message': msg }, 'sendMsgBack_uuid_' + msgUUID);
} else {
Connector.send(
runtimeData.jsonMap.message_list.name_user_send ?? 'send_private_msg',
runtimeData.jsonMap.message_list.name_user_send ?? 'send_msg',
{ 'user_id': id, 'message': msg }, 'sendMsgBack_uuid_' + msgUUID);
}
break
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import VueViewer from 'v-viewer'
import VueClipboard from 'vue-clipboard2'
import InfiniteScroll from 'vue3-infinite-scroll-better'
import packageInfo from '../package.json'
import { PrismEditor } from 'vue-prism-editor'

import App from './App.vue'

Expand All @@ -16,6 +17,7 @@ import { faSquare } from '@fortawesome/free-regular-svg-icons'
import './registerServiceWorker'

import 'viewerjs/dist/viewer.css'
import 'vue-prism-editor/dist/prismeditor.min.css'

import './assets/css/view.css'
import './assets/css/chat.css'
Expand Down Expand Up @@ -48,6 +50,7 @@ app.use(InfiniteScroll)
library.add(fas)
library.add(faSquare)
app.component('font-awesome-icon', FontAwesomeIcon)
app.component('PrismEditor', PrismEditor)

app.mount('#app')
export default app
Expand Down
Loading

0 comments on commit 7d9e504

Please sign in to comment.