-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathDataStorage.js
More file actions
49 lines (37 loc) · 1.05 KB
/
Copy pathDataStorage.js
File metadata and controls
49 lines (37 loc) · 1.05 KB
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
import * as fs from 'fs-extra';
import electron from 'electron';
const emptyDir = async (dirPath) => {
// eslint-disable-next-line no-console
console.info(`Clearing folder ${dirPath}`);
try {
await fs.emptyDir(dirPath);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
};
// platform related
class DataStorage {
static userDataDir;
static tmpDir;
static sessionDir;
static init() {
// Create the user data directory if it does not exist
this.userDataDir = electron.app.getPath('userData');
fs.ensureDir(this.userDataDir);
this.tmpDir = `${this.userDataDir}/Tmp`;
this.sessionDir = `${this.userDataDir}/Sessions`;
fs.ensureDir(this.tmpDir);
fs.ensureDir(this.sessionDir);
this.clear();
}
static clear() {
try {
emptyDir(this.tmpDir, false);
emptyDir(this.sessionDir, false);
} catch (e) {
console.error(e);
}
}
}
export default DataStorage;