add ops of save and read config files. migrate mainWindow to single file.

This commit is contained in:
bossgeekgo
2024-02-12 10:05:02 +08:00
parent 960c637372
commit 5d80d3a80d
5 changed files with 151 additions and 44 deletions
@@ -1,4 +1,5 @@
import fs from 'node:fs'
import fsPromise from 'node:fs/promises'
import path from 'node:path'
import os from 'node:os'
@@ -6,6 +7,8 @@ import defaultDingtalkConf from './default-config-file/dingtalk.json' assert {ty
import defaultBossConf from './default-config-file/boss.json' assert {type: 'json'}
import defaultTargetCompanyListConf from './default-config-file/target-company-list.json' assert {type: 'json'}
export const configFileNameList = ['boss.json', 'dingtalk.json', 'target-company-list.json']
const defaultConfigFileContentMap = {
'boss.json': JSON.stringify(defaultBossConf),
'dingtalk.json': JSON.stringify(defaultDingtalkConf),
@@ -28,15 +31,13 @@ const ensureRuntimeFolderPathExist = () => {
})
}
const configFolderPath = path.join(
export const configFolderPath = path.join(
runtimeFolderPath,
'config'
)
export const ensureConfigFileExist = () => {
ensureRuntimeFolderPathExist()
;[
'boss.json', 'dingtalk.json', 'target-company-list.json'
].forEach(
;configFileNameList.forEach(
fileName => {
if (!fs.existsSync(
path.join(configFolderPath, fileName)
@@ -71,3 +72,12 @@ export const readConfigFile = (fileName) => {
return o
}
export const writeConfigFile = async (fileName, content) => {
const filePath = path.join(configFolderPath, fileName)
const fileContent = JSON.stringify(content)
return fsPromise.writeFile(
filePath,
fileContent
)
}