diff --git a/src/atom-environment.js b/src/atom-environment.js index b5a048bc1..13682f3e7 100644 --- a/src/atom-environment.js +++ b/src/atom-environment.js @@ -45,7 +45,7 @@ const TextEditor = require('./text-editor'); const TextBuffer = require('text-buffer'); const TextEditorRegistry = require('./text-editor-registry'); const StartupTime = require('./startup-time'); -const getReleaseChannel = require('./get-release-channel'); +const { getReleaseChannel } = require('./get-app-details.js'); const packagejson = require("../package.json"); const stat = util.promisify(fs.stat); diff --git a/src/get-app-details.js b/src/get-app-details.js new file mode 100644 index 000000000..a0143da2e --- /dev/null +++ b/src/get-app-details.js @@ -0,0 +1,53 @@ + +function getReleaseChannel(version) { + // This matches stable, dev (with or without commit hash) and any other + // release channel following the pattern '1.00.0-channel0' + const match = version.match(/\d+\.\d+\.\d+(-([a-z]+)(\d+|-\w{4,})?)?$/); + if (!match) { + return "unrecognized"; + } else if (match[2]) { + return match[2]; + } + + return "stable"; +} + +function getAppName() { + const { app } = require("electron"); + + if (process.type === "renderer") { + return atom.getAppName(); + } + + const releaseChannel = getReleaseChannel(app.getVersion()); + const appNameParts = [app.getName()]; + + if (releaseChannel !== "stable") { + appNameParts.push( + releaseChannel.charAt(0).toUpperCase() + releaseChannel.slice(1) + ); + } + + return appNameParts.join(" "); +} + +function getConfigFilePath() { + const fs = require("fs"); + const path = require("path"); + + let configFilePath = [ "config.json", "config.cson" ].map(file => + path.join(process.env.ATOM_HOME, file) + ).find(f => fs.existsSync(f)); + + if (configFilePath) { + return configFilePath; + } else { + return null; + } +} + +module.exports = { + getReleaseChannel, + getAppName, + getConfigFilePath, +}; diff --git a/src/get-app-name.js b/src/get-app-name.js deleted file mode 100644 index 5ad814cef..000000000 --- a/src/get-app-name.js +++ /dev/null @@ -1,19 +0,0 @@ -const { app } = require('electron'); -const getReleaseChannel = require('./get-release-channel'); - -module.exports = function getAppName() { - if (process.type === 'renderer') { - return atom.getAppName(); - } - - const releaseChannel = getReleaseChannel(app.getVersion()); - const appNameParts = [app.getName()]; - - if (releaseChannel !== 'stable') { - appNameParts.push( - releaseChannel.charAt(0).toUpperCase() + releaseChannel.slice(1) - ); - } - - return appNameParts.join(' '); -}; diff --git a/src/get-release-channel.js b/src/get-release-channel.js deleted file mode 100644 index e14ec68e2..000000000 --- a/src/get-release-channel.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function(version) { - // This matches stable, dev (with or without commit hash) and any other - // release channel following the pattern '1.00.0-channel0' - const match = version.match(/\d+\.\d+\.\d+(-([a-z]+)(\d+|-\w{4,})?)?$/); - if (!match) { - return 'unrecognized'; - } else if (match[2]) { - return match[2]; - } - - return 'stable'; -}; diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 1f6953fd4..198d3a2bc 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -7,6 +7,7 @@ const ConfigFile = require('../config-file'); const FileRecoveryService = require('./file-recovery-service'); const StartupTime = require('../startup-time'); const ipcHelpers = require('../ipc-helpers'); +const { getConfigFilePath } = require('../get-app-details.js'); const { BrowserWindow, Menu, @@ -207,11 +208,7 @@ module.exports = class AtomApplication extends EventEmitter { this.initializeAtomHome(process.env.ATOM_HOME); - const configFilePath = fs.existsSync( - path.join(process.env.ATOM_HOME, 'config.json') - ) - ? path.join(process.env.ATOM_HOME, 'config.json') - : path.join(process.env.ATOM_HOME, 'config.cson'); + const configFilePath = getConfigFilePath(); this.configFile = ConfigFile.at(configFilePath); this.config = new Config({ diff --git a/src/main-process/atom-window.js b/src/main-process/atom-window.js index 0ca136fae..4343124b6 100644 --- a/src/main-process/atom-window.js +++ b/src/main-process/atom-window.js @@ -5,7 +5,7 @@ const { ipcMain, nativeImage } = require('electron'); -const getAppName = require('../get-app-name'); +const { getAppName } = require('../get-app-details.js'); const path = require('path'); const fs = require('fs'); const url = require('url'); diff --git a/src/main-process/start.js b/src/main-process/start.js index c2021508f..ebccaf938 100644 --- a/src/main-process/start.js +++ b/src/main-process/start.js @@ -2,7 +2,7 @@ const { app } = require('electron'); const path = require('path'); const temp = require('temp'); const parseCommandLine = require('./parse-command-line'); -const getReleaseChannel = require('../get-release-channel'); +const { getReleaseChannel, getConfigFilePath } = require('../get-app-details.js'); const atomPaths = require('../atom-paths'); const fs = require('fs'); const CSON = require('season'); @@ -118,12 +118,7 @@ module.exports = function start(resourcePath, devResourcePath, startTime) { function getConfig() { const config = new Config(); - let configFilePath; - if (fs.existsSync(path.join(process.env.ATOM_HOME, 'config.json'))) { - configFilePath = path.join(process.env.ATOM_HOME, 'config.json'); - } else if (fs.existsSync(path.join(process.env.ATOM_HOME, 'config.cson'))) { - configFilePath = path.join(process.env.ATOM_HOME, 'config.cson'); - } + let configFilePath = getConfigFilePath(); if (configFilePath) { const configFileData = CSON.readFileSync(configFilePath); diff --git a/src/main-process/win-shell.js b/src/main-process/win-shell.js index 27bbaf4f9..b0383ac45 100644 --- a/src/main-process/win-shell.js +++ b/src/main-process/win-shell.js @@ -1,7 +1,7 @@ const Registry = require('winreg'); const Path = require('path'); const ChildProcess = require('child_process'); -const getAppName = require('../get-app-name'); +const { getAppName } = require('../get-app-details.js'); const appName = getAppName(); const exeName = Path.basename(process.execPath); diff --git a/static/index.js b/static/index.js index 9c0ad88a3..3099c2040 100644 --- a/static/index.js +++ b/static/index.js @@ -7,7 +7,7 @@ const path = require('path'); const Module = require('module'); const getWindowLoadSettings = require('../src/get-window-load-settings'); - const getReleaseChannel = require('../src/get-release-channel'); + const { getReleaseChannel } = require('../src/get-app-details.js'); const StartupTime = require('../src/startup-time'); const entryPointDirPath = __dirname; let blobStore = null;