Skip to content

Commit

Permalink
fix daemon control
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Jan 31, 2024
1 parent 6868d9d commit 400ab13
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: PR

on:
pull_request:

Expand Down
12 changes: 8 additions & 4 deletions hostd/main/daemon.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { spawn } from 'child_process'
import { state } from './state'
import { getConfig, getConfigFilePath } from './config'
import { getBinaryDirectoryPath, getBinaryFilePath } from './binary'
import path from 'path'
import fs from 'fs'
import { getBinaryDirectoryPath, getBinaryFilePath } from './binary'

export async function startDaemon(): Promise<void> {
try {
await stopDaemon()
const config = getConfig()
const binaryFilePath = getBinaryFilePath()
state.daemon = spawn(binaryFilePath, ['-env'], {
env: { ...process.env, HOSTD_CONFIG_FILE: getConfigFilePath() },
state.daemon = spawn(binaryFilePath, [], {
env: { ...process.env, RENTERD_CONFIG_FILE: getConfigFilePath() },
cwd: config.directory,
})

Expand All @@ -25,12 +25,16 @@ export async function startDaemon(): Promise<void> {
// Emit events or log data as needed
})

state.daemon.on('error', (err) => {
console.log(`child process exited with error ${err}`)
state.daemon = null
})

state.daemon.on('close', (code) => {
console.log(`child process exited with code ${code}`)
state.daemon = null
})
} catch (err) {
console.log('Failed to start daemon', err)
state.daemon = null
throw err
}
Expand Down
4 changes: 1 addition & 3 deletions hostd/renderer/components/useConfigData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export function useConfigData() {
return useSWR<Config>(
'config',
async () => {
const config = await window.electron.getConfig()
console.log(config)
return config
return window.electron.getConfig()
},
{
refreshInterval: 10_000,
Expand Down
8 changes: 5 additions & 3 deletions renterd/main/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ export async function startDaemon(): Promise<void> {
// Emit events or log data as needed
})

state.daemon.on('error', (err) => {
console.log(`child process exited with error ${err}`)
state.daemon = null
})

state.daemon.on('close', (code) => {
console.log(`child process exited with code ${code}`)
state.daemon = null
})
} catch (err) {
console.log('Failed to start daemon', err)
state.daemon = null
console.log('state is', state)
throw err
}
}
Expand All @@ -54,7 +57,6 @@ export function stopDaemon(): Promise<void> {
}

export function getIsDaemonRunning(): boolean {
console.log('daemon', state)
return !!state.daemon && !state.daemon.killed
}

Expand Down
1 change: 0 additions & 1 deletion renterd/renderer/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export function Header() {
useConfig()
const config = useConfigData()
const installedVersion = useInstalledVersion()
console.log(isRunning.data)
return (
<Panel
className="sticky z-10 top-0 w-full h-10 flex gap-2 justify-center items-center px-3 max-w-[500px] rounded-t-none"
Expand Down
4 changes: 1 addition & 3 deletions renterd/renderer/components/useConfigData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export function useConfigData() {
return useSWR<Config>(
'config',
async () => {
const config = await window.electron.getConfig()
console.log(config)
return config
return window.electron.getConfig()
},
{
refreshInterval: 10_000,
Expand Down
2 changes: 1 addition & 1 deletion renterd/renderer/contexts/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function useConfigMain() {
setSettings({
password: values.httpPassword,
})
if (notConfiguredYet) {
if (closeWindowAfterSave) {
window.electron.closeWindow()
}
} catch (e) {
Expand Down

0 comments on commit 400ab13

Please sign in to comment.