Skip to content

Commit

Permalink
Added flatpak-spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeraKai committed Sep 14, 2023
1 parent 3356278 commit 1ab80c9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@
"args": true
},
{
"name": "/var/run/host/usr/local/bin/docker",
"cmd": "/var/run/host/usr/local/bin/docker",
"name": "docker",
"cmd": "docker",
"args": true
},
{
"name": "flatpak-spawn",
"cmd": "flatpak-spawn",
"args": true
},
{
Expand Down
40 changes: 33 additions & 7 deletions src/services/docker_frontends.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const fs = window.__TAURI__.fs;
let frontendsProcessesDocker = []

async function docker_command(name, action) {
return new shell.Command('/var/run/host/usr/local/bin/docker', ['compose', '-f', `${name}.yml`, action], { cwd: await path.join(await path.appLocalDataDir(), 'docker_compose') })
if (await fs.exists('/usr/bin/flatpak-spawn')) {
return new shell.Command('flatpak-spawn', ['--host', 'docker', 'compose', '-f', `${name}.yml`, action], { cwd: await path.join(await path.appLocalDataDir(), 'docker_compose') })
} else {
return new shell.Command('docker', ['compose', '-f', `${name}.yml`, action], { cwd: await path.join(await path.appLocalDataDir(), 'docker_compose') })
}
}

async function download_frontend(name) {
Expand Down Expand Up @@ -48,10 +52,19 @@ async function check_downloaded(name) {
resolve('not_downloaded')
return
}
const cmd = new shell.Command(
'/var/run/host/usr/local/bin/docker', ['ps', '-a', '--format', 'json', '--filter', `name=${name}`],
{ cwd: await path.join(await path.appLocalDataDir(), 'docker_compose') }
)
let cmd
if (await fs.exists('/usr/bin/flatpak-spawn')) {
cmd = new shell.Command(
'flatpak-spawn', ['--host', 'docker', 'ps', '-a', '--format', 'json', '--filter', `name=${name}`],
{ cwd: await path.join(await path.appLocalDataDir(), 'docker_compose') }
)
} else {
cmd = new shell.Command(
'docker', ['ps', '-a', '--format', 'json', '--filter', `name=${name}`],
{ cwd: await path.join(await path.appLocalDataDir(), 'docker_compose') }
)
}

cmd.on('close', () => resolve('not_downloaded'));
cmd.stdout.on('data', data => {
frontendsProcessesDocker.push(name)
Expand Down Expand Up @@ -104,11 +117,24 @@ async function remove_frontend(name) {
function health() {
return new Promise(async resolve => {
try {
const cmd = new shell.Command('/var/run/host/usr/local/bin/docker', ['compose', 'version'])
let cmd
if (await fs.exists('/usr/bin/flatpak-spawn')) {
cmd = new shell.Command('flatpak-spawn', ['--host', 'docker', 'compose', 'version'])
}
else {
cmd = new shell.Command('docker', ['compose', 'version'])
}

cmd.on('error', () => resolve('not_installed'));
cmd.stderr.on('data', () => resolve('not_installed'))
cmd.stdout.on('data', async () => {
const cmd = new shell.Command('/var/run/host/usr/local/bin/docker', ['ps'])
let cmd
if (await fs.exists('/usr/bin/flatpak-spawn')) {
cmd = new shell.Command('flatpak-spawn', ['--host', 'docker', 'ps'])
} else {
cmd = new shell.Command('docker', ['ps'])
}

cmd.on('error', () => resolve('not_running'));
cmd.stdout.on('data', () => resolve('running'))
cmd.stderr.on('data', () => resolve('not_running'))
Expand Down

0 comments on commit 1ab80c9

Please sign in to comment.