101 lines
3.4 KiB
JavaScript
101 lines
3.4 KiB
JavaScript
"use strict";
|
|
|
|
function registerOperationsIpc({
|
|
register, store, unraid, deployments, diagnostics, shell, dialog, path, app,
|
|
repositories, preflight, monitor,
|
|
}) {
|
|
register("operations:refresh", async ({ operationId }) => {
|
|
if (operationId) {
|
|
const operation = store.getOperation(operationId);
|
|
if (operation?.provider === "ssh-unraid")
|
|
return unraid.refreshOperation(operationId);
|
|
return deployments.refreshOperation(operationId);
|
|
}
|
|
const [actions, sshOperations] = await Promise.all([
|
|
deployments.refreshActiveOperations(),
|
|
unraid.refreshActiveOperations(),
|
|
]);
|
|
return [...actions, ...sshOperations];
|
|
});
|
|
register("operations:get", ({ operationId }) =>
|
|
store.getOperation(operationId),
|
|
);
|
|
|
|
register("diagnostics:status", () => diagnostics.getStatus());
|
|
register("diagnostics:clear", () => diagnostics.clear());
|
|
register("diagnostics:open-folder", async () => {
|
|
const error = await shell.openPath(diagnostics.logDirectory);
|
|
if (error) throw new Error(error);
|
|
return true;
|
|
});
|
|
register("diagnostics:export", async ({ privacyMode = "standard" }) => {
|
|
if (!["standard", "strict"].includes(privacyMode))
|
|
throw new Error("Unsupported diagnostic privacy mode.");
|
|
const result = await dialog.showSaveDialog({
|
|
title: "Export ForgeFlow diagnostic bundle",
|
|
defaultPath: path.join(
|
|
app.getPath("downloads"),
|
|
`ForgeFlow-Diagnostics-${new Date().toISOString().replace(/[:.]/g, "-")}.zip`,
|
|
),
|
|
filters: [{ name: "ZIP archive", extensions: ["zip"] }],
|
|
});
|
|
if (result.canceled || !result.filePath) return null;
|
|
const repositoryState = await repositories.refresh().catch((error) => {
|
|
diagnostics.warning("diagnostics.repository-snapshot.failed", error);
|
|
return [];
|
|
});
|
|
const systemPreflight = await preflight
|
|
.runSystem()
|
|
.catch((error) => ({ error: error.message }));
|
|
const destinationPath =
|
|
path.extname(result.filePath).toLowerCase() === ".zip"
|
|
? result.filePath
|
|
: `${result.filePath}.zip`;
|
|
return diagnostics.exportSupportBundle({
|
|
destinationPath,
|
|
publicState: store.getPublicState(),
|
|
repositories: repositoryState,
|
|
operations: store.data.operations,
|
|
preflight: systemPreflight,
|
|
privacyMode,
|
|
extra: {
|
|
appVersion: app.getVersion(),
|
|
setupComplete: store.data.setupComplete,
|
|
},
|
|
});
|
|
});
|
|
register("diagnostics:show-bundle", async ({ filePath }) => {
|
|
if (!diagnostics.isKnownBundlePath(filePath))
|
|
throw new Error(
|
|
"Only the most recently generated support bundle can be revealed.",
|
|
);
|
|
shell.showItemInFolder(filePath);
|
|
return true;
|
|
});
|
|
register(
|
|
"renderer:report",
|
|
async ({ level = "info", event = "renderer.event", details = {} }) => {
|
|
const method = ["debug", "info", "warning", "error"].includes(level)
|
|
? level
|
|
: "info";
|
|
await diagnostics[method](
|
|
`renderer.${String(event || "event").slice(0, 120)}`,
|
|
details,
|
|
);
|
|
return true;
|
|
},
|
|
);
|
|
|
|
register("app:reset", async () => {
|
|
await diagnostics.info("app.reset.requested", {});
|
|
store.data = store.migrate({});
|
|
store.sessionToken = null;
|
|
await store.save();
|
|
monitor?.setPaths([]);
|
|
monitor?.restart();
|
|
return store.getPublicState();
|
|
});
|
|
}
|
|
|
|
module.exports = { registerOperationsIpc };
|