Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ app.whenReady().then(() => {
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
stopWatchingDirectory()
killZImageProcess()
app.quit()
}
})
Expand All @@ -177,6 +175,8 @@ app.on('before-quit', async (event) => {
console.log('Quitting...')
return
}
console.log('Stopping watching directory...')
stopWatchingDirectory()
console.log('Killing child process before quitting...')
event.preventDefault()
isQuitting = true
Expand Down
32 changes: 27 additions & 5 deletions src/main/zimage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { readdir } from 'node:fs/promises'
import { join, normalize } from 'node:path'

import { IpcChannelOn } from '@shared/const/ipc'
import kill from 'tree-kill'

import { getCorePath } from './getPath'
import { PRESET_MODELS } from './modelManager'
Expand Down Expand Up @@ -143,7 +144,9 @@ export async function runZImageCommand(_event: IpcMainEvent, options: ZImageOpti
args.push('-g', `${options.gpuId}`)
}

console.log(`[Batch ${i + 1}/${count}] Executing ZImage:`, getCorePath(), args)
const current_start_args = `[Batch ${i + 1}/${count}] Executing ZImage: ${getCorePath()} ${args.join(' ')} \n\n`
console.log(current_start_args)
_event.sender.send(IpcChannelOn.COMMAND_STDOUT, current_start_args)

// Run and wait
await runSingleZImage(_event, args, getCorePath())
Expand All @@ -159,9 +162,28 @@ export async function runZImageCommand(_event: IpcMainEvent, options: ZImageOpti

export async function killZImageProcess(_event?: IpcMainEvent): Promise<void> {
isBatchStopped = true
if (zImageChild) {
console.log('Killing ZImage process...')
zImageChild.kill()
zImageChild = null
if (!zImageChild || !zImageChild.pid) {
console.log('ZImage process not running or no PID found.')
return
}

const pid = zImageChild.pid
console.log(`Killing ZImage process tree with PID: ${pid}`)

return new Promise<void>((resolve) => {
kill(pid, 'SIGKILL', (err) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using SIGKILL (9) is quite aggressive as it forces the process to terminate immediately without any opportunity for cleanup. It is generally recommended to use SIGTERM (the default for tree-kill) first. If SIGKILL is intentionally used to ensure compute-heavy tasks or GPU resources are released immediately, consider adding a brief comment to explain this choice.

Suggested change
kill(pid, 'SIGKILL', (err) => {
kill(pid, 'SIGTERM', (err) => {

if (err) {
console.error(`Failed to kill process tree: ${err.message}`)
}
else {
console.log('ZImage process tree killed successfully')
}

// Ensure reference is cleared if it matches
if (zImageChild && zImageChild.pid === pid) {
zImageChild = null
}
resolve()
})
})
}
10 changes: 6 additions & 4 deletions src/renderer/src/store/zimageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,16 @@ export const useZImageStore = defineStore(
}
}

isGenerating.value = true
logs.value = ''
// Don't clear generatedImages - keep history

if (!selectedModel.value) {
return {
success: false,
message: i18n.global.t('common.selectModelFirst'),
}
}

isGenerating.value = true
logs.value = ''

const options: ZImageOptions = {
prompt: prompt.value,
negativePrompt: negativePrompt.value,
Expand All @@ -156,6 +155,9 @@ export const useZImageStore = defineStore(
modelDir: modelFolder.value,
}

console.log('[Store] Starting generation with options:', JSON.stringify(options, null, 2))
logs.value += `${JSON.stringify(options, null, 2)}\n`

// Listeners
const onStdout = (_event: any, data: string): void => {
logs.value += data
Expand Down