old
parent
5b5e686b8c
commit
1010b6cdd5
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @authors yutent (yutent@doui.cc)
|
* @authors yutent (yutent@doui.cc)
|
||||||
* @date 2019-11-06 09:26:52
|
* @date 2019-12-02 15:38:50
|
||||||
* @version v2.0.1
|
* @version v2.0.1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @authors yutent (yutent@doui.cc)
|
* @authors yutent (yutent@doui.cc)
|
||||||
* @date 2019-09-27 11:36:21
|
* @date 2019-12-02 15:38:50
|
||||||
* @version v2.0.1
|
* @version v2.0.1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,6 +11,7 @@ const fs = require('iofs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const HOST_FILE = path.resolve(app.getPath('userData'), 'host.cache')
|
const HOST_FILE = path.resolve(app.getPath('userData'), 'host.cache')
|
||||||
|
const LOCK_FILE = path.resolve(app.getPath('userData'), 'lock')
|
||||||
|
|
||||||
if (!fs.exists(HOST_FILE)) {
|
if (!fs.exists(HOST_FILE)) {
|
||||||
fs.echo('{}', HOST_FILE)
|
fs.echo('{}', HOST_FILE)
|
||||||
|
@ -56,6 +57,12 @@ ipcMain.on('dns-host', (ev, conn) => {
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'history':
|
case 'history':
|
||||||
|
if (fs.exists(LOCK_FILE)) {
|
||||||
|
var cache = fs.cat(HOST_FILE)
|
||||||
|
ev.returnValue = JSON.parse(cache)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var cache = fs.cat('/etc/hosts').toString()
|
var cache = fs.cat('/etc/hosts').toString()
|
||||||
var records = cache.split(/[\n\r]+/)
|
var records = cache.split(/[\n\r]+/)
|
||||||
var list = []
|
var list = []
|
||||||
|
@ -77,6 +84,10 @@ ipcMain.on('dns-host', (ev, conn) => {
|
||||||
list.forEach(it => {
|
list.forEach(it => {
|
||||||
it.name = it.name.split('.')
|
it.name = it.name.split('.')
|
||||||
let domain = it.name.splice(-2, 2).join('.')
|
let domain = it.name.splice(-2, 2).join('.')
|
||||||
|
if (domain === 'com.cn' || domain === 'org.cn' || domain === 'net.cn') {
|
||||||
|
domain = it.name.pop() + '.' + domain
|
||||||
|
}
|
||||||
|
|
||||||
if (dict[domain]) {
|
if (dict[domain]) {
|
||||||
dict[domain].push({
|
dict[domain].push({
|
||||||
value: it.ip,
|
value: it.ip,
|
||||||
|
@ -97,5 +108,7 @@ ipcMain.on('dns-host', (ev, conn) => {
|
||||||
})
|
})
|
||||||
list = null
|
list = null
|
||||||
ev.returnValue = dict
|
ev.returnValue = dict
|
||||||
|
fs.echo(JSON.stringify(dict), HOST_FILE)
|
||||||
|
fs.echo('', LOCK_FILE)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue