old
宇天 2019-12-03 17:25:16 +08:00
parent 1010b6cdd5
commit 163e2cfaf4
4 changed files with 53 additions and 5 deletions

View File

@ -56,7 +56,7 @@
<span>A</span>
<wc-input class="long" :duplex="it.value" label="请填写IP"></wc-input>
<section>
<wc-switch :duplex="it.enabled"></wc-switch>
<wc-switch :duplex="it.enabled" @change="recordChanges(it)"></wc-switch>
<wc-button size="mini" color="red" @active="$remove">删除</wc-button>
</section>
<wc-input :duplex="it.remark"></wc-input>

View File

@ -19,6 +19,7 @@ const WIN = remote.getCurrentWindow()
const $doc = Anot(document)
var dict = {}
var tmp_records = {}
Anot({
$id: 'app',
@ -33,6 +34,7 @@ Anot({
// this.$refs.preview.show()
this.check()
},
watch: {},
methods: {
addRecord() {
log('---')
@ -68,6 +70,17 @@ Anot({
toggleDomain(name) {
this.curr = name
this.records = dict[name]
tmp_records = Object.create(null)
for (let it of this.records) {
if (tmp_records[it.record]) {
tmp_records[it.record].push(it)
} else {
tmp_records[it.record] = [it]
}
}
setTimeout(() => {
this.$refs.records.scrollTop = 0
}, 50)
},
check() {
var check = ipcRenderer.sendSync('dns-host', { type: 'check' })
@ -77,13 +90,34 @@ Anot({
var tmp = []
for (var k in dict) {
tmp.push(k)
if (k) {
tmp.push(k)
} else {
delete dict[k]
}
}
this.domains = tmp
} else {
this.permissionShow = true
}
},
save() {}
// 同一个记录, 允许一条被激活
recordChanges(item) {
if (item.enabled) {
if (tmp_records[item.record].length > 1) {
for (let it of tmp_records[item.record]) {
if (it.value !== item.value) {
it.enabled = false
}
}
}
}
},
save() {
if (this.curr) {
dict[this.curr] = this.records.$model
ipcRenderer.send('dns-host', { type: 'set', data: dict })
}
}
}
})

View File

@ -66,7 +66,7 @@ app.once('ready', () => {
win = null
})
win.openDevTools()
// win.openDevTools()
// 然后加载应用的 index.html
win.loadURL('app://local/index.html')

View File

@ -44,7 +44,21 @@ ipcMain.on('dns-host', (ev, conn) => {
clearTimeout(timer)
timer = setTimeout(() => {
fs.echo(JSON.stringify(conn.data), HOST_FILE)
}, 2000)
var txt = ''
for (let k in conn.data) {
for (let it of conn.data[k]) {
if (it.enabled) {
var name = it.record === '@' ? '' : it.record
if (name) {
name += '.'
}
txt += `${it.value.padEnd(15, ' ')} ${name + k}\n`
}
}
txt += '\n\n'
}
fs.echo(txt, '/etc/hosts')
}, 1000)
break
case 'check':