diff --git a/src/index.html b/src/index.html
index 12db07c..06b9192 100644
--- a/src/index.html
+++ b/src/index.html
@@ -56,7 +56,7 @@
A
diff --git a/src/js/app.js b/src/js/app.js
index ec4f7e5..90f9fb6 100644
--- a/src/js/app.js
+++ b/src/js/app.js
@@ -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 })
+ }
+ }
}
})
diff --git a/src/main.js b/src/main.js
index 186d86d..cfc347e 100644
--- a/src/main.js
+++ b/src/main.js
@@ -66,7 +66,7 @@ app.once('ready', () => {
win = null
})
- win.openDevTools()
+ // win.openDevTools()
// 然后加载应用的 index.html
win.loadURL('app://local/index.html')
diff --git a/src/tools/init.js b/src/tools/init.js
index 9bfe86e..77531dc 100644
--- a/src/tools/init.js
+++ b/src/tools/init.js
@@ -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':