Skip to content

Commit eb7f0aa

Browse files
committed
Produce channel-specific Atom .exe and .cmd files on Windows
1 parent ab3c942 commit eb7f0aa

8 files changed

Lines changed: 120 additions & 88 deletions

File tree

‎script/config.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ const apmMetadata = require(path.join(apmRootPath, 'package.json'))
2323
const computedAppVersion = computeAppVersion(process.env.ATOM_RELEASE_VERSION || appMetadata.version)
2424
const channel = getChannel(computedAppVersion)
2525
const appName = getAppName(channel)
26+
const executableName = getExecutableName(channel, appName)
2627

2728
module.exports = {
2829
appMetadata,
2930
apmMetadata,
3031
channel,
3132
appName,
33+
executableName,
3234
computedAppVersion,
3335
repositoryRootPath,
3436
apmRootPath,
@@ -62,6 +64,16 @@ function getAppName (channel) {
6264
: `Atom ${process.env.ATOM_CHANNEL_DISPLAY_NAME || channel.charAt(0).toUpperCase() + channel.slice(1)}`
6365
}
6466

67+
function getExecutableName (channel, appName) {
68+
if (process.platform === 'darwin') {
69+
return appName
70+
} else if (process.platform === 'win32') {
71+
return channel === 'stable' ? 'atom.exe' : `atom-${channel}.exe`
72+
} else {
73+
return 'atom'
74+
}
75+
}
76+
6577
function computeAppVersion (version) {
6678
if (version.match(/-dev$/)) {
6779
const result = spawnSync('git', ['rev-parse', '--short', 'HEAD'], {cwd: repositoryRootPath})

‎script/lib/create-windows-installer.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const CONFIG = require('../config')
1010
module.exports = (packagedAppPath) => {
1111
const archSuffix = process.arch === 'ia32' ? '' : '-' + process.arch
1212
const options = {
13-
exe: 'atom.exe',
1413
title: CONFIG.appName,
1514
appDirectory: packagedAppPath,
1615
authors: 'GitHub Inc.',

‎script/lib/generate-startup-snapshot.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ module.exports = function (packagedAppPath) {
8484
const verifySnapshotScriptPath = path.join(CONFIG.repositoryRootPath, 'script', 'verify-snapshot-script')
8585
let nodeBundledInElectronPath
8686
if (process.platform === 'darwin') {
87-
const executableName = CONFIG.appName
88-
nodeBundledInElectronPath = path.join(packagedAppPath, 'Contents', 'MacOS', executableName)
89-
} else if (process.platform === 'win32') {
90-
nodeBundledInElectronPath = path.join(packagedAppPath, 'atom.exe')
87+
nodeBundledInElectronPath = path.join(packagedAppPath, 'Contents', 'MacOS', CONFIG.executableName)
9188
} else {
92-
nodeBundledInElectronPath = path.join(packagedAppPath, 'atom')
89+
nodeBundledInElectronPath = path.join(packagedAppPath, CONFIG.executableName)
9390
}
9491
childProcess.execFileSync(
9592
nodeBundledInElectronPath,

‎script/lib/package-application.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ function buildAsarUnpackGlobExpression () {
115115
function getAppName () {
116116
if (process.platform === 'darwin') {
117117
return CONFIG.appName
118+
} else if (process.platform === 'win32') {
119+
return CONFIG.channel === 'stable' ? 'atom' : `atom-${CONFIG.channel}`
118120
} else {
119121
return 'atom'
120122
}

‎script/test‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (process.platform === 'darwin') {
2626
assert(executablePaths.length === 1, `More than one application to run tests against was found. ${executablePaths.join(',')}`)
2727
executablePath = executablePaths[0]
2828
} else if (process.platform === 'win32') {
29-
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, '**', 'atom.exe'))
29+
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, '**', CONFIG.executableName))
3030
assert(executablePaths.length === 1, `More than one application to run tests against was found. ${executablePaths.join(',')}`)
3131
executablePath = executablePaths[0]
3232
} else {

‎spec/squirrel-update-spec.js‎

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ const invokeCallback = function(callback) {
1313
return (typeof callback === 'function' ? callback(error, stdout) : undefined);
1414
};
1515

16+
const createFakeApp = function() {
17+
return {
18+
quit: jasmine.createSpy('quit'),
19+
getName: () => AtomTestAppName,
20+
getPath: () => 'atom-test.exe'
21+
};
22+
}
23+
1624
const AtomTestAppName = 'Atom Testing'
1725

18-
describe("Windows Squirrel Update", function() {
26+
fdescribe("Windows Squirrel Update", function() {
1927
let tempHomeDirectory = null;
2028

2129
beforeEach(function() {
@@ -30,16 +38,9 @@ describe("Windows Squirrel Update", function() {
3038
);
3139

3240
// Prevent any actual change to Windows Shell
33-
class FakeShellOption {
34-
isRegistered(callback) { return callback(true); }
35-
register(callback) { return callback(null); }
36-
deregister(callback) { return callback(null, true); }
37-
update(callback) { return callback(null); }
38-
}
39-
WinShell.fileHandler = new FakeShellOption();
40-
WinShell.fileContextMenu = new FakeShellOption();
41-
WinShell.folderContextMenu = new FakeShellOption();
42-
return WinShell.folderBackgroundContextMenu = new FakeShellOption();
41+
spyOn(WinShell, 'registerShellIntegration').andCallFake((appName, callback) => callback())
42+
spyOn(WinShell, 'updateShellIntegration').andCallFake((appName, callback) => callback())
43+
spyOn(WinShell, 'deregisterShellIntegration').andCallFake((appName, callback) => callback())
4344
});
4445

4546
afterEach(function() {
@@ -49,10 +50,7 @@ describe("Windows Squirrel Update", function() {
4950
});
5051

5152
it("quits the app on all squirrel events", function() {
52-
const app = {
53-
quit: jasmine.createSpy('quit'),
54-
getName: () => AtomTestAppName
55-
};
53+
const app = createFakeApp()
5654

5755
expect(SquirrelUpdate.handleStartupEvent(app, '--squirrel-install')).toBe(true);
5856

@@ -104,7 +102,7 @@ describe("Windows Squirrel Update", function() {
104102

105103
return describe("on install", function() {
106104
beforeEach(function() {
107-
const app = {quit: jasmine.createSpy('quit')};
105+
const app = createFakeApp()
108106
SquirrelUpdate.handleStartupEvent(app, '--squirrel-install');
109107
return waitsFor(() => app.quit.callCount === 1);
110108
});
@@ -116,10 +114,7 @@ describe("Windows Squirrel Update", function() {
116114
fs.removeSync(desktopShortcutPath);
117115
expect(fs.existsSync(desktopShortcutPath)).toBe(false);
118116

119-
const app = {
120-
quit: jasmine.createSpy('quit'),
121-
getName: () => AtomTestAppName
122-
};
117+
const app = createFakeApp()
123118
SquirrelUpdate.handleStartupEvent(app, '--squirrel-updated');
124119
return waitsFor(() => app.quit.callCount === 1);
125120
});
@@ -129,10 +124,7 @@ describe("Windows Squirrel Update", function() {
129124

130125
return describe("when shortcut is kept and app is updated", function() {
131126
beforeEach(function() {
132-
const app = {
133-
quit: jasmine.createSpy('quit'),
134-
getName: () => AtomTestAppName
135-
};
127+
const app = createFakeApp()
136128
SquirrelUpdate.handleStartupEvent(app, '--squirrel-updated');
137129
return waitsFor(() => app.quit.callCount === 1);
138130
});
@@ -146,14 +138,15 @@ describe("Windows Squirrel Update", function() {
146138
it("quits the app and spawns a new one", function() {
147139
const app = new EventEmitter();
148140
app.quit = jasmine.createSpy('quit');
141+
app.getPath = () => 'atom-test.exe'
149142

150143
SquirrelUpdate.restartAtom(app);
151144
expect(app.quit.callCount).toBe(1);
152145

153146
expect(Spawner.spawn.callCount).toBe(0);
154147
app.emit('will-quit');
155148
expect(Spawner.spawn.callCount).toBe(1);
156-
return expect(path.basename(Spawner.spawn.argsForCall[0][0])).toBe('atom.cmd');
149+
return expect(path.basename(Spawner.spawn.argsForCall[0][0])).toBe('atom-test.cmd');
157150
})
158151
);
159152
});

‎src/main-process/squirrel-update.js‎

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const appFolder = path.resolve(process.execPath, '..')
99
const rootAtomFolder = path.resolve(appFolder, '..')
1010
const binFolder = path.join(rootAtomFolder, 'bin')
1111
const updateDotExe = path.join(rootAtomFolder, 'Update.exe')
12-
const exeName = path.basename(process.execPath)
1312

1413
if (process.env.SystemRoot) {
1514
const system32Path = path.join(process.env.SystemRoot, 'System32')
@@ -30,17 +29,20 @@ const spawnUpdate = (args, callback) => Spawner.spawn(updateDotExe, args, callba
3029
// This is done by adding .cmd shims to the root bin folder in the Atom
3130
// install directory that point to the newly installed versions inside
3231
// the versioned app directories.
33-
const addCommandsToPath = callback => {
32+
const addCommandsToPath = (exeName, callback) => {
33+
const atomCmdName = exeName.replace('.exe', '.cmd')
34+
const apmCmdName = atomCmdName.replace('atom', 'apm')
35+
3436
const installCommands = callback => {
35-
const atomCommandPath = path.join(binFolder, 'atom.cmd')
37+
const atomCommandPath = path.join(binFolder, atomCmdName)
3638
const relativeAtomPath = path.relative(binFolder, path.join(appFolder, 'resources', 'cli', 'atom.cmd'))
3739
const atomCommand = `@echo off\r\n\"%~dp0\\${relativeAtomPath}\" %*`
3840

3941
const atomShCommandPath = path.join(binFolder, 'atom')
4042
const relativeAtomShPath = path.relative(binFolder, path.join(appFolder, 'resources', 'cli', 'atom.sh'))
4143
const atomShCommand = `#!/bin/sh\r\n\"$(dirname \"$0\")/${relativeAtomShPath.replace(/\\/g, '/')}\" \"$@\"\r\necho`
4244

43-
const apmCommandPath = path.join(binFolder, 'apm.cmd')
45+
const apmCommandPath = path.join(binFolder, apmCmdName)
4446
const relativeApmPath = path.relative(binFolder, path.join(process.resourcesPath, 'app', 'apm', 'bin', 'apm.cmd'))
4547
const apmCommand = `@echo off\r\n\"%~dp0\\${relativeApmPath}\" %*`
4648

@@ -94,32 +96,35 @@ const removeCommandsFromPath = callback =>
9496
}
9597
})
9698

99+
const getExeName = (app) => path.basename(app.getPath('exe'))
100+
97101
// Create a desktop and start menu shortcut by using the command line API
98102
// provided by Squirrel's Update.exe
99-
const createShortcuts = (locations, callback) => spawnUpdate(['--createShortcut', exeName, '-l', locations.join(',')], callback)
103+
const createShortcuts = (exeName, locations, callback) =>
104+
spawnUpdate(['--createShortcut', exeName, '-l', locations.join(',')], callback)
100105

101106
// Update the desktop and start menu shortcuts by using the command line API
102107
// provided by Squirrel's Update.exe
103-
const updateShortcuts = (app, callback) => {
108+
const updateShortcuts = (appName, exeName, callback) => {
104109
const homeDirectory = fs.getHomeDirectory()
105110
if (homeDirectory) {
106-
const desktopShortcutPath = path.join(homeDirectory, 'Desktop', `${app.getName()}.lnk`)
111+
const desktopShortcutPath = path.join(homeDirectory, 'Desktop', `${appName}.lnk`)
107112
// Check if the desktop shortcut has been previously deleted and
108113
// and keep it deleted if it was
109114
fs.exists(desktopShortcutPath, (desktopShortcutExists) => {
110115
const locations = ['StartMenu']
111116
if (desktopShortcutExists) { locations.push('Desktop') }
112117

113-
createShortcuts(locations, callback)
118+
createShortcuts(exeName, locations, callback)
114119
})
115120
} else {
116-
createShortcuts(['Desktop', 'StartMenu'], callback)
121+
createShortcuts(exeName, ['Desktop', 'StartMenu'], callback)
117122
}
118123
}
119124

120125
// Remove the desktop and start menu shortcuts by using the command line API
121126
// provided by Squirrel's Update.exe
122-
const removeShortcuts = callback => spawnUpdate(['--removeShortcut', exeName], callback)
127+
const removeShortcuts = (exeName, callback) => spawnUpdate(['--removeShortcut', exeName], callback)
123128

124129
exports.spawn = spawnUpdate
125130

@@ -129,52 +134,38 @@ exports.existsSync = () => fs.existsSync(updateDotExe)
129134
// Restart Atom using the version pointed to by the atom.cmd shim
130135
exports.restartAtom = (app) => {
131136
let args
137+
const exeName = getExeName(app)
138+
const atomCmdName = exeName.replace('.exe', '.cmd')
132139
if (global.atomApplication && global.atomApplication.lastFocusedWindow) {
133140
const {projectPath} = global.atomApplication.lastFocusedWindow
134141
if (projectPath) args = [projectPath]
135142
}
136-
app.once('will-quit', () => Spawner.spawn(path.join(binFolder, 'atom.cmd'), args))
143+
app.once('will-quit', () => Spawner.spawn(path.join(binFolder, atomCmdName), args))
137144
app.quit()
138145
}
139146

140-
const updateContextMenus = callback =>
141-
WinShell.fileContextMenu.update(() =>
142-
WinShell.folderContextMenu.update(() =>
143-
WinShell.folderBackgroundContextMenu.update(() => callback())
144-
)
145-
)
146-
147147
// Handle squirrel events denoted by --squirrel-* command line arguments.
148148
exports.handleStartupEvent = (app, squirrelCommand) => {
149+
const exeName = getExeName(app)
149150
switch (squirrelCommand) {
150151
case '--squirrel-install':
151-
createShortcuts(['Desktop', 'StartMenu'], () =>
152-
addCommandsToPath(() =>
153-
WinShell.fileHandler.register(() =>
154-
updateContextMenus(() => app.quit())
155-
)
152+
createShortcuts(exeName, ['Desktop', 'StartMenu'], () =>
153+
addCommandsToPath(exeName, () =>
154+
WinShell.registerShellIntegration(app.getName(), () => app.quit())
156155
)
157156
)
158157
return true
159158
case '--squirrel-updated':
160-
updateShortcuts(app, () =>
161-
addCommandsToPath(() =>
162-
WinShell.fileHandler.update(() =>
163-
updateContextMenus(() => app.quit())
164-
)
159+
updateShortcuts(app.getName(), exeName, () =>
160+
addCommandsToPath(exeName, () =>
161+
WinShell.updateShellIntegration(app.getName(), () => app.quit())
165162
)
166163
)
167164
return true
168165
case '--squirrel-uninstall':
169-
removeShortcuts(() =>
166+
removeShortcuts(exeName, () =>
170167
removeCommandsFromPath(() =>
171-
WinShell.fileHandler.deregister(() =>
172-
WinShell.fileContextMenu.deregister(() =>
173-
WinShell.folderContextMenu.deregister(() =>
174-
WinShell.folderBackgroundContextMenu.deregister(() => app.quit())
175-
)
176-
)
177-
)
168+
WinShell.deregisterShellIntegration(app.getName(), () => app.quit())
178169
)
179170
)
180171
return true

0 commit comments

Comments
 (0)