feat: 百度统计,转移config目录,防止更新后被删除
parent
87ac9173f9
commit
274ce7968c
|
@ -1,7 +1,7 @@
|
||||||
# dev-sidecar
|
# dev-sidecar
|
||||||
开发者边车,命名取自service-mesh的service-sidecar,意为为开发者打辅助的边车工具
|
开发者边车,命名取自service-mesh的service-sidecar,意为为开发者打辅助的边车工具
|
||||||
通过本地代理的方式将http请求代理到一些国内的加速通道上
|
通过本地代理的方式将http请求代理到一些国内的加速通道上
|
||||||
不用翻墙也能解决一些网站和库无法访问或访问速度慢的问题
|
不用`ss小飞机`也能解决一些网站和库无法访问或访问速度慢的问题
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,6 +18,7 @@
|
||||||
"@docmirror/mitmproxy": "1.0.2",
|
"@docmirror/mitmproxy": "1.0.2",
|
||||||
"ant-design-vue": "^1.6.5",
|
"ant-design-vue": "^1.6.5",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
|
"electron-baidu-tongji": "^1.0.5",
|
||||||
"electron-store": "^6.0.1",
|
"electron-store": "^6.0.1",
|
||||||
"electron-updater": "^4.3.5",
|
"electron-updater": "^4.3.5",
|
||||||
"es-abstract": "^1.17.7",
|
"es-abstract": "^1.17.7",
|
||||||
|
@ -29,6 +30,10 @@
|
||||||
"vue-json-editor": "^1.4.2",
|
"vue-json-editor": "^1.4.2",
|
||||||
"vue-router": "^3.4.8"
|
"vue-router": "^3.4.8"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"hexoid": "^1.0.0",
|
||||||
|
"formidable": "2.0.0-canary.20200504.1"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vue/cli-plugin-babel": "~4.5.0",
|
"@vue/cli-plugin-babel": "~4.5.0",
|
||||||
"@vue/cli-plugin-eslint": "~4.5.0",
|
"@vue/cli-plugin-eslint": "~4.5.0",
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
/* global __static */
|
/* global __static */
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { app, protocol, BrowserWindow, Menu, Tray } from 'electron'
|
import { app, protocol, BrowserWindow, Menu, Tray, ipcMain } from 'electron'
|
||||||
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
|
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
|
||||||
import bridge from './bridge/index'
|
import bridge from './bridge/index'
|
||||||
import updateHandle from './bridge/update-handle'
|
import updateHandle from './bridge/update-handle'
|
||||||
|
import { ebtMain } from './tongji'
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const isMac = process.platform === 'darwin'
|
const isMac = process.platform === 'darwin'
|
||||||
|
|
||||||
|
@ -190,6 +192,10 @@ if (!isFirstInstance) {
|
||||||
}
|
}
|
||||||
// 自动更新
|
// 自动更新
|
||||||
updateHandle(win, updateUrl)
|
updateHandle(win, updateUrl)
|
||||||
|
|
||||||
|
// 百度分析
|
||||||
|
ebtMain(ipcMain, isDevelopment)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 最小化到托盘
|
// 最小化到托盘
|
||||||
tray = setTray(app)
|
tray = setTray(app)
|
||||||
|
|
|
@ -120,14 +120,14 @@ function _getSettingsPath () {
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir)
|
fs.mkdirSync(dir)
|
||||||
}
|
}
|
||||||
return dir + 'setting.json5'
|
return dir + '/setting.json5'
|
||||||
}
|
}
|
||||||
function _getConfigPath () {
|
function _getConfigPath () {
|
||||||
const dir = getDefaultConfigBasePath()
|
const dir = getDefaultConfigBasePath()
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir)
|
fs.mkdirSync(dir)
|
||||||
}
|
}
|
||||||
return dir + 'config.json5'
|
return dir + '/config.json5'
|
||||||
}
|
}
|
||||||
|
|
||||||
function doMerge (defObj, newObj) {
|
function doMerge (defObj, newObj) {
|
||||||
|
|
|
@ -7,6 +7,10 @@ import VueRouter from 'vue-router'
|
||||||
import routes from './view/router'
|
import routes from './view/router'
|
||||||
import DsContainer from './view/components/container'
|
import DsContainer from './view/components/container'
|
||||||
import './view/style/index.scss'
|
import './view/style/index.scss'
|
||||||
|
import { ipcRenderer } from 'electron'
|
||||||
|
|
||||||
|
const tongji = require('./tongji')
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
Vue.use(antd)
|
Vue.use(antd)
|
||||||
Vue.use(VueRouter)
|
Vue.use(VueRouter)
|
||||||
|
@ -25,6 +29,10 @@ view.initApi().then(async (api) => {
|
||||||
render: h => h(App)
|
render: h => h(App)
|
||||||
}).$mount('#app')
|
}).$mount('#app')
|
||||||
|
|
||||||
|
const BAIDU_SITE_ID = 'f2d170ce560aef0005b689f28697f852'
|
||||||
|
// 百度统计
|
||||||
|
tongji.ebtRenderer(ipcRenderer, BAIDU_SITE_ID, router)
|
||||||
|
|
||||||
view.initModules(app)
|
view.initModules(app)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
|
||||||
|
const request = require('request')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* first step
|
||||||
|
* @param {*} ipcMain
|
||||||
|
*/
|
||||||
|
const ebtMain = (ipcMain, isDevelopment) => {
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (!(ipcMain && ipcMain.on)) {
|
||||||
|
throw new TypeError('require ipcMain')
|
||||||
|
}
|
||||||
|
|
||||||
|
// step 2
|
||||||
|
ipcMain.on('electron-baidu-tongji-message', (event, arg) => {
|
||||||
|
// electron 生产模式下是直接请求文件系统,没有 http 地址
|
||||||
|
// 前台拿不到 hm.js 的内容
|
||||||
|
request({
|
||||||
|
url: `https://hm.baidu.com/hm.js?${arg}`,
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Referer: 'https://hm.baidu.com/'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err, response, body) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('百度统计请求出错', err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const rource = '(h.c.b.su=h.c.b.u||document.location.href),h.c.b.u=f.protocol+"//"+document.location.host+'
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (body && body.indexOf(rource) >= 0) {
|
||||||
|
// step 3
|
||||||
|
let text = body
|
||||||
|
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (!isDevelopment) {
|
||||||
|
// 百度统计可能改规则了,不统计 file:// 开始的请求
|
||||||
|
// 这里强制替换为 https
|
||||||
|
const target = '(h.c.b.su=h.c.b.u||"https://"+c.dm[0]+a[1]),h.c.b.u="https://"+c.dm[0]+'
|
||||||
|
const target2 = '"https://"+c.dm[0]+window.location.pathname+window.location.hash'
|
||||||
|
text = body.replace(rource, target).replace(/window.location.href/g, target2)
|
||||||
|
}
|
||||||
|
console.log('baidu tonji: ret')
|
||||||
|
event.sender.send('electron-baidu-tongji-reply', { text, isDevelopment })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* second step
|
||||||
|
* @param {*} ipcRenderer
|
||||||
|
* @param {*} siteId
|
||||||
|
* @param {*} router
|
||||||
|
*/
|
||||||
|
const ebtRenderer = (ipcRenderer, siteId, router) => {
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (!(ipcRenderer && ipcRenderer.on && ipcRenderer.send)) {
|
||||||
|
throw new TypeError('require ipcRenderer')
|
||||||
|
}
|
||||||
|
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (!(siteId && typeof siteId === 'string')) {
|
||||||
|
throw new TypeError('require siteId')
|
||||||
|
}
|
||||||
|
|
||||||
|
// step 4
|
||||||
|
ipcRenderer.on('electron-baidu-tongji-reply', (_, { text, isDevelopment }) => {
|
||||||
|
console.log('electron-baidu-tongji-reply')
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (isDevelopment) { document.body.classList.add('electron-baidu-tongji_dev') }
|
||||||
|
|
||||||
|
window._hmt = window._hmt || []
|
||||||
|
|
||||||
|
const hm = document.createElement('script')
|
||||||
|
hm.text = text
|
||||||
|
|
||||||
|
const head = document.getElementsByTagName('head')[0]
|
||||||
|
head.appendChild(hm)
|
||||||
|
|
||||||
|
// Vue单页应用时,监听router的每次变化
|
||||||
|
// 把虚拟的url地址赋给百度统计的API接口
|
||||||
|
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (router && router.beforeEach) {
|
||||||
|
router.beforeEach((to, _, next) => {
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (to.path) {
|
||||||
|
window._hmt.push(['_trackPageview', '/#' + to.fullPath])
|
||||||
|
console.log('baidu trace', to.fullPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// step 1
|
||||||
|
ipcRenderer.send('electron-baidu-tongji-message', siteId)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { ebtMain, ebtRenderer }
|
|
@ -1,4 +1,6 @@
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const webpack = require('webpack')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
pages: {
|
pages: {
|
||||||
index: {
|
index: {
|
||||||
|
@ -8,6 +10,9 @@ module.exports = {
|
||||||
},
|
},
|
||||||
configureWebpack: config => {
|
configureWebpack: config => {
|
||||||
const configNew = {
|
const configNew = {
|
||||||
|
plugins: [
|
||||||
|
new webpack.DefinePlugin({ 'global.GENTLY': true })
|
||||||
|
],
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue