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

fix language change without remote

This commit is contained in:
Pavlo Buidenkov 2022-05-30 17:37:16 +02:00
parent df3a37f7b8
commit 747d275add
5 changed files with 27 additions and 21 deletions

View File

@ -1,17 +1,13 @@
import React, { useContext, useEffect, useState } from 'react';
import { remote } from 'electron';
import { ipcRenderer } from 'electron';
import { HTMLSelect } from '@blueprintjs/core';
import i18n from 'i18next';
import SharingSessionService from '../../features/SharingSessionService';
import { SettingsContext } from '../../containers/SettingsProvider';
import i18n_client, {
getLangFullNameToLangISOKeyMap,
getLangISOKeyToLangFullNameMap,
} from '../../configs/i18next.config.client';
const sharingSessionService = remote.getGlobal(
'sharingSessionService'
) as SharingSessionService;
import { IpcEvents } from '../../main/IpcEvents.enum';
export default function LanguageSelector() {
const { setCurrentLanguageHook } = useContext(SettingsContext);
@ -38,10 +34,7 @@ export default function LanguageSelector() {
getLangFullNameToLangISOKeyMap().get(event.currentTarget.value) ||
'English';
i18n.changeLanguage(newLang);
// TODO: call sharing sessions service here to notify all connected clients about language change
sharingSessionService.sharingSessions.forEach((sharingSession) => {
sharingSession?.appLanguageChanged();
});
ipcRenderer.invoke(IpcEvents.AppLanguageChanged);
}
};

View File

@ -235,7 +235,7 @@ export default function TopPanel(props: any) {
{renderSettingsButton()}
</div>
</div>
{isConnectedDevicesDrawerOpen ? (
{isSettingsOpen ? (
<SettingsOverlay
isSettingsOpen={isSettingsOpen}
handleClose={handleSettingsClose}

View File

@ -61,19 +61,23 @@ export default class PeerConnection {
}
notifyClientWithNewLanguage() {
this.sendEncryptedMessage({
type: 'APP_LANGUAGE',
payload: {
value: getAppLanguage(),
},
});
setTimeout(() => {
this.sendEncryptedMessage({
type: 'APP_LANGUAGE',
payload: {
value: getAppLanguage(),
},
});
}, 1000);
}
notifyClientWithNewColorTheme() {
this.sendEncryptedMessage({
type: 'APP_THEME',
payload: { value: getAppTheme() },
});
setTimeout(() => {
this.sendEncryptedMessage({
type: 'APP_THEME',
payload: { value: getAppTheme() },
});
}, 1000);
}
async setDesktopCapturerSourceID(id: string) {

View File

@ -12,4 +12,5 @@ export enum IpcEvents {
GetConnectedDevices = 'get-connected-devices-list',
DisconnectDeviceById = 'disconnect-device-by-id',
DisconnectAllDevices = 'disconnect-all-devices',
AppLanguageChanged = 'app-language-changed',
}

View File

@ -179,4 +179,12 @@ export default function initIpcMainHandlers(
ipcMain.handle(IpcEvents.DisconnectAllDevices, () => {
getDeskreenGlobal().connectedDevicesService.disconnectAllDevices();
});
ipcMain.handle(IpcEvents.AppLanguageChanged, () => {
getDeskreenGlobal().sharingSessionService.sharingSessions.forEach(
(sharingSession) => {
sharingSession?.appLanguageChanged();
}
);
});
}