/
AppAdapter.ts
44 lines (35 loc) · 1.02 KB
/
AppAdapter.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 * as path from "path"
import { homedir as getHomedir } from "os"
export interface AppAdapter {
readonly version: string
readonly name: string
readonly isPackaged: boolean
/**
* Path to update metadata file.
*/
readonly appUpdateConfigPath: string
/**
* Path to user data directory.
*/
readonly userDataPath: string
/**
* Path to cache directory.
*/
readonly baseCachePath: string
whenReady(): Promise<void>
quit(): void
onQuit(handler: (exitCode: number) => void): void
}
export function getAppCacheDir() {
const homedir = getHomedir()
// https://github.com/electron/electron/issues/1404#issuecomment-194391247
let result: string
if (process.platform === "win32") {
result = process.env["LOCALAPPDATA"] || path.join(homedir, "AppData", "Local")
} else if (process.platform === "darwin") {
result = path.join(homedir, "Library", "Application Support", "Caches")
} else {
result = process.env["XDG_CACHE_HOME"] || path.join(homedir, ".cache")
}
return result
}