2017-05-25 22:59:02 -08:00
|
|
|
// This module exports paths, names, and other metadata that is referenced
|
2019-11-28 05:17:01 -09:00
|
|
|
import {homedir} from 'os';
|
|
|
|
|
import {app} from 'electron';
|
|
|
|
|
import {statSync} from 'fs';
|
|
|
|
|
import {resolve, join} from 'path';
|
|
|
|
|
import isDev from 'electron-is-dev';
|
2017-05-25 22:59:02 -08:00
|
|
|
|
2017-06-02 16:03:47 -08:00
|
|
|
const cfgFile = '.hyper.js';
|
|
|
|
|
const defaultCfgFile = 'config-default.js';
|
2019-03-02 13:58:19 -09:00
|
|
|
const homeDirectory = homedir();
|
2017-05-25 22:59:02 -08:00
|
|
|
|
2019-05-05 20:00:50 -08:00
|
|
|
// If the user defines XDG_CONFIG_HOME they definitely want their config there,
|
|
|
|
|
// otherwise use the home directory in linux/mac and userdata in windows
|
|
|
|
|
const applicationDirectory =
|
|
|
|
|
process.env.XDG_CONFIG_HOME !== undefined
|
|
|
|
|
? join(process.env.XDG_CONFIG_HOME, 'hyper')
|
2019-10-02 16:56:50 -08:00
|
|
|
: process.platform == 'win32'
|
|
|
|
|
? app.getPath('userData')
|
|
|
|
|
: homedir();
|
2019-03-02 13:58:19 -09:00
|
|
|
|
|
|
|
|
let cfgDir = applicationDirectory;
|
2019-05-08 10:56:45 -08:00
|
|
|
let cfgPath = join(applicationDirectory, cfgFile);
|
2019-12-24 06:56:23 -09:00
|
|
|
const legacyCfgPath = join(homeDirectory, cfgFile); // Hyper 2 config location
|
2017-05-25 22:59:02 -08:00
|
|
|
|
|
|
|
|
const devDir = resolve(__dirname, '../..');
|
2017-06-02 16:03:47 -08:00
|
|
|
const devCfg = join(devDir, cfgFile);
|
|
|
|
|
const defaultCfg = resolve(__dirname, defaultCfgFile);
|
2017-05-25 22:59:02 -08:00
|
|
|
|
2017-09-10 15:20:52 -08:00
|
|
|
if (isDev) {
|
|
|
|
|
// if a local config file exists, use it
|
|
|
|
|
try {
|
|
|
|
|
statSync(devCfg);
|
|
|
|
|
cfgPath = devCfg;
|
|
|
|
|
cfgDir = devDir;
|
|
|
|
|
console.log('using config file:', cfgPath);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 16:07:50 -08:00
|
|
|
const plugins = resolve(cfgDir, '.hyper_plugins');
|
|
|
|
|
const plugs = {
|
2019-05-08 10:56:45 -08:00
|
|
|
legacyBase: resolve(homeDirectory, '.hyper_plugins'),
|
|
|
|
|
legacyLocal: resolve(homeDirectory, '.hyper_plugins', 'local'),
|
2017-08-21 16:07:50 -08:00
|
|
|
base: plugins,
|
|
|
|
|
local: resolve(plugins, 'local'),
|
|
|
|
|
cache: resolve(plugins, 'cache')
|
|
|
|
|
};
|
|
|
|
|
const yarn = resolve(__dirname, '../../bin/yarn-standalone.js');
|
2018-01-09 06:05:19 -09:00
|
|
|
const cliScriptPath = resolve(__dirname, '../../bin/hyper');
|
2018-04-22 12:13:23 -08:00
|
|
|
const cliLinkPath = '/usr/local/bin/hyper';
|
2017-08-21 16:07:50 -08:00
|
|
|
|
2017-09-22 13:53:49 -08:00
|
|
|
const icon = resolve(__dirname, '../static/icon96x96.png');
|
2017-05-25 22:59:02 -08:00
|
|
|
|
2017-06-02 16:03:47 -08:00
|
|
|
const keymapPath = resolve(__dirname, '../keymaps');
|
|
|
|
|
const darwinKeys = join(keymapPath, 'darwin.json');
|
|
|
|
|
const win32Keys = join(keymapPath, 'win32.json');
|
|
|
|
|
const linuxKeys = join(keymapPath, 'linux.json');
|
|
|
|
|
|
|
|
|
|
const defaultPlatformKeyPath = () => {
|
|
|
|
|
switch (process.platform) {
|
2017-09-10 05:35:10 -08:00
|
|
|
case 'darwin':
|
|
|
|
|
return darwinKeys;
|
|
|
|
|
case 'win32':
|
|
|
|
|
return win32Keys;
|
|
|
|
|
case 'linux':
|
|
|
|
|
return linuxKeys;
|
|
|
|
|
default:
|
|
|
|
|
return darwinKeys;
|
2017-06-02 16:03:47 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-28 05:17:01 -09:00
|
|
|
export {
|
2017-09-10 05:35:10 -08:00
|
|
|
cfgDir,
|
|
|
|
|
cfgPath,
|
2019-05-08 10:56:45 -08:00
|
|
|
legacyCfgPath,
|
2017-09-10 05:35:10 -08:00
|
|
|
cfgFile,
|
|
|
|
|
defaultCfg,
|
|
|
|
|
icon,
|
|
|
|
|
defaultPlatformKeyPath,
|
|
|
|
|
plugs,
|
2018-01-09 06:05:19 -09:00
|
|
|
yarn,
|
2018-04-22 12:13:23 -08:00
|
|
|
cliScriptPath,
|
2019-03-02 13:58:19 -09:00
|
|
|
cliLinkPath,
|
|
|
|
|
homeDirectory
|
2017-05-25 22:59:02 -08:00
|
|
|
};
|