Create get-app-name module that returns correct application name

Before, in order to retrieve the application name, Electron's
`getName()` method was used (https://electronjs.org/docs/api/app#appgetname).

Now, instead, we also use the Atom version in order to calculate the release
channel and be able to have it on the app name (e.g `Atom Nightly`).
This commit is contained in:
Rafael Oleza 2019-07-04 11:26:36 +02:00
parent 0578c0626e
commit f7b7545fd0
5 changed files with 28 additions and 7 deletions

View File

@ -97,7 +97,7 @@ describe('AtomWindow', function() {
const { browserWindow } = w;
assert.isFalse(browserWindow.isVisible());
assert.strictEqual(browserWindow.getTitle(), 'Atom');
assert.isTrue(browserWindow.getTitle().startsWith('Atom'));
const settings = JSON.parse(browserWindow.loadSettingsJSON);
assert.strictEqual(settings.userSettings, 'stub-config');

View File

@ -1,4 +1,5 @@
const { BrowserWindow, app, dialog, ipcMain } = require('electron');
const getAppName = require('./get-app-name');
const path = require('path');
const url = require('url');
const { EventEmitter } = require('events');
@ -35,7 +36,7 @@ module.exports = class AtomWindow extends EventEmitter {
const options = {
show: false,
title: app.getName(),
title: getAppName(),
tabbingIdentifier: 'atom',
webPreferences: {
// Prevent specs from throttling when the window is in the background:
@ -80,7 +81,7 @@ module.exports = class AtomWindow extends EventEmitter {
this.loadSettings = Object.assign({}, settings);
this.loadSettings.appVersion = app.getVersion();
this.loadSettings.appName = app.getName();
this.loadSettings.appName = getAppName();
this.loadSettings.resourcePath = this.resourcePath;
this.loadSettings.atomHome = process.env.ATOM_HOME;
if (this.loadSettings.devMode == null) this.loadSettings.devMode = false;

View File

@ -0,0 +1,15 @@
const { app } = require('electron');
const getReleaseChannel = require('../get-release-channel');
module.exports = function 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,5 +1,6 @@
let setxPath;
const fs = require('fs-plus');
const getAppName = require('./get-app-name');
const path = require('path');
const Spawner = require('./spawner');
const WinShell = require('./win-shell');
@ -182,25 +183,27 @@ exports.restartAtom = app => {
// Handle squirrel events denoted by --squirrel-* command line arguments.
exports.handleStartupEvent = (app, squirrelCommand) => {
const exeName = getExeName(app);
const appName = getAppName();
switch (squirrelCommand) {
case '--squirrel-install':
createShortcuts(exeName, ['Desktop', 'StartMenu'], () =>
addCommandsToPath(exeName, () =>
WinShell.registerShellIntegration(app.getName(), () => app.quit())
WinShell.registerShellIntegration(appName, () => app.quit())
)
);
return true;
case '--squirrel-updated':
updateShortcuts(app.getName(), exeName, () =>
updateShortcuts(appName, exeName, () =>
addCommandsToPath(exeName, () =>
WinShell.updateShellIntegration(app.getName(), () => app.quit())
WinShell.updateShellIntegration(appName, () => app.quit())
)
);
return true;
case '--squirrel-uninstall':
removeShortcuts(exeName, () =>
removeCommandsFromPath(() =>
WinShell.deregisterShellIntegration(app.getName(), () => app.quit())
WinShell.deregisterShellIntegration(appName, () => app.quit())
)
);
return true;

View File

@ -1,5 +1,6 @@
const Registry = require('winreg');
const Path = require('path');
const getAppName = require('./get-app-name');
let exeName = Path.basename(process.execPath);
let appPath = `"${process.execPath}"`;
@ -136,6 +137,7 @@ function deregisterShellIntegration(appName, callback) {
}
module.exports = {
appName: getAppName(),
registerShellIntegration,
updateShellIntegration,
deregisterShellIntegration