update
This commit is contained in:
75
APP/screen-share/main.js
Normal file
75
APP/screen-share/main.js
Normal file
@@ -0,0 +1,75 @@
|
||||
const { app, BrowserWindow, desktopCapturer, ipcMain } = require('electron');
|
||||
const path = require('path');
|
||||
|
||||
let mainWindow;
|
||||
|
||||
function createWindow() {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
},
|
||||
});
|
||||
|
||||
mainWindow.loadFile('index.html');
|
||||
}
|
||||
|
||||
ipcMain.handle('get-sources', async () => {
|
||||
const sources = await desktopCapturer.getSources({
|
||||
types: ['screen', 'window'],
|
||||
thumbnailSize: { width: 320, height: 180 },
|
||||
});
|
||||
return sources.map((s) => ({
|
||||
id: s.id,
|
||||
name: s.name,
|
||||
thumbnail: s.thumbnail.toDataURL(),
|
||||
}));
|
||||
});
|
||||
|
||||
let robotjs = null;
|
||||
try {
|
||||
robotjs = require('robotjs');
|
||||
} catch (e) {
|
||||
console.warn('robotjs nicht verfuegbar – Fernsteuerung deaktiviert');
|
||||
}
|
||||
|
||||
ipcMain.on('remote-control', (_event, data) => {
|
||||
if (!robotjs) return;
|
||||
|
||||
try {
|
||||
switch (data.action) {
|
||||
case 'mousemove':
|
||||
robotjs.moveMouse(Math.round(data.x), Math.round(data.y));
|
||||
break;
|
||||
case 'mousedown':
|
||||
robotjs.mouseToggle('down', data.button || 'left');
|
||||
break;
|
||||
case 'mouseup':
|
||||
robotjs.mouseToggle('up', data.button || 'left');
|
||||
break;
|
||||
case 'click':
|
||||
robotjs.mouseClick(data.button || 'left');
|
||||
break;
|
||||
case 'keydown':
|
||||
robotjs.keyToggle(data.key, 'down', data.modifiers || []);
|
||||
break;
|
||||
case 'keyup':
|
||||
robotjs.keyToggle(data.key, 'up', data.modifiers || []);
|
||||
break;
|
||||
case 'scroll':
|
||||
robotjs.scrollMouse(data.deltaX || 0, data.deltaY || 0);
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Fernsteuerungsfehler:', err.message);
|
||||
}
|
||||
});
|
||||
|
||||
app.whenReady().then(createWindow);
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
app.quit();
|
||||
});
|
||||
Reference in New Issue
Block a user