Migrate to getAppDetails()

Remove both `getAppName` and `getReleaseChannel` into `getAppDetails`. Move consumers over to new module. Rewrite config file path logic into shorter function, and move known users of this logic to new module
This commit is contained in:
confused-Techie 2023-09-03 14:50:39 -07:00
parent 2b4b216830
commit 03f2c30ee9
9 changed files with 61 additions and 47 deletions

View File

@ -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);

53
src/get-app-details.js Normal file
View File

@ -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,
};

View File

@ -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(' ');
};

View File

@ -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';
};

View File

@ -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({

View File

@ -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');

View File

@ -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);

View File

@ -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);

View File

@ -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;