Skip to content

Commit

Permalink
Get server installation working again
Browse files Browse the repository at this point in the history
References #460
  • Loading branch information
Gert-dev committed Jun 2, 2019
1 parent 7ed4b4e commit 7474a3f
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 178 deletions.
178 changes: 2 additions & 176 deletions lib/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
*/
const {CompositeDisposable} = require('atom');

const packageDeps = require('atom-package-deps');

const fs = require('fs');
const process = require('process');

const Proxy = require('./Proxy');
const AtomConfig = require('./AtomConfig');
const PhpInvoker = require('./PhpInvoker');
const ConfigTester = require('./ConfigTester');
const ServerManager = require('./ServerManager');
const ProjectManager = require('./ProjectManager');
const ComposerService = require('./ComposerService');
Expand All @@ -28,7 +25,7 @@ const functions = {
*
* @var {String}
*/
serverVersionSpecification: '4.3.1',
serverVersionSpecification: '5.0.0-RC',

/**
* The name of the package.
Expand Down Expand Up @@ -115,52 +112,10 @@ const functions = {
*/
linterProvider: null,

/**
* Tests the user's configuration.
*/
testConfig() {
const configTester = new ConfigTester(this.getPhpInvoker());

atom.notifications.addInfo('Serenata - Testing Configuration', {
dismissable: true,
detail: 'Now testing your configuration... \n \n' +

`If you've selected Docker, this may take a while the first time as the Docker image has to be ` +
`fetched first.`
});

const callback = () => {
return configTester.test().then(wasSuccessful => {
if (!wasSuccessful) {
const errorMessage =
`PHP is not configured correctly. Please visit the settings screen to correct this error. ` +
`If you are using a relative path to PHP, make sure it is in your PATH variable.`;

return atom.notifications.addError('Serenata - Failure', {dismissable: true, detail: errorMessage});

} else {
return atom.notifications.addSuccess('Serenata - Success', {
dismissable: true,
detail: 'Your setup is working correctly.'
});
}
});
};

return this.busySignalService.reportBusyWhile('Testing your configuration...', callback, {
waitingFor : 'computer',
revealTooltip : false
});
},

/**
* Registers any commands that are available to the user.
*/
registerCommands() {
atom.commands.add('atom-workspace', { 'php-ide-serenata:test-configuration': () => {
return this.testConfig();
}});

return atom.commands.add('atom-workspace', { 'php-ide-serenata:sort-use-statements': () => {
const activeTextEditor = atom.workspace.getActiveTextEditor();

Expand All @@ -170,118 +125,6 @@ const functions = {
}});
},

/**
* @return {Promise}
*/
installServerIfNecessary() {
return new Promise((resolve, reject) => {
let notification;
if (this.getServerManager().isInstalled()) {
resolve();
return;
}

const message =
'The server isn\'t installed yet or is outdated. I can install the latest version for you ' +
'automatically.\n \n' +

'First time using this package? Please visit the package settings to set up PHP correctly first.';

return notification = atom.notifications.addInfo('Serenata - Server Installation', {
detail : message,
dismissable : true,

buttons: [
{
text: 'Open package settings',
onDidClick: () => {
return atom.workspace.open(`atom://config/packages/${this.packageName}`);
}
},

{
text: 'Test my setup',
onDidClick: () => {
return this.testConfig();
}
},

{
text: 'Ready, install the server',
onDidClick: () => {
notification.dismiss();

const callback = () => {
const promise = this.installServer();

promise.catch(() => {
return reject(new Error('Server installation failed'));
});

return promise.then(() => {
return resolve();
});
};

if (this.busySignalService) {
return this.busySignalService.reportBusyWhile('Installing the server...', callback, {
waitingFor : 'computer',
revealTooltip : false
});

} else {
return console.warn(
'Busy signal service not loaded yet whilst installing server, not showing ' +
'loading spinner'
);
}
}
},

{
text: 'No, go away',
onDidClick: () => {
notification.dismiss();
return reject();
}
}
]
});
});
},

/**
* @return {Promise}
*/
installServer() {
let message =
'The server is being downloaded and installed. To do this, Composer is automatically downloaded and ' +
'installed into a temporary folder.\n \n' +

'Progress and output is sent to the developer tools console, in case you\'d like to monitor it.\n \n' +

'You will be notified once the install finishes (or fails).';

atom.notifications.addInfo('Serenata - Installing Server', {'detail': message, dismissable: true});

const successHandler = () => atom.notifications.addSuccess('Serenata - Server Installation Succeeded', {dismissable: true});

const failureHandler = function() {
message =
'Installation of the server failed. This can happen for a variety of reasons, such as an outdated ' +
'PHP version or missing extensions.\n \n' +

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

'Additionally, the README provides more information about requirements and troubleshooting.';

return atom.notifications.addError('Serenata - Server Installation Failed', {detail: message, dismissable: true});
};

return this.getServerManager().install().then(successHandler, failureHandler);
},

/**
* Shows a notification informing about support.
*/
Expand Down Expand Up @@ -355,24 +198,6 @@ const functions = {
});
},

/**
* Activates the package.
*/
activate() {
return packageDeps.install(this.packageName, true).then(() => {
const promise = this.installServerIfNecessary();

promise.then(() => {
return this.doActivate();
});

promise.catch(() => {
});

return promise;
});
},

/**
* @return {Service}
*/
Expand Down Expand Up @@ -487,6 +312,7 @@ const SerenataClient = require('./SerenataClient');
const client = new SerenataClient(
functions.getProxy(),
functions.getProjectManager(),
functions.getServerManager(),
functions.getPhpInvoker(),
functions.getConfiguration()
);
Expand Down
Loading

0 comments on commit 7474a3f

Please sign in to comment.