Skip to content

Commit

Permalink
实现所有修改过的设置都能自动保存
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmader committed Apr 8, 2019
1 parent 6a45ba9 commit 5a043b7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

const fs = require("fs")
const { resolve, join } = require("path")
const { EOL } = require("os")
const { ipcRenderer, shell, remote: { app } } = require("electron")

const check_update = require("./check_update.js")
Expand Down Expand Up @@ -74,10 +75,15 @@ const saveLocalConfig = (options) => {
let conf = fs.readFileSync(conf_path).toString()

Object.entries(options).forEach(([key, value]) => {
conf = conf.replace(
new RegExp(`(${key}=).*`),
"$1" + value
)
const r = new RegExp(`^(?:#\\s*)?(${key}=).*`, "m")
if (r.test(conf)) {
conf = conf.replace(
r,
"$1" + value
)
} else {
conf += `${EOL}${key}=${value}`
}
})

fs.writeFileSync(conf_path, conf)
Expand Down

0 comments on commit 5a043b7

Please sign in to comment.