稳定测试版
This commit is contained in:
24
main/ipc/files.js
Normal file
24
main/ipc/files.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// main/ipc/files.js
|
||||
const { ipcMain } = require('electron')
|
||||
const fsp = require('node:fs/promises')
|
||||
const { normalizePath } = require('../utils/paths')
|
||||
|
||||
function registerFileIpc() {
|
||||
ipcMain.removeHandler('file-exists')
|
||||
ipcMain.handle('file-exists', async (_evt, targetPath, baseDir) => {
|
||||
try {
|
||||
const full = normalizePath(targetPath, baseDir)
|
||||
const stat = await fsp.stat(full).catch(err => (err?.code === 'ENOENT' ? null : Promise.reject(err)))
|
||||
if (!stat) return { ok: true, exists: false, path: full }
|
||||
return {
|
||||
ok: true, exists: true, path: full,
|
||||
isFile: stat.isFile(), isDirectory: stat.isDirectory(),
|
||||
size: stat.size, mtimeMs: stat.mtimeMs
|
||||
}
|
||||
} catch (e) {
|
||||
return { ok: false, error: e.message || String(e) }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { registerFileIpc }
|
||||
30
main/ipc/mq.js
Normal file
30
main/ipc/mq.js
Normal file
@@ -0,0 +1,30 @@
|
||||
// main/ipc/mq.js
|
||||
const { ipcMain } = require('electron')
|
||||
const mq = require('../../js/rabbitmq-service') // 复用你的文件
|
||||
let currentTenantId = null
|
||||
|
||||
async function startConsumer(emitMessage, tenantId) {
|
||||
await mq.startConsumer(
|
||||
`q.tenant.${tenantId}`,
|
||||
(msg) => emitMessage(msg.json ?? msg.text),
|
||||
{ prefetch: 1, requeueOnError: false, durable: true, assertQueue: true }
|
||||
)
|
||||
}
|
||||
|
||||
function registerMqIpc(emitMessage) {
|
||||
ipcMain.removeHandler('start-mq')
|
||||
ipcMain.handle('start-mq', async (_event, tenantId, userId) => {
|
||||
currentTenantId = tenantId
|
||||
await startConsumer(emitMessage, tenantId)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
ipcMain.removeHandler('mq-send')
|
||||
ipcMain.handle('mq-send', async (_event, payload) => {
|
||||
if (!currentTenantId) return { ok: false, error: 'tenant not set' }
|
||||
await mq.publishToQueue(`q.tenant.${currentTenantId}`, payload)
|
||||
return { ok: true }
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { registerMqIpc }
|
||||
17
main/ipc/system.js
Normal file
17
main/ipc/system.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// main/ipc/system.js
|
||||
const { ipcMain, dialog } = require('electron')
|
||||
|
||||
function registerSystemIpc() {
|
||||
ipcMain.removeHandler('manual-gc')
|
||||
ipcMain.handle('manual-gc', () => {
|
||||
if (global.gc) {
|
||||
global.gc()
|
||||
console.log('🧹 手动触发 GC 成功')
|
||||
} else {
|
||||
console.warn('⚠️ global.gc 不存在,请确认 --expose-gc')
|
||||
}
|
||||
})
|
||||
// 你也可以把 select-file 放这里(如果不想放 window.js)
|
||||
}
|
||||
|
||||
module.exports = { registerSystemIpc }
|
||||
Reference in New Issue
Block a user