1
0
mirror of https://github.com/pavlobu/deskreen.git synced 2025-05-28 05:10:09 -07:00

Deskreen stepper advance removing remote

This commit is contained in:
Pavlo Buidenkov 2022-05-29 01:21:28 +02:00
parent f87e74ae2a
commit 70e2c47555
5 changed files with 35 additions and 88 deletions

View File

@ -32,15 +32,13 @@ import ColorlibStepIcon, {
} from '../components/StepperPanel/ColorlibStepIcon';
import ColorlibConnector from '../components/StepperPanel/ColorlibConnector';
import { SettingsContext } from './SettingsProvider';
import SharingSessionService from '../features/SharingSessionService';
import ConnectedDevicesService from '../features/ConnectedDevicesService';
import SharingSessionStatusEnum from '../features/SharingSessionService/SharingSessionStatusEnum';
import Logger from '../utils/LoggerWithFilePrefix';
import LanguageSelector from '../components/LanguageSelector';
import { getShuffledArrayOfHello } from '../configs/i18next.config.client';
import ToggleThemeBtnGroup from '../components/ToggleThemeBtnGroup';
const log = new Logger(__filename);
import SharingSessionService from '../features/SharingSessionService';
import ConnectedDevicesService from '../features/ConnectedDevicesService';
const sharingSessionService = remote.getGlobal(
'sharingSessionService'
@ -49,6 +47,8 @@ const connectedDevicesService = remote.getGlobal(
'connectedDevicesService'
) as ConnectedDevicesService;
const log = new Logger(__filename);
const Fade = require('react-reveal/Fade');
const useStyles = makeStyles(() =>
@ -117,24 +117,11 @@ const DeskreenStepper = React.forwardRef((_props, ref) => {
}, []);
useEffect(() => {
sharingSessionService
.createWaitingForConnectionSharingSession()
// eslint-disable-next-line promise/always-return
.then((waitingForConnectionSharingSession) => {
waitingForConnectionSharingSession.setOnDeviceConnectedCallback(
(device: Device) => {
connectedDevicesService.setPendingConnectionDevice(device);
}
);
})
.catch((e) => log.error(e));
connectedDevicesService.addPendingConnectedDeviceListener(
(device: Device) => {
setPendingConnectionDevice(device);
setIsAlertOpen(true);
}
);
ipcRenderer.invoke('create-waiting-for-connection-sharing-session');
ipcRenderer.on('set-pending-connection-device', (_, device) => {
setPendingConnectionDevice(device);
setIsAlertOpen(true);
});
}, []);
useEffect(() => {

View File

@ -84,49 +84,5 @@ describe('ConnectedDevicesService tests', () => {
expect(isInArray).toBe(true);
});
});
describe('when .addPendingConnectedDeviceListener() was called', () => {
it('should add listener to .pendingDeviceConnectedListeners array', () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const testCallback = (_: Device) => {};
service.addPendingConnectedDeviceListener(testCallback);
let isInArray = false;
service.pendingDeviceConnectedListeners.forEach((c) => {
if (c === testCallback) {
isInArray = true;
}
});
expect(isInArray).toBe(true);
});
});
describe('when .setPendingConnectionDevice() was called', () => {
it('should set passed device as pendingConnectionDevice and call .emitPendingConnectionDeviceConnected', () => {
service.emitPendingConnectionDeviceConnected = jest.fn();
service.setPendingConnectionDevice(testDevice);
expect(service.pendingConnectionDevice).toBe(testDevice);
expect(service.emitPendingConnectionDeviceConnected).toBeCalled();
});
});
describe('when .emitPendingConnectionDeviceConnected() was called', () => {
it('should call all callbacks in pendingDeviceConnectedListeners', () => {
const testCallback1 = jest.fn();
const testCallback2 = jest.fn();
service.pendingDeviceConnectedListeners = [
testCallback1,
testCallback2,
];
service.emitPendingConnectionDeviceConnected();
expect(testCallback1).toBeCalled();
expect(testCallback2).toBeCalled();
});
});
});
});

View File

@ -14,8 +14,6 @@ class ConnectedDevices {
pendingConnectionDevice: Device = nullDevice;
pendingDeviceConnectedListeners: ((device: Device) => void)[] = [];
resetPendingConnectionDevice() {
this.pendingConnectionDevice = nullDevice;
}
@ -41,21 +39,8 @@ class ConnectedDevices {
this.devices.push(device);
}
addPendingConnectedDeviceListener(callback: (device: Device) => void) {
this.pendingDeviceConnectedListeners.push(callback);
}
setPendingConnectionDevice(device: Device) {
this.pendingConnectionDevice = device;
this.emitPendingConnectionDeviceConnected();
}
emitPendingConnectionDeviceConnected() {
this.pendingDeviceConnectedListeners.forEach(
(callback: (device: Device) => void) => {
callback(this.pendingConnectionDevice);
}
);
}
}

View File

@ -95,10 +95,6 @@ export default class DeskreenApp {
);
}
initIpcMain() {
initIpcMainHandlers(this.mainWindow, this.latestVersion, this.appVersion);
}
async createWindow() {
if (
process.env.NODE_ENV === 'development' ||
@ -167,6 +163,8 @@ export default class DeskreenApp {
// Remove this if your app does not use auto updates
// eslint-disable-next-line
new AppUpdater();
initIpcMainHandlers(this.mainWindow, this.latestVersion, this.appVersion);
}
initI18n() {
@ -205,7 +203,6 @@ export default class DeskreenApp {
}
this.initElectronAppObject();
this.initIpcMain();
}
}

View File

@ -6,12 +6,13 @@ import SharingSession from '../features/SharingSessionService/SharingSession';
import RoomIDService from '../server/RoomIDService';
import getDeskreenGlobal from '../utils/mainProcessHelpers/getDeskreenGlobal';
import signalingServer from '../server';
import { DeskreenGlobalService } from '../utils/mainProcessHelpers/DeskreenGlobalService.enum';
import Logger from '../utils/LoggerWithFilePrefix';
const log = new Logger(__filename);
const v4IPGetter = require('internal-ip').v4;
export default function initIpcMainHandlers(
mainWindow: BrowserWindow | null,
mainWindow: BrowserWindow,
latestVersion: string,
appVersion: string
) {
@ -90,4 +91,25 @@ export default function initIpcMainHandlers(
const deskreenGlobal = getDeskreenGlobal();
deskreenGlobal.roomIDService.unmarkRoomIDAsTaken(roomID);
});
ipcMain.handle('create-waiting-for-connection-sharing-session', () => {
console.log('handle create-waiting-for-connection-sharing-session');
getDeskreenGlobal()
.sharingSessionService.createWaitingForConnectionSharingSession()
// eslint-disable-next-line promise/always-return
.then((waitingForConnectionSharingSession) => {
waitingForConnectionSharingSession.setOnDeviceConnectedCallback(
(device: Device) => {
getDeskreenGlobal().connectedDevicesService.setPendingConnectionDevice(
device
);
mainWindow.webContents.send(
'set-pending-connection-device',
device
);
}
);
})
.catch((e) => log.error(e));
});
}