[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
79
electron/bridges/systemNotification.cjs
Normal file
79
electron/bridges/systemNotification.cjs
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
|
||||
const TITLE_MAX = 120;
|
||||
const BODY_MAX = 500;
|
||||
const CONTROL_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g;
|
||||
|
||||
function sanitizeNotificationText(value, max) {
|
||||
if (typeof value !== "string" || max <= 0) return "";
|
||||
const cleaned = value.replace(CONTROL_CHARS, "").replace(/\s+/g, " ").trim();
|
||||
if (cleaned.length <= max) return cleaned;
|
||||
return `${cleaned.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
|
||||
}
|
||||
|
||||
function showSystemNotification({
|
||||
Notification,
|
||||
BrowserWindow,
|
||||
sender,
|
||||
title,
|
||||
body,
|
||||
sessionId,
|
||||
defaultTitle = "Netcatty",
|
||||
}) {
|
||||
if (typeof Notification !== "function" || typeof Notification.isSupported !== "function") {
|
||||
return { shown: false, reason: "unavailable" };
|
||||
}
|
||||
if (!Notification.isSupported()) {
|
||||
return { shown: false, reason: "unsupported" };
|
||||
}
|
||||
|
||||
const safeTitle = sanitizeNotificationText(title, TITLE_MAX) || defaultTitle;
|
||||
const safeBody = sanitizeNotificationText(body, BODY_MAX);
|
||||
const safeSessionId = typeof sessionId === "string" ? sessionId : "";
|
||||
|
||||
const notification = new Notification({
|
||||
title: safeTitle,
|
||||
body: safeBody,
|
||||
silent: false,
|
||||
});
|
||||
|
||||
notification.on("click", () => {
|
||||
const win = typeof BrowserWindow?.fromWebContents === "function"
|
||||
? BrowserWindow.fromWebContents(sender)
|
||||
: null;
|
||||
if (win && !win.isDestroyed()) {
|
||||
if (typeof win.isMinimized === "function" && win.isMinimized()) win.restore();
|
||||
win.show();
|
||||
win.focus();
|
||||
}
|
||||
if (safeSessionId && sender && typeof sender.isDestroyed === "function" && !sender.isDestroyed()) {
|
||||
sender.send("netcatty:tray:focusSession", safeSessionId);
|
||||
}
|
||||
});
|
||||
|
||||
notification.show();
|
||||
return { shown: true };
|
||||
}
|
||||
|
||||
function registerSystemNotificationHandlers(ipcMain, { electronModule, BrowserWindow }) {
|
||||
ipcMain.handle("netcatty:notification:show", async (event, payload) => {
|
||||
try {
|
||||
return showSystemNotification({
|
||||
Notification: electronModule?.Notification,
|
||||
BrowserWindow,
|
||||
sender: event?.sender,
|
||||
title: payload?.title,
|
||||
body: payload?.body,
|
||||
sessionId: payload?.sessionId,
|
||||
});
|
||||
} catch (err) {
|
||||
return { shown: false, reason: err?.message || "failed" };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sanitizeNotificationText,
|
||||
showSystemNotification,
|
||||
registerSystemNotificationHandlers,
|
||||
};
|
||||
Reference in New Issue
Block a user