window[Plugin.id] = window[Plugin.id] || {
logs: Vue.ref([])
}
/* 触发器 手动触发 */
const onRun = async () => {
openUI()
}
/* 触发器 APP就绪后 */
const onReady = async () => {
hookWailsIPC()
}
/* 右键 - 清空日志 */
const ClearHistory = () => {
window[Plugin.id].logs.value.splice(0)
Plugins.message.success('common.success')
}
/* 右键 - 导出日志 */
const ExportLogs = () => {
const content = JSON.stringify(window[Plugin.id].logs.value, null, 2)
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `${Plugins.APP_TITLE}_${Plugins.APP_VERSION}_${Plugins.formatDate(Date.now(), 'YYYYMMDDHHmmss')}.txt`
a.click()
URL.revokeObjectURL(url)
}
const SecurelyExportLogs = () => {
const list = Plugins.deepClone(window[Plugin.id].logs.value)
const maskedLogs = []
list.forEach((item) => {
const { name, args } = item
switch (name) {
case 'bridge.App.ProcessMemory': {
return
}
case 'bridge.App.ReadFile': {
const [file] = args
if (file === 'data/sing-box/config.json' || file === 'data/mihomo/config.yaml') {
if (item.result.flag) {
item.result.data = '【核心运行配置】已脱敏'
}
}
if (file.startsWith('data/subscribes')) {
if (item.result.flag) {
item.result.data = '【订阅文件】已脱敏'
}
}
break
}
case 'bridge.App.WriteFile': {
const [file] = args
if (file === 'data/user.yaml') {
item.args[1] = '【用户设置】已脱敏'
}
if (file === 'data/profiles.yaml') {
item.args[1] = '【配置索引】已忽略'
}
if (file === 'data/scheduledtasks.yaml') {
item.args[1] = '【计划任务索引】已忽略'
}
if (file === 'data/plugins.yaml') {
item.args[1] = '【插件索引】已忽略'
}
if (file === 'data/subscribes.yaml') {
item.args[1] = '【订阅索引】已忽略'
}
if (file === 'data/rulesets.yaml') {
item.args[1] = '【规则集索引】已忽略'
}
if (file.startsWith('data/.cache/tmp_subscription')) {
item.args[1] = '【订阅缓存文件】已忽略'
}
if (file === 'data/sing-box/config.json' || file === 'data/mihomo/config.yaml') {
item.args[1] = '【核心运行配置】已脱敏'
}
if (file.startsWith('data/subscribes')) {
item.args[1] = '【订阅文件】已脱敏'
}
if (file.startsWith('data/plugins/plugin')) {
item.args[1] = '【插件源码】已忽略'
}
break
}
case 'bridge.App.Requests': {
const [method, url, header] = item.args
const { subscribes } = Plugins.useSubscribesStore()
if (subscribes.some((s) => s.url === url)) {
item.args[1] = '【订阅链接】已脱敏'
if (item.result.flag && item.result.status === 200) {
item.result.body = '【订阅内容】已脱敏'
}
} else if (item.result.status >= 200 && item.result.status <= 299) {
if (header['Authorization'] !== undefined) {
header['Authorization'] = '【TOKEN】已忽略'
}
item.result.body = '【请求结果】已忽略'
}
break
}
case 'bridge.App.UpdateTrayAndMenus': {
item.args[0] = '【托盘图标】已忽略'
item.args[1] = '【托盘菜单】已忽略'
break
}
case 'bridge.App.UpdateTrayMenus': {
item.args[0] = '【托盘菜单项】已忽略'
break
}
}
maskedLogs.push(item)
})
const content = JSON.stringify(maskedLogs, null, 2)
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `${Plugins.APP_TITLE}_${Plugins.APP_VERSION}_${Plugins.formatDate(Date.now(), 'YYYYMMDDHHmmss')}-desensitized.txt`
a.click()
URL.revokeObjectURL(url)
}
const openUI = () => {
const component = {
template: `