{"version":3,"file":"share-menu.mjs","names":[],"sources":["../../src/main/share-menu/index.ts"],"sourcesContent":["/**\n * Main process handlers for shareMenu module (macOS only)\n * Provides access to the system share sheet for sharing content\n */\n\nimport { ShareMenu, BrowserWindow } from \"electron\";\nimport type { RpcServer } from \"electron-json-rpc/main\";\nimport type { PopupOptions, SharingItem } from \"@shared/share-menu.types.js\";\n\nconst RPC_METHOD_PREFIX = \"shareMenu\";\n\n// Store active ShareMenu instances for each window\nconst activeMenus = new Map<number, ShareMenu>();\n\n/**\n * Create a ShareMenu instance and pop it up\n */\nexport async function popupHandler(...params: unknown[]): Promise<void> {\n  const [sharingItem, options] = params as [SharingItem, PopupOptions?];\n\n  // Get the target browser window\n  let browserWindow: BrowserWindow | undefined;\n  if (options?.browserWindow) {\n    const windows = BrowserWindow.getAllWindows();\n    browserWindow = windows.find((w) => w.id === options.browserWindow);\n  } else {\n    browserWindow = BrowserWindow.getFocusedWindow() ?? undefined;\n  }\n\n  // Create the ShareMenu\n  const shareMenu = new ShareMenu(sharingItem);\n\n  // Build popup options\n  const popupOptions: Record<string, unknown> = {};\n  if (browserWindow) {\n    popupOptions[\"window\"] = browserWindow;\n  }\n  if (options?.x !== undefined && options?.y !== undefined) {\n    popupOptions[\"x\"] = options.x;\n    popupOptions[\"y\"] = options.y;\n  }\n  if (options?.positioningItem !== undefined) {\n    popupOptions[\"positioningItem\"] = options.positioningItem;\n  }\n\n  // Store the menu instance for later closePopup calls\n  if (browserWindow) {\n    activeMenus.set(browserWindow.id, shareMenu);\n  }\n\n  // Pop up the menu\n  shareMenu.popup(popupOptions);\n}\n\n/**\n * Close the share menu popup for a window\n */\nexport async function closePopupHandler(...params: unknown[]): Promise<void> {\n  const [windowId] = params as [number?];\n\n  if (windowId !== undefined) {\n    const windows = BrowserWindow.getAllWindows();\n    const browserWindow = windows.find((w) => w.id === windowId);\n    if (browserWindow) {\n      const menu = activeMenus.get(browserWindow.id);\n      if (menu) {\n        menu.closePopup(browserWindow);\n        activeMenus.delete(browserWindow.id);\n      }\n    }\n  } else {\n    // Close all active menus\n    for (const [id, menu] of activeMenus) {\n      const windows = BrowserWindow.getAllWindows();\n      const browserWindow = windows.find((w) => w.id === id);\n      if (browserWindow) {\n        menu.closePopup(browserWindow);\n      }\n    }\n    activeMenus.clear();\n  }\n}\n\n/**\n * Register all shareMenu module RPC handlers\n */\nexport function registerShareMenuModule(rpc: RpcServer): void {\n  rpc.register(`${RPC_METHOD_PREFIX}.popup`, popupHandler);\n  rpc.register(`${RPC_METHOD_PREFIX}.closePopup`, closePopupHandler);\n}\n"],"mappings":";;;;;;;AASA,MAAM,oBAAoB;AAG1B,MAAM,8BAAc,IAAI,KAAwB;;;;AAKhD,eAAsB,aAAa,GAAG,QAAkC;CACtE,MAAM,CAAC,aAAa,WAAW;CAG/B,IAAI;AACJ,KAAI,SAAS,cAEX,iBADgB,cAAc,eAAe,CACrB,MAAM,MAAM,EAAE,OAAO,QAAQ,cAAc;KAEnE,iBAAgB,cAAc,kBAAkB,IAAI;CAItD,MAAM,YAAY,IAAI,UAAU,YAAY;CAG5C,MAAM,eAAwC,EAAE;AAChD,KAAI,cACF,cAAa,YAAY;AAE3B,KAAI,SAAS,MAAM,UAAa,SAAS,MAAM,QAAW;AACxD,eAAa,OAAO,QAAQ;AAC5B,eAAa,OAAO,QAAQ;;AAE9B,KAAI,SAAS,oBAAoB,OAC/B,cAAa,qBAAqB,QAAQ;AAI5C,KAAI,cACF,aAAY,IAAI,cAAc,IAAI,UAAU;AAI9C,WAAU,MAAM,aAAa;;;;;AAM/B,eAAsB,kBAAkB,GAAG,QAAkC;CAC3E,MAAM,CAAC,YAAY;AAEnB,KAAI,aAAa,QAAW;EAE1B,MAAM,gBADU,cAAc,eAAe,CACf,MAAM,MAAM,EAAE,OAAO,SAAS;AAC5D,MAAI,eAAe;GACjB,MAAM,OAAO,YAAY,IAAI,cAAc,GAAG;AAC9C,OAAI,MAAM;AACR,SAAK,WAAW,cAAc;AAC9B,gBAAY,O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