mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-20 01:10:27 -07:00
move ipcMain handlers to separate folder
This commit is contained in:
parent
77aa921dc7
commit
468bc83c9a
@ -32,7 +32,9 @@
|
||||
if (process.env.START_HOT) {
|
||||
// Dynamically insert the bundled app script in the renderer process
|
||||
const port = process.env.PORT || 1212;
|
||||
scripts.push(`http://localhost:${port}/dist/mainWindow.renderer.dev.js`);
|
||||
scripts.push(
|
||||
`http://localhost:${port}/dist/mainWindow.renderer.dev.js`
|
||||
);
|
||||
} else {
|
||||
scripts.push('./dist/mainWindow.renderer.prod.js');
|
||||
}
|
||||
|
@ -1,3 +1 @@
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
@ -10,23 +10,17 @@
|
||||
*/
|
||||
import 'core-js/stable';
|
||||
import 'regenerator-runtime/runtime';
|
||||
import { Display } from 'electron/main';
|
||||
import path from 'path';
|
||||
import { app, BrowserWindow, ipcMain, screen, shell } from 'electron';
|
||||
import { app, BrowserWindow, shell } from 'electron';
|
||||
import settings from 'electron-settings';
|
||||
import i18n from './configs/i18next.config';
|
||||
import signalingServer from './server';
|
||||
import MenuBuilder from './menu';
|
||||
import initGlobals from './utils/mainProcessHelpers/initGlobals';
|
||||
import ConnectedDevicesService from './features/ConnectedDevicesService';
|
||||
import RoomIDService from './server/RoomIDService';
|
||||
import SharingSession from './features/SharingSessionService/SharingSession';
|
||||
import getDeskreenGlobal from './utils/mainProcessHelpers/getDeskreenGlobal';
|
||||
import AppUpdater from './utils/AppUpdater';
|
||||
import installExtensions from './utils/installExtensions';
|
||||
import getNewVersionTag from './utils/getNewVersionTag';
|
||||
|
||||
const v4IPGetter = require('internal-ip').v4;
|
||||
import initIpcMainHandlers from './main/ipcMainHandlers';
|
||||
|
||||
export default class DeskreenApp {
|
||||
mainWindow: BrowserWindow | null = null;
|
||||
@ -102,74 +96,7 @@ export default class DeskreenApp {
|
||||
}
|
||||
|
||||
initIpcMain() {
|
||||
ipcMain.on('client-changed-language', async (_, newLangCode) => {
|
||||
i18n.changeLanguage(newLangCode);
|
||||
await settings.set('appLanguage', newLangCode);
|
||||
});
|
||||
|
||||
ipcMain.handle('get-signaling-server-port', () => {
|
||||
if (this.mainWindow === null) return;
|
||||
this.mainWindow.webContents.send(
|
||||
'sending-port-from-main',
|
||||
signalingServer.port
|
||||
);
|
||||
});
|
||||
|
||||
ipcMain.handle('get-all-displays', () => {
|
||||
return screen.getAllDisplays();
|
||||
});
|
||||
|
||||
ipcMain.handle('get-display-size-by-display-id', (_, displayID: string) => {
|
||||
const display = screen.getAllDisplays().find((d: Display) => {
|
||||
return `${d.id}` === displayID;
|
||||
});
|
||||
|
||||
if (display) {
|
||||
return display.size;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
ipcMain.handle('main-window-onbeforeunload', () => {
|
||||
const deskreenGlobal = getDeskreenGlobal();
|
||||
deskreenGlobal.connectedDevicesService = new ConnectedDevicesService();
|
||||
deskreenGlobal.roomIDService = new RoomIDService();
|
||||
deskreenGlobal.sharingSessionService.sharingSessions.forEach(
|
||||
(sharingSession: SharingSession) => {
|
||||
sharingSession.denyConnectionForPartner();
|
||||
sharingSession.destroy();
|
||||
}
|
||||
);
|
||||
|
||||
deskreenGlobal.rendererWebrtcHelpersService.helpers.forEach(
|
||||
(helperWindow) => {
|
||||
helperWindow.close();
|
||||
}
|
||||
);
|
||||
|
||||
deskreenGlobal.sharingSessionService.waitingForConnectionSharingSession = null;
|
||||
deskreenGlobal.rendererWebrtcHelpersService.helpers.clear();
|
||||
deskreenGlobal.sharingSessionService.sharingSessions.clear();
|
||||
});
|
||||
|
||||
ipcMain.handle('get-latest-version', () => {
|
||||
return this.latestVersion;
|
||||
});
|
||||
|
||||
ipcMain.handle('get-current-version', () => {
|
||||
return this.appVersion;
|
||||
});
|
||||
|
||||
ipcMain.handle('get-local-lan-ip', async () => {
|
||||
if (
|
||||
process.env.RUN_MODE === 'dev' ||
|
||||
process.env.NODE_ENV === 'production'
|
||||
) {
|
||||
const ip = await v4IPGetter();
|
||||
return ip;
|
||||
}
|
||||
return '255.255.255.255';
|
||||
});
|
||||
initIpcMainHandlers(this.mainWindow, this.latestVersion, this.appVersion);
|
||||
}
|
||||
|
||||
async createWindow() {
|
||||
|
82
app/main/ipcMainHandlers.ts
Normal file
82
app/main/ipcMainHandlers.ts
Normal file
@ -0,0 +1,82 @@
|
||||
import { Display, ipcMain, BrowserWindow, screen } from 'electron';
|
||||
import settings from 'electron-settings';
|
||||
import i18n from '../configs/i18next.config';
|
||||
import ConnectedDevicesService from '../features/ConnectedDevicesService';
|
||||
import SharingSession from '../features/SharingSessionService/SharingSession';
|
||||
import RoomIDService from '../server/RoomIDService';
|
||||
import getDeskreenGlobal from '../utils/mainProcessHelpers/getDeskreenGlobal';
|
||||
import signalingServer from '../server';
|
||||
|
||||
const v4IPGetter = require('internal-ip').v4;
|
||||
|
||||
export default function initIpcMainHandlers(
|
||||
mainWindow: BrowserWindow | null,
|
||||
latestVersion: string,
|
||||
appVersion: string
|
||||
) {
|
||||
ipcMain.on('client-changed-language', async (_, newLangCode) => {
|
||||
i18n.changeLanguage(newLangCode);
|
||||
await settings.set('appLanguage', newLangCode);
|
||||
});
|
||||
|
||||
ipcMain.handle('get-signaling-server-port', () => {
|
||||
if (mainWindow === null) return;
|
||||
mainWindow.webContents.send('sending-port-from-main', signalingServer.port);
|
||||
});
|
||||
|
||||
ipcMain.handle('get-all-displays', () => {
|
||||
return screen.getAllDisplays();
|
||||
});
|
||||
|
||||
ipcMain.handle('get-display-size-by-display-id', (_, displayID: string) => {
|
||||
const display = screen.getAllDisplays().find((d: Display) => {
|
||||
return `${d.id}` === displayID;
|
||||
});
|
||||
|
||||
if (display) {
|
||||
return display.size;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
ipcMain.handle('main-window-onbeforeunload', () => {
|
||||
const deskreenGlobal = getDeskreenGlobal();
|
||||
deskreenGlobal.connectedDevicesService = new ConnectedDevicesService();
|
||||
deskreenGlobal.roomIDService = new RoomIDService();
|
||||
deskreenGlobal.sharingSessionService.sharingSessions.forEach(
|
||||
(sharingSession: SharingSession) => {
|
||||
sharingSession.denyConnectionForPartner();
|
||||
sharingSession.destroy();
|
||||
}
|
||||
);
|
||||
|
||||
deskreenGlobal.rendererWebrtcHelpersService.helpers.forEach(
|
||||
(helperWindow) => {
|
||||
helperWindow.close();
|
||||
}
|
||||
);
|
||||
|
||||
deskreenGlobal.sharingSessionService.waitingForConnectionSharingSession = null;
|
||||
deskreenGlobal.rendererWebrtcHelpersService.helpers.clear();
|
||||
deskreenGlobal.sharingSessionService.sharingSessions.clear();
|
||||
});
|
||||
|
||||
ipcMain.handle('get-latest-version', () => {
|
||||
return latestVersion;
|
||||
});
|
||||
|
||||
ipcMain.handle('get-current-version', () => {
|
||||
return appVersion;
|
||||
});
|
||||
|
||||
ipcMain.handle('get-local-lan-ip', async () => {
|
||||
if (
|
||||
process.env.RUN_MODE === 'dev' ||
|
||||
process.env.NODE_ENV === 'production'
|
||||
) {
|
||||
const ip = await v4IPGetter();
|
||||
return ip;
|
||||
}
|
||||
return '255.255.255.255';
|
||||
});
|
||||
}
|
@ -37,9 +37,13 @@
|
||||
if (process.env.START_HOT) {
|
||||
// Dynamically insert the bundled app script in the renderer process
|
||||
const port = process.env.PORT || 1212;
|
||||
scripts.push(`http://localhost:${port}/dist/peerConnectionHelperRendererWindow.renderer.dev.js`);
|
||||
scripts.push(
|
||||
`http://localhost:${port}/dist/peerConnectionHelperRendererWindow.renderer.dev.js`
|
||||
);
|
||||
} else {
|
||||
scripts.push('./dist/peerConnectionHelperRendererWindow.renderer.prod.js');
|
||||
scripts.push(
|
||||
'./dist/peerConnectionHelperRendererWindow.renderer.prod.js'
|
||||
);
|
||||
}
|
||||
|
||||
if (scripts.length) {
|
||||
|
@ -268,7 +268,7 @@
|
||||
"cross-env": "^7.0.0",
|
||||
"css-loader": "^3.6.0",
|
||||
"detect-port": "^1.3.0",
|
||||
"electron-builder": "^22.3.6",
|
||||
"electron-builder": "^23.0.3",
|
||||
"electron-devtools-installer": "^2.2.4",
|
||||
"electron-rebuild": "^3.2.7",
|
||||
"enzyme": "^3.11.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user