Skip to content

Commit

Permalink
feat: add support for launching docker daemon at start if not running
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Mar 29, 2024
1 parent 90bfd17 commit d9623b0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
27 changes: 0 additions & 27 deletions electron/docker.js

This file was deleted.

31 changes: 31 additions & 0 deletions electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
setupUbuntu,
OperateCmd,
OperateDirectory,
startDocker
} = require('./install');
const { killProcesses } = require('./processes');
const { isPortAvailable, findAvailablePort } = require('./ports');
Expand Down Expand Up @@ -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') {
Expand All @@ -278,6 +282,8 @@ ipcMain.on('check', async function (event, argument) {
}
}

startDocker(event.sender)

if (isDev) {
event.sender.send(
'response',
Expand Down

0 comments on commit d9623b0

Please sign in to comment.