Files
AgentCompany/src/main/updater-service.ts
T
ZacharyZhang-NYandClaude Opus 4.6 667ac48aa5 feat(04-01): refactor all notify() call sites to use structured NotificationOptions
- Change ipc-support.ts notify() from (title, body) to (options: NotificationOptions)
- Wire createNotificationService in bootstrap-application.ts with lazy service graph refs
- Update all 12 call sites with entity context, urgency, navigation, and batch keys
- Update dependency interfaces in service-graph, worker, orchestration, automation, updater, desktop-shell
- No string-based notify() calls remain in src/main/

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 16:37:07 -04:00

78 lines
2.2 KiB
TypeScript

import electronUpdater from "electron-updater";
import type { AppDatabase } from "./database";
import type { NotificationOptions } from "./notification-service";
const { autoUpdater } = electronUpdater;
interface UpdaterServiceDependencies {
db: AppDatabase;
logger: {
info: (...args: unknown[]) => void;
error: (...args: unknown[]) => void;
};
notify: (options: NotificationOptions) => void;
}
export function createUpdaterService({
db,
logger,
notify,
}: UpdaterServiceDependencies) {
function attachListeners() {
autoUpdater.on("checking-for-update", () => {
logger.info("[updater] checking for updates");
});
autoUpdater.on("update-available", (info) => {
notify({
title: "Update Available",
body: `Version ${info.version} is ready to install`,
urgency: "informational",
navigation: { section: "settings" },
});
});
autoUpdater.on("update-not-available", () => {
notify({
title: "Up to Date",
body: "You are running the latest version",
urgency: "informational",
navigation: { section: "settings" },
});
});
autoUpdater.on("error", (error) => {
logger.error("[updater] error", error);
notify({
title: "Update Check Failed",
body: "Could not check for updates. Try again later.",
urgency: "informational",
navigation: { section: "settings" },
});
});
}
async function checkForUpdates() {
const snapshot = db.listSnapshot();
if (!snapshot.updatesEnabled || process.env.AGENTCOMPANY_DISABLE_UPDATES === "true") {
return false;
}
const updateUrl = process.env.AGENTCOMPANY_UPDATE_URL?.trim();
if (!updateUrl || updateUrl.includes("example.invalid")) {
logger.info("[updater] Skipping update check because no real update URL is configured.");
return false;
}
try {
autoUpdater.logger = logger as any;
autoUpdater.autoDownload = false;
await autoUpdater.checkForUpdates();
return true;
} catch (error) {
logger.error(error);
return false;
}
}
return {
attachListeners,
checkForUpdates,
};
}