mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-18 00:10:12 -07:00
more ipc invoke, less globals
This commit is contained in:
parent
70e2c47555
commit
19a1da6ff3
@ -18,6 +18,7 @@ import translationZH_CN from '../locales/zh_CN/translation.json';
|
|||||||
import translationZH_TW from '../locales/zh_TW/translation.json';
|
import translationZH_TW from '../locales/zh_TW/translation.json';
|
||||||
import translationDA from '../locales/da/translation.json';
|
import translationDA from '../locales/da/translation.json';
|
||||||
import translationDE from '../locales/de/translation.json';
|
import translationDE from '../locales/de/translation.json';
|
||||||
|
import { IpcEvents } from '../main/IpcEvents.enum';
|
||||||
|
|
||||||
export const getLangFullNameToLangISOKeyMap = (): Map<string, string> => {
|
export const getLangFullNameToLangISOKeyMap = (): Map<string, string> => {
|
||||||
const res = new Map<string, string>();
|
const res = new Map<string, string>();
|
||||||
@ -68,7 +69,7 @@ export const getShuffledArrayOfHello = (): string[] => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function initI18NextOptions() {
|
async function initI18NextOptions() {
|
||||||
const appPath = await ipcRenderer.invoke('get-app-path');
|
const appPath = await ipcRenderer.invoke(IpcEvents.GetAppPath);
|
||||||
const i18nextOptions = {
|
const i18nextOptions = {
|
||||||
interpolation: {
|
interpolation: {
|
||||||
escapeValue: false,
|
escapeValue: false,
|
||||||
|
@ -39,6 +39,7 @@ import { getShuffledArrayOfHello } from '../configs/i18next.config.client';
|
|||||||
import ToggleThemeBtnGroup from '../components/ToggleThemeBtnGroup';
|
import ToggleThemeBtnGroup from '../components/ToggleThemeBtnGroup';
|
||||||
import SharingSessionService from '../features/SharingSessionService';
|
import SharingSessionService from '../features/SharingSessionService';
|
||||||
import ConnectedDevicesService from '../features/ConnectedDevicesService';
|
import ConnectedDevicesService from '../features/ConnectedDevicesService';
|
||||||
|
import { IpcEvents } from '../main/IpcEvents.enum';
|
||||||
|
|
||||||
const sharingSessionService = remote.getGlobal(
|
const sharingSessionService = remote.getGlobal(
|
||||||
'sharingSessionService'
|
'sharingSessionService'
|
||||||
@ -117,8 +118,8 @@ const DeskreenStepper = React.forwardRef((_props, ref) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ipcRenderer.invoke('create-waiting-for-connection-sharing-session');
|
ipcRenderer.invoke(IpcEvents.CreateWaitingForConnectionSharingSession);
|
||||||
ipcRenderer.on('set-pending-connection-device', (_, device) => {
|
ipcRenderer.on(IpcEvents.SetPendingConnectionDevice, (_, device) => {
|
||||||
setPendingConnectionDevice(device);
|
setPendingConnectionDevice(device);
|
||||||
setIsAlertOpen(true);
|
setIsAlertOpen(true);
|
||||||
});
|
});
|
||||||
@ -184,17 +185,7 @@ const DeskreenStepper = React.forwardRef((_props, ref) => {
|
|||||||
setPendingConnectionDevice(null);
|
setPendingConnectionDevice(null);
|
||||||
setIsUserAllowedConnection(false);
|
setIsUserAllowedConnection(false);
|
||||||
|
|
||||||
sharingSessionService
|
ipcRenderer.invoke(IpcEvents.CreateWaitingForConnectionSharingSession);
|
||||||
.createWaitingForConnectionSharingSession()
|
|
||||||
// eslint-disable-next-line promise/always-return
|
|
||||||
.then((waitingForConnectionSharingSession) => {
|
|
||||||
waitingForConnectionSharingSession.setOnDeviceConnectedCallback(
|
|
||||||
(device: Device) => {
|
|
||||||
connectedDevicesService.setPendingConnectionDevice(device);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((e) => log.error(e));
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleResetWithSharingSessionRestart = useCallback(() => {
|
const handleResetWithSharingSessionRestart = useCallback(() => {
|
||||||
@ -202,24 +193,8 @@ const DeskreenStepper = React.forwardRef((_props, ref) => {
|
|||||||
setPendingConnectionDevice(null);
|
setPendingConnectionDevice(null);
|
||||||
setIsUserAllowedConnection(false);
|
setIsUserAllowedConnection(false);
|
||||||
|
|
||||||
const sharingSession =
|
ipcRenderer.invoke(IpcEvents.ResetWaitingForConnectionSharingSession);
|
||||||
sharingSessionService.waitingForConnectionSharingSession;
|
ipcRenderer.invoke(IpcEvents.CreateWaitingForConnectionSharingSession);
|
||||||
sharingSession?.disconnectByHostMachineUser();
|
|
||||||
sharingSession?.destroy();
|
|
||||||
sharingSessionService.sharingSessions.delete(sharingSession?.id as string);
|
|
||||||
sharingSessionService.waitingForConnectionSharingSession = null;
|
|
||||||
|
|
||||||
sharingSessionService
|
|
||||||
.createWaitingForConnectionSharingSession()
|
|
||||||
// eslint-disable-next-line promise/always-return
|
|
||||||
.then((waitingForConnectionSharingSession) => {
|
|
||||||
waitingForConnectionSharingSession.setOnDeviceConnectedCallback(
|
|
||||||
(device: Device) => {
|
|
||||||
connectedDevicesService.setPendingConnectionDevice(device);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((e) => log.error(e));
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => ({
|
React.useImperativeHandle(ref, () => ({
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
|
import { IpcEvents } from '../../main/IpcEvents.enum';
|
||||||
import SharingSessionStatusEnum from '../SharingSessionService/SharingSessionStatusEnum';
|
import SharingSessionStatusEnum from '../SharingSessionService/SharingSessionStatusEnum';
|
||||||
import NullSimplePeer from './NullSimplePeer';
|
import NullSimplePeer from './NullSimplePeer';
|
||||||
import NullUser from './NullUser';
|
import NullUser from './NullUser';
|
||||||
@ -29,5 +30,5 @@ export default function handleSelfDestroy(peerConnection: PeerConnection) {
|
|||||||
peerConnection.isCallStarted = false;
|
peerConnection.isCallStarted = false;
|
||||||
peerConnection.socket.disconnect();
|
peerConnection.socket.disconnect();
|
||||||
|
|
||||||
ipcRenderer.invoke('unmark-room-id-as-taken', peerConnection.roomID);
|
ipcRenderer.invoke(IpcEvents.UnmarkRoomIDAsTaken, peerConnection.roomID);
|
||||||
}
|
}
|
||||||
|
8
app/main/IpcEvents.enum.ts
Normal file
8
app/main/IpcEvents.enum.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
|
export enum IpcEvents {
|
||||||
|
CreateWaitingForConnectionSharingSession = 'create-waiting-for-connection-sharing-session',
|
||||||
|
SetPendingConnectionDevice = 'set-pending-connection-device',
|
||||||
|
UnmarkRoomIDAsTaken = 'unmark-room-id-as-taken',
|
||||||
|
GetAppPath = 'get-app-path',
|
||||||
|
ResetWaitingForConnectionSharingSession = 'reset-waiting-for-connection-sharing-session',
|
||||||
|
}
|
@ -7,6 +7,7 @@ import RoomIDService from '../server/RoomIDService';
|
|||||||
import getDeskreenGlobal from '../utils/mainProcessHelpers/getDeskreenGlobal';
|
import getDeskreenGlobal from '../utils/mainProcessHelpers/getDeskreenGlobal';
|
||||||
import signalingServer from '../server';
|
import signalingServer from '../server';
|
||||||
import Logger from '../utils/LoggerWithFilePrefix';
|
import Logger from '../utils/LoggerWithFilePrefix';
|
||||||
|
import { IpcEvents } from './IpcEvents.enum';
|
||||||
|
|
||||||
const log = new Logger(__filename);
|
const log = new Logger(__filename);
|
||||||
const v4IPGetter = require('internal-ip').v4;
|
const v4IPGetter = require('internal-ip').v4;
|
||||||
@ -82,18 +83,17 @@ export default function initIpcMainHandlers(
|
|||||||
return '255.255.255.255';
|
return '255.255.255.255';
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('get-app-path', () => {
|
ipcMain.handle(IpcEvents.GetAppPath, () => {
|
||||||
const deskreenGlobal = getDeskreenGlobal();
|
const deskreenGlobal = getDeskreenGlobal();
|
||||||
return deskreenGlobal.appPath;
|
return deskreenGlobal.appPath;
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('unmark-room-id-as-taken', (_, roomID) => {
|
ipcMain.handle(IpcEvents.UnmarkRoomIDAsTaken, (_, roomID) => {
|
||||||
const deskreenGlobal = getDeskreenGlobal();
|
const deskreenGlobal = getDeskreenGlobal();
|
||||||
deskreenGlobal.roomIDService.unmarkRoomIDAsTaken(roomID);
|
deskreenGlobal.roomIDService.unmarkRoomIDAsTaken(roomID);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('create-waiting-for-connection-sharing-session', () => {
|
ipcMain.handle(IpcEvents.CreateWaitingForConnectionSharingSession, () => {
|
||||||
console.log('handle create-waiting-for-connection-sharing-session');
|
|
||||||
getDeskreenGlobal()
|
getDeskreenGlobal()
|
||||||
.sharingSessionService.createWaitingForConnectionSharingSession()
|
.sharingSessionService.createWaitingForConnectionSharingSession()
|
||||||
// eslint-disable-next-line promise/always-return
|
// eslint-disable-next-line promise/always-return
|
||||||
@ -104,7 +104,7 @@ export default function initIpcMainHandlers(
|
|||||||
device
|
device
|
||||||
);
|
);
|
||||||
mainWindow.webContents.send(
|
mainWindow.webContents.send(
|
||||||
'set-pending-connection-device',
|
IpcEvents.SetPendingConnectionDevice,
|
||||||
device
|
device
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -112,4 +112,15 @@ export default function initIpcMainHandlers(
|
|||||||
})
|
})
|
||||||
.catch((e) => log.error(e));
|
.catch((e) => log.error(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle(IpcEvents.ResetWaitingForConnectionSharingSession, () => {
|
||||||
|
const sharingSession = getDeskreenGlobal().sharingSessionService
|
||||||
|
.waitingForConnectionSharingSession;
|
||||||
|
sharingSession?.disconnectByHostMachineUser();
|
||||||
|
sharingSession?.destroy();
|
||||||
|
getDeskreenGlobal().sharingSessionService.sharingSessions.delete(
|
||||||
|
sharingSession?.id as string
|
||||||
|
);
|
||||||
|
getDeskreenGlobal().sharingSessionService.waitingForConnectionSharingSession = null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
11
app/menu.ts
11
app/menu.ts
@ -215,11 +215,12 @@ export default class MenuBuilder {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const subMenuView =
|
// const subMenuView =
|
||||||
process.env.NODE_ENV === 'development' ||
|
// process.env.NODE_ENV === 'development' ||
|
||||||
process.env.DEBUG_PROD === 'true'
|
// process.env.DEBUG_PROD === 'true'
|
||||||
? subMenuViewDev
|
// ? subMenuViewDev
|
||||||
: subMenuViewProd;
|
// : subMenuViewProd;
|
||||||
|
const subMenuView = subMenuViewDev;
|
||||||
|
|
||||||
return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
|
return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user