Skip to content

Commit 1693732

Browse files
committed
Make first-time setup more user-friendly
1 parent 2b37e4c commit 1693732

File tree

2 files changed

+121
-73
lines changed

2 files changed

+121
-73
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.3.0
2+
* The PHP configuration will no longer be tested on every startup, just when requested
3+
* Made first-time installation a little more user-friendly by requesting user to set up PHP correctly before trying to install core
4+
* Renamed the `php-integrator-base:configuration` command to `php-integrator-base:test-configuration` to better indicate what it does
5+
16
## 3.2.1
27
* Update to core [3.2.1](https://gitlab.com/php-integrator/core/tags/3.2.1)
38
* [Fix busy messages lingering sometimes](https://github.com/php-integrator/atom-base/issues/372)

lib/Main.coffee

Lines changed: 116 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ module.exports =
3232
properties:
3333
phpCommand:
3434
title : 'PHP command'
35-
description : 'The path to your PHP binary (e.g. /usr/bin/php, php, ...).
36-
Requires a restart after changing.'
35+
description : 'The path to your PHP binary (e.g. /usr/bin/php, php, ...). Requires a restart after
36+
changing. You can also use the php-integrator-base:test-configuration command to
37+
test it.'
3738
type : 'string'
3839
default : 'php'
3940
order : 1
@@ -284,38 +285,21 @@ module.exports =
284285

285286
###*
286287
* Tests the user's configuration.
287-
*
288-
* @param {bool} testServices
289-
*
290-
* @return {bool}
291288
###
292-
testConfig: (testServices = true) ->
289+
testConfig: () ->
293290
configTester = new ConfigTester(@getConfiguration())
294291

295-
result = configTester.test()
296-
297-
if not result
298-
errorMessage =
299-
"PHP is not correctly set up and as a result PHP integrator will not work. Please visit the settings
300-
screen to correct this error. If you are not specifying an absolute path for PHP or Composer, make
301-
sure they are in your PATH.
302-
303-
Please restart Atom after correcting the path."
304-
305-
atom.notifications.addError('Incorrect setup!', {'detail': errorMessage})
306-
307-
return false
308-
309-
if testServices and not @projectManagerService?
292+
if not configTester.test()
310293
errorMessage =
311-
"There is no project manager service available. Install the atom-project-manager package for project
312-
support to work in its full extent."
313-
314-
atom.notifications.addError('Incorrect setup!', {'detail': errorMessage})
294+
"PHP is not configured correctly. Please visit the settings screen to correct this error. If you are
295+
using a relative path to PHP, make sure it is in your PATH variable."
315296

316-
return false
297+
atom.notifications.addError('PHP Integrator - Failure', {dismissable: true, detail: errorMessage})
317298

318-
return true
299+
atom.notifications.addSuccess 'PHP Integrator - Success', {
300+
dismissable: true,
301+
detail: 'Your setup is working correctly.'
302+
}
319303

320304
###*
321305
* Registers any commands that are available to the user.
@@ -377,12 +361,8 @@ module.exports =
377361

378362
@performInitialFullIndexForCurrentProject()
379363

380-
atom.commands.add 'atom-workspace', "php-integrator-base:configuration": =>
381-
return unless @testConfig()
382-
383-
atom.notifications.addSuccess 'Success', {
384-
'detail' : 'Your PHP integrator configuration is working correctly!'
385-
}
364+
atom.commands.add 'atom-workspace', "php-integrator-base:test-configuration": =>
365+
@testConfig()
386366

387367
atom.commands.add 'atom-workspace', "php-integrator-base:sort-use-statements": =>
388368
activeTextEditor = atom.workspace.getActiveTextEditor()
@@ -497,41 +477,93 @@ module.exports =
497477
###*
498478
* @return {Promise}
499479
###
500-
updateCoreIfOutdated: () ->
501-
if @getCoreManager().isInstalled()
502-
return new Promise (resolve, reject) ->
480+
installCoreIfNecessary: () ->
481+
return new Promise (resolve, reject) =>
482+
if @getCoreManager().isInstalled()
503483
resolve()
484+
return
485+
486+
message =
487+
"The core isn't installed yet or is outdated. I can install the latest version for you " +
488+
"automatically.\n \n" +
489+
490+
"First time using this package? Please visit the package settings to set up PHP correctly first."
491+
492+
notification = atom.notifications.addInfo('PHP Integrator - Core Installation', {
493+
detail : message
494+
dismissable : true
495+
496+
buttons: [
497+
{
498+
text: 'Open package settings'
499+
onDidClick: () =>
500+
atom.workspace.open('atom://config/packages/' + @packageName)
501+
},
502+
503+
{
504+
text: 'Test my setup'
505+
onDidClick: () =>
506+
@testConfig()
507+
},
508+
509+
{
510+
text: 'Ready, install the core'
511+
onDidClick: () =>
512+
notification.dismiss()
513+
514+
promise = @installCore()
515+
516+
promise.then () =>
517+
resolve()
518+
519+
promise.catch () =>
520+
reject(new Error('Core installation failed'))
521+
},
522+
523+
{
524+
text: 'No, go away'
525+
onDidClick: () =>
526+
notification.dismiss()
527+
reject()
528+
}
529+
]
530+
})
504531

532+
###*
533+
* @return {Promise}
534+
###
535+
installCore: () ->
505536
message =
506-
"The core isn't installed yet or is outdated. A new version is in the process of being downloaded.\n \n" +
537+
"The core is being downloaded and installed. To do this, Composer is automatically downloaded and " +
538+
"installed into a temporary folder.\n \n" +
507539

508-
"Progress is being sent to the developer tools console, in case you'd like to monitor it.\n \n" +
540+
"Progress and output is sent to the developer tools console, in case you'd like to monitor it.\n \n" +
509541

510542
"You will be notified once the install finishes (or fails)."
511543

512-
atom.notifications.addInfo('PHP Integrator - Downloading Core', {'detail': message, dismissable: true})
544+
atom.notifications.addInfo('PHP Integrator - Installing Core', {'detail': message, dismissable: true})
513545

514546
successHandler = () ->
515-
atom.notifications.addSuccess('Core installation successful', dismissable: true)
547+
atom.notifications.addSuccess('PHP Integrator - Core Installation Succeeded', dismissable: true)
516548

517549
failureHandler = () ->
518550
message =
519-
"The core failed to install. This can happen for a variety of reasons, such as an outdated PHP " +
551+
"Installation of the core failed. This can happen for a variety of reasons, such as an outdated PHP " +
520552
"version or missing extensions.\n \n" +
521553

522554
"Logs in the developer tools will likely provide you with more information about what is wrong. You " +
523555
"can open it via the menu View → Developer → Toggle Developer Tools.\n \n" +
524556

525557
"Additionally, the README provides more information about requirements and troubleshooting."
526558

527-
atom.notifications.addError('Core installation failed', {detail: message, dismissable: true})
559+
atom.notifications.addError('PHP Integrator - Core Installation Failed', {detail: message, dismissable: true})
528560

529-
return @getCoreManager().install().then(successHandler, failureHandler)
561+
@getCoreManager().install().then(successHandler, failureHandler)
530562

531563
###*
532564
* Checks if the php-integrator-navigation package is installed and notifies the user it is obsolete if it is.
533565
###
534-
notifyAboutRedundantNavigationPackageIfnecessary: () ->
566+
notifyAboutRedundantNavigationPackageIfNecessary: () ->
535567
atom.packages.onDidActivatePackage (packageData) ->
536568
return if packageData.name != 'php-integrator-navigation'
537569

@@ -565,7 +597,7 @@ module.exports =
565597
* Checks if the php-integrator-autocomplete-plus package is installed and notifies the user it is obsolete if it
566598
* is.
567599
###
568-
notifyAboutRedundantAutocompletionPackageIfnecessary: () ->
600+
notifyAboutRedundantAutocompletionPackageIfNecessary: () ->
569601
atom.packages.onDidActivatePackage (packageData) ->
570602
return if packageData.name != 'php-integrator-autocomplete-plus'
571603

@@ -599,44 +631,55 @@ module.exports =
599631
* Activates the package.
600632
###
601633
activate: ->
602-
packageDeps.install(@packageName, true).then () =>
603-
return if not @testConfig(false)
634+
return packageDeps.install(@packageName, true).then () =>
635+
promise = @installCoreIfNecessary()
604636

605-
@updateCoreIfOutdated().then () =>
606-
@notifyAboutRedundantNavigationPackageIfnecessary()
607-
@notifyAboutRedundantAutocompletionPackageIfnecessary()
637+
promise.then () =>
638+
@doActivate()
639+
640+
promise.catch () =>
641+
return
642+
643+
return promise
644+
645+
###*
646+
* Does the actual activation.
647+
###
648+
doActivate: () ->
649+
@notifyAboutRedundantNavigationPackageIfNecessary()
650+
@notifyAboutRedundantAutocompletionPackageIfNecessary()
608651

609-
@registerCommands()
610-
@registerConfigListeners()
611-
@registerStatusBarListeners()
652+
@registerCommands()
653+
@registerConfigListeners()
654+
@registerStatusBarListeners()
612655

613-
@editorTimeoutMap = {}
656+
@editorTimeoutMap = {}
614657

615-
@registerAtomListeners()
658+
@registerAtomListeners()
616659

617-
if @getConfiguration().get('datatips.enable')
618-
@activateDatatips()
660+
if @getConfiguration().get('datatips.enable')
661+
@activateDatatips()
619662

620-
if @getConfiguration().get('signatureHelp.enable')
621-
@activateSignatureHelp()
663+
if @getConfiguration().get('signatureHelp.enable')
664+
@activateSignatureHelp()
622665

623-
if @getConfiguration().get('linting.enable')
624-
@activateLinting()
666+
if @getConfiguration().get('linting.enable')
667+
@activateLinting()
625668

626-
if @getConfiguration().get('gotoDefinition.enable')
627-
@activateGotoDefinition()
669+
if @getConfiguration().get('gotoDefinition.enable')
670+
@activateGotoDefinition()
628671

629-
if @getConfiguration().get('autocompletion.enable')
630-
@activateAutocompletion()
672+
if @getConfiguration().get('autocompletion.enable')
673+
@activateAutocompletion()
631674

632-
@getProxy().setIsActive(true)
675+
@getProxy().setIsActive(true)
633676

634-
# This fixes the corner case where the core is still installing, the project manager service has already
635-
# loaded and the project is already active. At that point, the index that resulted from it silently
636-
# failed because the proxy (and core) weren't active yet. This in turn causes the project to not
637-
# automatically start indexing, which is especially relevant if a core update requires a reindex.
638-
if @activeProject?
639-
@changeActiveProject(@activeProject)
677+
# This fixes the corner case where the core is still installing, the project manager service has already
678+
# loaded and the project is already active. At that point, the index that resulted from it silently
679+
# failed because the proxy (and core) weren't active yet. This in turn causes the project to not
680+
# automatically start indexing, which is especially relevant if a core update requires a reindex.
681+
if @activeProject?
682+
@changeActiveProject(@activeProject)
640683

641684
###*
642685
* Registers listeners for events from Atom's API.

0 commit comments

Comments
 (0)