-
Notifications
You must be signed in to change notification settings - Fork 813
/
Copy pathmodel.ts
44 lines (32 loc) · 1.06 KB
/
model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import path from 'path'
import low from 'lowdb'
import FileSync from 'lowdb/adapters/FileSync'
import { BrowserWindow } from 'electron'
import { IApplicationDb, IApplication } from './interfaces/application'
export default class Model {
appDir: string
buildDir: string
$setting: any
$posts: any
$theme: any
db: IApplicationDb
mainWindow: BrowserWindow
constructor(appInstance: IApplication) {
this.appDir = appInstance.appDir
this.buildDir = appInstance.buildDir
this.db = appInstance.db
this.mainWindow = appInstance.mainWindow
this.initDataStore()
}
private initDataStore(): void {
const settingAdapter = new FileSync(path.join(this.appDir, 'config/setting.json'))
const setting = low(settingAdapter)
this.$setting = setting
const postsAdapter = new FileSync(path.join(this.appDir, 'config/posts.json'))
const posts = low(postsAdapter)
this.$posts = posts
const themeAdapter = new FileSync(path.join(this.appDir, 'config/theme.json'))
const theme = low(themeAdapter)
this.$theme = theme
}
}