diff --git a/electron/docker.js b/electron/docker.js deleted file mode 100644 index 2f388b803..000000000 --- a/electron/docker.js +++ /dev/null @@ -1,27 +0,0 @@ -const Docker = require('dockerode'); - -const connectionRefusedCode = 'ECONNREFUSED'; - -const docker = new Docker( - process.platform === 'win32' - ? { socketPath: '//./pipe/docker_engine' } - : { socketPath: '/var/run/docker.sock' }, -); - -function isDockerRunning() { - return new Promise((resolve, reject) => { - docker.ping((err) => { - if (err) { - if (err.code === connectionRefusedCode) { - resolve(false); // Docker is not running - } else { - reject(err); // Error other than connection refused - } - } else { - resolve(true); // Docker is running - } - }); - }); -} - -module.exports = { isDockerRunning }; diff --git a/electron/install.js b/electron/install.js index ec03340c8..18c0ff385 100644 --- a/electron/install.js +++ b/electron/install.js @@ -5,6 +5,7 @@ const os = require('os'); const sudo = require('sudo-prompt'); const process = require('process'); const { spawnSync } = require('child_process'); +const Docker = require('dockerode'); const OperateDirectory = `${os.homedir()}/.operate`; @@ -267,8 +268,38 @@ async function setupUbuntu(ipcChannel) { await installOperateCli('/usr/local/bin') } + +async function startDocker(ipcChannel) { + const docker = new Docker(); + let running = await new Promise((resolve, reject) => { + docker.ping((err) => { + resolve(!err) + }); + }); + if (!running) { + console.log(appendLog("Starting docker")) + ipcChannel.send("response", "Starting docker") + if (process.platform == "darwin") { + runCmdUnix("open", ["-a", "Docker"]) + } else if (process.platform == "win32") { + // TODO + } else { + runSudoUnix("sudo", ["service", "docker", "restart"]) + } + } + while (!running) { + running = await new Promise((resolve, reject) => { + docker.ping((err) => { + resolve(!err) + }); + }); + }; +} + + module.exports = { setupDarwin, + startDocker, setupUbuntu, OperateDirectory, OperateCmd, diff --git a/electron/main.js b/electron/main.js index 6dad2ad98..31df40ae0 100644 --- a/electron/main.js +++ b/electron/main.js @@ -20,6 +20,7 @@ const { setupUbuntu, OperateCmd, OperateDirectory, + startDocker } = require('./install'); const { killProcesses } = require('./processes'); const { isPortAvailable, findAvailablePort } = require('./ports'); @@ -267,6 +268,9 @@ async function launchNextAppDev() { ipcMain.on('check', async function (event, argument) { try { + + + event.sender.send('response', 'Checking installation'); if (!isDev) { if (platform === 'darwin') { @@ -278,6 +282,8 @@ ipcMain.on('check', async function (event, argument) { } } + startDocker(event.sender) + if (isDev) { event.sender.send( 'response',