Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Electron main process for the host agent.
  2. // Owns: the consent window, screen-source selection, and OS input injection.
  3. // WebRTC lives in the renderer (it needs a DOM/navigator); input events arrive
  4. // from the renderer over IPC and are injected here.
  5. const { app, BrowserWindow, ipcMain, desktopCapturer, screen } = require('electron');
  6. const path = require('path');
  7. const injector = require('./input/inject');
  8. const SERVER_URL = process.env.SERVER_URL || 'http://localhost:8090';
  9. const ENROLL_TOKEN = process.env.AGENT_ENROLL_TOKEN || '';
  10. let win;
  11. function createWindow() {
  12. win = new BrowserWindow({
  13. width: 460,
  14. height: 560,
  15. resizable: false,
  16. title: 'Remote Access Agent',
  17. webPreferences: {
  18. preload: path.join(__dirname, 'preload.js'),
  19. contextIsolation: true,
  20. nodeIntegration: false,
  21. },
  22. });
  23. win.loadFile(path.join(__dirname, 'renderer', 'agent.html'));
  24. // Pass config to the renderer once loaded
  25. win.webContents.on('did-finish-load', () => {
  26. win.webContents.send('config', { serverUrl: SERVER_URL, enrollToken: ENROLL_TOKEN });
  27. });
  28. }
  29. // ---- Screen source for getDisplayMedia (Electron requires a handler) ----
  30. function registerDisplayMediaHandler() {
  31. const { session } = require('electron');
  32. session.defaultSession.setDisplayMediaRequestHandler((request, callback) => {
  33. desktopCapturer.getSources({ types: ['screen'] }).then((sources) => {
  34. // Default to the primary display; production would let the user pick.
  35. callback({ video: sources[0], audio: 'loopback' });
  36. });
  37. }, { useSystemPicker: false });
  38. }
  39. // ---- IPC: renderer forwards remote input events here for OS injection ----
  40. ipcMain.on('inject-input', (_e, evt) => {
  41. injector.inject(evt);
  42. });
  43. ipcMain.on('session-ended', () => {
  44. injector.releaseAll();
  45. });
  46. ipcMain.handle('get-primary-size', () => {
  47. const { size } = screen.getPrimaryDisplay();
  48. return size;
  49. });
  50. app.whenReady().then(() => {
  51. registerDisplayMediaHandler();
  52. createWindow();
  53. app.on('activate', () => {
  54. if (BrowserWindow.getAllWindows().length === 0) createWindow();
  55. });
  56. });
  57. app.on('window-all-closed', () => {
  58. if (process.platform !== 'darwin') app.quit();
  59. });