mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-16 07:20:16 -07:00
complete migrate to electron-store and finish electron 18.2.3 upgrade!
This commit is contained in:
parent
c16a22e06d
commit
391c7721cd
@ -10,7 +10,9 @@ import { ElectronStoreKeys } from '../enums/ElectronStoreKeys.enum';
|
|||||||
|
|
||||||
const i18nextOptions = {
|
const i18nextOptions = {
|
||||||
fallbackLng: config.fallbackLng,
|
fallbackLng: config.fallbackLng,
|
||||||
lng: store.get(ElectronStoreKeys.AppLanguage),
|
lng: store.has(ElectronStoreKeys.AppLanguage)
|
||||||
|
? String(store.get(ElectronStoreKeys.AppLanguage))
|
||||||
|
: 'en',
|
||||||
ns: 'translation',
|
ns: 'translation',
|
||||||
defaultNS: 'translation',
|
defaultNS: 'translation',
|
||||||
backend: {
|
backend: {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
/* eslint-disable react/prop-types */
|
/* eslint-disable react/prop-types */
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Classes } from '@blueprintjs/core';
|
import { Classes } from '@blueprintjs/core';
|
||||||
|
import { ipcRenderer } from 'electron';
|
||||||
|
import { IpcEvents } from '../main/IpcEvents.enum';
|
||||||
|
|
||||||
// TODO: move to 'constants' tsx file ?
|
// TODO: move to 'constants' tsx file ?
|
||||||
export const LIGHT_UI_BACKGROUND = 'rgba(240, 248, 250, 1)';
|
export const LIGHT_UI_BACKGROUND = 'rgba(240, 248, 250, 1)';
|
||||||
@ -28,27 +30,26 @@ export const SettingsProvider: React.FC = ({ children }) => {
|
|||||||
const [isDarkTheme, setIsDarkTheme] = useState(false);
|
const [isDarkTheme, setIsDarkTheme] = useState(false);
|
||||||
const [currentLanguage, setCurrentLanguage] = useState('en');
|
const [currentLanguage, setCurrentLanguage] = useState('en');
|
||||||
|
|
||||||
const loadDarkThemeFromSettings = () => {
|
const loadDarkThemeFromSettings = async () => {
|
||||||
// const gotIsDarkThemeFromSettings = settings.hasSync('appIsDarkTheme')
|
const isDarkAppTheme = await ipcRenderer.invoke(
|
||||||
// ? settings.getSync('appIsDarkTheme') === 'true'
|
IpcEvents.GetIsAppDarkTheme
|
||||||
// : false;
|
);
|
||||||
const gotIsDarkThemeFromSettings = true;
|
|
||||||
|
|
||||||
if (gotIsDarkThemeFromSettings) {
|
if (isDarkAppTheme) {
|
||||||
document.body.classList.toggle(Classes.DARK);
|
document.body.classList.toggle(Classes.DARK);
|
||||||
document.body.style.backgroundColor = LIGHT_UI_BACKGROUND;
|
document.body.style.backgroundColor = LIGHT_UI_BACKGROUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsDarkTheme(gotIsDarkThemeFromSettings);
|
setIsDarkTheme(isDarkAppTheme);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadDarkThemeFromSettings();
|
loadDarkThemeFromSettings();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setIsDarkThemeHook = (val: boolean) => {
|
const setIsDarkThemeHook = (isAppDarkTheme: boolean) => {
|
||||||
// settings.setSync('appIsDarkTheme', `${val}`);
|
ipcRenderer.invoke(IpcEvents.SetIsAppDarkTheme, isAppDarkTheme);
|
||||||
setIsDarkTheme(val);
|
setIsDarkTheme(isAppDarkTheme);
|
||||||
};
|
};
|
||||||
|
|
||||||
const setCurrentLanguageHook = (newLang: string) => {
|
const setCurrentLanguageHook = (newLang: string) => {
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
export enum ElectronStoreKeys {
|
export enum ElectronStoreKeys {
|
||||||
AppLanguage = 'appLanguage',
|
AppLanguage = 'appLanguage',
|
||||||
IsNotFirstTimeAppStart = 'isNotFirstTimeAppStart',
|
IsNotFirstTimeAppStart = 'isNotFirstTimeAppStart',
|
||||||
|
IsAppDarkTheme = 'isAppDarkTheme',
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import { ipcRenderer } from 'electron';
|
||||||
import uuid from 'uuid';
|
import uuid from 'uuid';
|
||||||
import { process as processMessage } from '../../utils/message';
|
import { process as processMessage } from '../../utils/message';
|
||||||
|
import { IpcEvents } from '../../main/IpcEvents.enum';
|
||||||
|
|
||||||
export function handleDeviceIPMessage(
|
export function handleDeviceIPMessage(
|
||||||
deviceIP: string,
|
deviceIP: string,
|
||||||
@ -40,24 +42,22 @@ export default async function handleRecieveEncryptedMessage(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (message.type === 'GET_APP_THEME') {
|
if (message.type === 'GET_APP_THEME') {
|
||||||
|
const isDarkAppTheme = await ipcRenderer.invoke(
|
||||||
|
IpcEvents.GetIsAppDarkTheme
|
||||||
|
);
|
||||||
peerConnection.sendEncryptedMessage({
|
peerConnection.sendEncryptedMessage({
|
||||||
type: 'APP_THEME',
|
type: 'APP_THEME',
|
||||||
payload: {
|
payload: {
|
||||||
// value: settings.hasSync('appIsDarkTheme')
|
value: isDarkAppTheme,
|
||||||
// ? settings.getSync('appIsDarkTheme') === 'true'
|
|
||||||
// : false,
|
|
||||||
value: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (message.type === 'GET_APP_LANGUAGE') {
|
if (message.type === 'GET_APP_LANGUAGE') {
|
||||||
|
const appLanguage = await ipcRenderer.invoke(IpcEvents.GetAppLanguage);
|
||||||
peerConnection.sendEncryptedMessage({
|
peerConnection.sendEncryptedMessage({
|
||||||
type: 'APP_LANGUAGE',
|
type: 'APP_LANGUAGE',
|
||||||
payload: {
|
payload: {
|
||||||
// value: settings.hasSync('appLanguage')
|
value: appLanguage,
|
||||||
// ? settings.getSync('appLanguage')
|
|
||||||
// : 'en',
|
|
||||||
value: 'en',
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -61,21 +61,21 @@ export default class PeerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifyClientWithNewLanguage() {
|
notifyClientWithNewLanguage() {
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
this.sendEncryptedMessage({
|
this.sendEncryptedMessage({
|
||||||
type: 'APP_LANGUAGE',
|
type: 'APP_LANGUAGE',
|
||||||
payload: {
|
payload: {
|
||||||
value: getAppLanguage(),
|
value: await getAppLanguage(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyClientWithNewColorTheme() {
|
notifyClientWithNewColorTheme() {
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
this.sendEncryptedMessage({
|
this.sendEncryptedMessage({
|
||||||
type: 'APP_THEME',
|
type: 'APP_THEME',
|
||||||
payload: { value: getAppTheme() },
|
payload: { value: await getAppTheme() },
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
@ -119,11 +119,9 @@ export default class DeskreenApp {
|
|||||||
? {
|
? {
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
enableRemoteModule: true,
|
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
preload: path.join(__dirname, 'dist/mainWindow.renderer.prod.js'),
|
preload: path.join(__dirname, 'dist/mainWindow.renderer.prod.js'),
|
||||||
enableRemoteModule: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -24,4 +24,6 @@ export enum IpcEvents {
|
|||||||
GetAppLanguage = 'get-app-language',
|
GetAppLanguage = 'get-app-language',
|
||||||
GetIsFirstTimeAppStart = 'get-is-not-first-time-app-start',
|
GetIsFirstTimeAppStart = 'get-is-not-first-time-app-start',
|
||||||
SetAppStartedOnce = 'set-app-started-once',
|
SetAppStartedOnce = 'set-app-started-once',
|
||||||
|
GetIsAppDarkTheme = 'get-is-app-dark-theme',
|
||||||
|
SetIsAppDarkTheme = 'set-is-app-dark-theme',
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,13 @@ export default function initIpcMainHandlers(
|
|||||||
) {
|
) {
|
||||||
ipcMain.on('client-changed-language', async (_, newLangCode) => {
|
ipcMain.on('client-changed-language', async (_, newLangCode) => {
|
||||||
i18n.changeLanguage(newLangCode);
|
i18n.changeLanguage(newLangCode);
|
||||||
// await settings.set('appLanguage', newLangCode);
|
if (store.has(ElectronStoreKeys.AppLanguage)) {
|
||||||
|
if (store.get(ElectronStoreKeys.AppLanguage) === newLangCode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
store.delete(ElectronStoreKeys.AppLanguage);
|
||||||
|
}
|
||||||
|
store.set(ElectronStoreKeys.AppLanguage, newLangCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('get-signaling-server-port', () => {
|
ipcMain.handle('get-signaling-server-port', () => {
|
||||||
@ -293,4 +299,25 @@ export default function initIpcMainHandlers(
|
|||||||
}
|
}
|
||||||
store.set(ElectronStoreKeys.IsNotFirstTimeAppStart, true);
|
store.set(ElectronStoreKeys.IsNotFirstTimeAppStart, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle(IpcEvents.GetIsAppDarkTheme, () => {
|
||||||
|
if (store.has(ElectronStoreKeys.IsAppDarkTheme)) {
|
||||||
|
return store.get(ElectronStoreKeys.IsAppDarkTheme);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle(IpcEvents.SetIsAppDarkTheme, (_, isDarkTheme) => {
|
||||||
|
if (store.has(ElectronStoreKeys.IsAppDarkTheme)) {
|
||||||
|
store.delete(ElectronStoreKeys.IsAppDarkTheme);
|
||||||
|
}
|
||||||
|
store.set(ElectronStoreKeys.IsAppDarkTheme, isDarkTheme);
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle(IpcEvents.GetAppLanguage, () => {
|
||||||
|
if (store.has(ElectronStoreKeys.AppLanguage)) {
|
||||||
|
return store.get(ElectronStoreKeys.AppLanguage);
|
||||||
|
}
|
||||||
|
return 'en';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export default function getAppLanguage(): string {
|
import { ipcRenderer } from 'electron';
|
||||||
// return settings.hasSync('appLanguage')
|
import { IpcEvents } from '../main/IpcEvents.enum';
|
||||||
// ? (settings.getSync('appLanguage') as string)
|
|
||||||
// : 'en';
|
export default async function getAppLanguage(): Promise<string> {
|
||||||
return 'en';
|
const appLanguage = await ipcRenderer.invoke(IpcEvents.GetAppLanguage);
|
||||||
|
return appLanguage;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export default function getAppTheme(): boolean {
|
import { ipcRenderer } from 'electron';
|
||||||
// return settings.hasSync('appIsDarkTheme')
|
import { IpcEvents } from '../main/IpcEvents.enum';
|
||||||
// ? settings.getSync('appIsDarkTheme') === 'true'
|
|
||||||
// : false;
|
export default async function getAppTheme(): Promise<boolean> {
|
||||||
return true;
|
const isAppDarkTheme = await ipcRenderer.invoke(IpcEvents.GetIsAppDarkTheme);
|
||||||
|
return isAppDarkTheme;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user