old
宇天 2019-12-02 21:37:00 +08:00
parent 5b5e686b8c
commit 1010b6cdd5
4 changed files with 17 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
/**
*
* @authors yutent (yutent@doui.cc)
* @date 2019-11-06 09:26:52
* @date 2019-12-02 15:38:50
* @version v2.0.1
*
*/

View File

@ -1,7 +1,7 @@
/**
*
* @authors yutent (yutent@doui.cc)
* @date 2019-09-27 11:36:21
* @date 2019-12-02 15:38:50
* @version v2.0.1
*
*/

View File

@ -11,6 +11,7 @@ const fs = require('iofs')
const path = require('path')
const HOST_FILE = path.resolve(app.getPath('userData'), 'host.cache')
const LOCK_FILE = path.resolve(app.getPath('userData'), 'lock')
if (!fs.exists(HOST_FILE)) {
fs.echo('{}', HOST_FILE)
@ -56,6 +57,12 @@ ipcMain.on('dns-host', (ev, conn) => {
break
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 records = cache.split(/[\n\r]+/)
var list = []
@ -77,6 +84,10 @@ ipcMain.on('dns-host', (ev, conn) => {
list.forEach(it => {
it.name = it.name.split('.')
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]) {
dict[domain].push({
value: it.ip,
@ -97,5 +108,7 @@ ipcMain.on('dns-host', (ev, conn) => {
})
list = null
ev.returnValue = dict
fs.echo(JSON.stringify(dict), HOST_FILE)
fs.echo('', LOCK_FILE)
}
})