ContextMenu
The ContextMenu API allows mods to add custom right-click menu items to various targets in the game.
Import
ts
import { ContextMenu } from "@hotbunny/hackhub-content-sdk";Functions
ContextMenu.register(item: ContextMenuItem)
Registers a custom context menu item for a specific target.
ts
ContextMenu.register({
id: "scan-file",
label: "Scan with Antivirus",
target: "file",
icon: "mod-asset://scan-icon.png",
onClick: (context) => {
UI.toast(`Scanning ${context.name}...`);
},
});ContextMenu.unregister(id: string)
Removes a previously registered context menu item.
ts
ContextMenu.unregister("scan-file");ContextMenu.getItems(target: string): ContextMenuItem[]
Returns all mod-added context menu items for a specific target.
ts
const fileItems = ContextMenu.getItems("file");
console.log(`${fileItems.length} custom file context items`);ContextMenuItem Interface
| Property | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique identifier |
label | string | Yes | Display text |
icon | string | No | Icon URL (supports mod-asset:// protocol) |
target | "file" | "desktop" | "taskbar" | "window" | Yes | Where the item appears |
onClick | (context: any) => void | No | Callback with context data |
Targets
| Target | Description | Context Data |
|---|---|---|
"file" | Right-click on desktop files/folders | { target: "file", name: string, id: string } |
"desktop" | Right-click on desktop background | { target: "desktop" } |
"taskbar" | Right-click on taskbar icons | { target: "taskbar", app: string } |
"window" | Right-click on window titlebars | { target: "window" } |
Example: File Scanner
ts
import { ContextMenu, UI } from "@hotbunny/hackhub-content-sdk";
ContextMenu.register({
id: "antivirus-scan",
label: "Scan for Viruses",
target: "file",
icon: "mod-asset://shield.png",
onClick: (context) => {
UI.toast(`Scanning "${context.name}"...`);
setTimeout(() => {
UI.toast(`"${context.name}" is clean!`);
}, 2000);
},
});Example: Desktop Quick Action
ts
import { ContextMenu } from "@hotbunny/hackhub-content-sdk";
ContextMenu.register({
id: "quick-note",
label: "Create Quick Note",
target: "desktop",
onClick: () => {
// Create a quick note file on desktop
Files.create({
name: "Quick Note",
extension: "txt",
data: "Type your note here...",
});
},
});Example: Taskbar Extension
ts
import { ContextMenu, UI } from "@hotbunny/hackhub-content-sdk";
ContextMenu.register({
id: "app-info",
label: "Show App Info",
target: "taskbar",
onClick: (context) => {
UI.toast(`App: ${context.app}`);
},
});