|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import uri from 'vs/base/common/uri'; |
7 | | -import * as path from 'path'; |
8 | | -import * as os from 'os'; |
9 | 7 |
|
10 | 8 | interface IPaths { |
11 | 9 | getAppDataPath(platform: string): string; |
12 | 10 | getUserDataPath(platform: string, appName: string, args: string[]): string; |
13 | 11 | } |
14 | 12 |
|
15 | | -function defaultGetAppDataPath(platform) { |
16 | | - switch (platform) { |
17 | | - case 'win32': return process.env['APPDATA']; |
18 | | - case 'darwin': return path.join(os.homedir(), 'Library', 'Application Support'); |
19 | | - case 'linux': return process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config'); |
20 | | - default: throw new Error('Platform not supported'); |
21 | | - } |
22 | | -} |
23 | | - |
24 | | -function defaultGetUserDataPath(platform, appName) { |
25 | | - return path.join(getAppDataPath(platform), appName); |
26 | | -} |
27 | | - |
28 | | -let _getAppDataPath: (platform: string) => string; |
29 | | -let _getUserDataPath: (platform: string, appName: string, args: string[]) => string; |
30 | | - |
31 | | -try { |
32 | | - const pathsPath = uri.parse(require.toUrl('paths')).fsPath; |
33 | | - const paths = require.__$__nodeRequire<IPaths>(pathsPath); |
34 | | - |
35 | | - _getAppDataPath = paths.getAppDataPath; |
36 | | - _getUserDataPath = paths.getUserDataPath; |
37 | | -} catch (error) { |
38 | | - _getAppDataPath = (platform) => defaultGetAppDataPath(platform); |
39 | | - _getUserDataPath = (platform: string, appName: string, args: string[]) => defaultGetUserDataPath(platform, appName); |
40 | | -} |
41 | | - |
42 | | -export const getAppDataPath = _getAppDataPath; |
43 | | -export const getUserDataPath = _getUserDataPath; |
| 13 | +const pathsPath = uri.parse(require.toUrl('paths')).fsPath; |
| 14 | +const paths = require.__$__nodeRequire<IPaths>(pathsPath); |
| 15 | +export const getAppDataPath = paths.getAppDataPath; |
| 16 | +export const getUserDataPath = paths.getUserDataPath; |
0 commit comments