-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.js
77 lines (70 loc) · 2.08 KB
/
user.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require('fs')
const path = require('path')
const defaultSettings = require('./default.json')
class TmUser {
constructor() {
if (!fs.existsSync(TmUser.UserPath + 'settings.json')) {
if (!fs.existsSync(TmUser.UserPath)) fs.mkdirSync(TmUser.UserPath)
this.Settings = defaultSettings
this.saveSettings()
} else {
this.Settings = require(TmUser.UserPath + 'settings.json')
}
this.Captions = require('./languages/' + this.Settings.language + '/general.json')
this.Styles = global.themes[this.Settings.theme]
this.Route = 'homepage'
this.Prefix = { homepage: '', editor: '', settings: '', documents: '' }
}
saveSettings() {
fs.writeFile(
TmUser.UserPath + 'settings.json',
JSON.stringify(this.Settings),
{ encoding: 'utf8' },
() => {}
)
}
getSetting(key) {
if (this.Settings[key] === undefined) {
this.Settings[key] = defaultSettings[key]
}
return this.Settings[key]
}
setSetting(key, value) {
this.Settings[key] = value
this.saveSettings()
}
}
switch (process.platform) {
case 'win32': {
const userParentPath = path.join(process.env.LOCALAPPDATA, 'Obstudio/')
TmUser.UserPath = path.join(userParentPath, 'Thulium 3/')
if (!fs.existsSync(userParentPath)) fs.mkdirSync(userParentPath)
if (!fs.existsSync(TmUser.UserPath)) fs.mkdirSync(TmUser.UserPath)
const dataParentPath = path.join(process.env.ALLUSERSPROFILE, 'Obstudio/')
TmUser.DataPath = path.join(dataParentPath, 'Thulium 3/')
if (!fs.existsSync(dataParentPath)) fs.mkdirSync(dataParentPath)
if (!fs.existsSync(TmUser.DataPath)) fs.mkdirSync(TmUser.DataPath)
TmUser.LineEnding = 'CRLF'
break
}
default:
// DO SOMETHING
}
const user = new TmUser()
user.Settings.lineEnding = TmUser.LineEnding
global.saveSettings = function() {
fs.writeFile(
TmUser.UserPath + 'settings.json',
JSON.stringify(global.user.state.Settings),
{ encoding: 'utf8' },
(err) => {
if (err) {
console.error(err)
}
}
)
}
module.exports = {
state: user,
mutations: {}
}